Re: Swap database instance at runtime

Riza Nugraha <[email protected]> Wed, 18 Nov 2009 13:07:04 +0100
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Hi all,

I'm currently having the same situation here. I'm using more or less the
same method which is basically setting the new connectionDictionary to my
EOModel.

I tried to fetch some records after switching the connection but it's still
giving me the result from the previous connection.

Did I miss something? Should I use new editingContext every time I switched
to the new connection? I tried this as well .. but the problem still
persists. Kindly please advice.

Best regards,

Riza Nugraha
------------------
Email: [email protected]

2009/11/17 Mark Fisher <[email protected]>

> I use these methods in Application.java to change the DB connection at
> runtime:
>
>             //  ******************************
>             protected void setDBConnection(String serverURL){
>                 if (null == serverURL)
>                     serverURL = "jdbc:FrontBase://
> yourserver.com/DatabaseName/user=_SYSTEM/isolation=read_committed/locking=optimistic
> ";//eq setDBConnection("yourserver.com");
>                 else
>                     serverURL = "jdbc:FrontBase://"+serverURL+"/" +
> surveyTableName+
> "/user=_SYSTEM/isolation=read_committed/locking=optimistic";
>                                                 //
>                 String modelName  = "EOModelName";
>
>
>                 java.util.Enumeration e =
> EOModelGroup.defaultGroup().models().objectEnumerator();
>                 while (e.hasMoreElements() == true){
>
>
>                     EOModel m = (EOModel)e.nextElement();
>                     // use this part to isolate the model you wish to
> connect
>                     if (m.name().equals(modelName)){
>                         NSMutableDictionary d = newNSMutableDictionary(m.connectionDictionary());
>                         //
>                         d.setObjectForKey (serverURL,
> com.webobjects.jdbcadaptor.JDBCAdaptor.URLKey);
>                         //d.setObjectForKey (username,
> JDBCAdaptor.UsernameKey);
>                         //d.setObjectForKey (password,
> JDBCAdaptor.PasswordKey);
>                         //
>                         m.setConnectionDictionary(d);
>                     }
>                 }
>             }
>             protected void setDBtable(String serverURL, String tableName){
>                 if (null == serverURL || null == tableName )
>                     serverURL = "jdbc:FrontBase://
> yourserver.com/DatabaseName/user=_SYSTEM/isolation=read_committed/locking=optimistic
> "; //eq setDBConnection("yourserver.com");
>                 else
>                     serverURL = "jdbc:FrontBase://"+serverURL+"/" +
> tableName+ "/user=_SYSTEM/isolation=read_committed/locking=optimistic";
>                                                 //
>                 String modelName  = "EOModelName";
>
>
>                 java.util.Enumeration e =
> EOModelGroup.defaultGroup().models().objectEnumerator();
>                 while (e.hasMoreElements() == true){
>
>
>                     EOModel m = (EOModel)e.nextElement();
>                     // use this part to isolate the model you wish to
> connect
>                     if (m.name().equals(modelName)){
>                         NSMutableDictionary d = newNSMutableDictionary(m.connectionDictionary());
>                         //
>                         d.setObjectForKey (serverURL,
> com.webobjects.jdbcadaptor.JDBCAdaptor.URLKey);
>                         //d.setObjectForKey (username,
> JDBCAdaptor.UsernameKey);
>                         //d.setObjectForKey (password,
> JDBCAdaptor.PasswordKey);
>                         //
>                         m.setConnectionDictionary(d);
>                     }
>                 }
>
>
>             }
>
>
>             protected String getDBConnection(){
>                 String serverURL=null;
>                 String modelName  = "EOModelName";
>                 java.util.Enumeration e =
> EOModelGroup.defaultGroup().models().objectEnumerator();
>                 while (e.hasMoreElements() == true){
>
>
>                     EOModel m = (EOModel)e.nextElement();
>                     // use this part to isolate the model you wish to
> connect
>                     if (m.name().equals(modelName)){
>                         NSMutableDictionary d = newNSMutableDictionary(m.connectionDictionary());
>                         serverURL =
> (String)d.objectForKey(com.webobjects.jdbcadaptor.JDBCAdaptor.URLKey);
>                     }
>                 }
>   //NSLog.out.appendln("Application->getDBConnection() ="+serverURL);
>                 return new String(serverURL);
>             }
>             //  ******************************
>
>
> Mark Fisher
> Chief Technology Officer
> LoTi Connection Inc.
>
> On Nov 17, 2009, at 12:00 PM, [email protected] wrote:
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 17 Nov 2009 10:46:03 +0100
> From: Rogier Bosch <[email protected]>
> Subject: Swap database instance at runtime
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes
>
> Hi All,
>
> I have one WO application which i would like to connect to different
> databases (1 db for each customer). The database schema is the same
> for all of them. My question is: how can i  (if  possible) @ runtime,
> swap the EO model/objects to connect to a different database instance?
>
> A small peace of example code would be appreciated.
>
> Many thanks in advance,
>
> Roger
>
>
>
>
>
>
>
> _______________________________________________
> WebObjects-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
>
>

_______________________________________________
WebObjects-dev mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/webobjects-dev