• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question: Best practice for switching db connections as build time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question: Best practice for switching db connections as build time


  • Subject: Re: Question: Best practice for switching db connections as build time
  • From: Henrique Gomes <email@hidden>
  • Date: Fri, 24 Oct 2008 16:05:00 +0100


On Oct 24, 2008, at 3:17 PM, William Sandner wrote:

We have 4 different environments that we deploy to, development, test, staging, and production.  We are using ant as our build tool.

For most of our environments we connect to a localhost database with a common password, but production is on an external server which has a more secure password.  What is the best way to change the db connection at build time?

Example:
When I build for production, I want to make sure the connection is pointing to the correct server and the password is correct.

I know I can use ant to search and replace for connection string tokens in the Properties file, but is this the easiest way?


I am doing it by replacing the connection string on the modelAdded Notification with  properties:


public Application() {


NSNotificationCenter.defaultCenter().addObserver(
this,
new NSSelector("modelAdded",
new Class[] { NSNotification.class }),
EOModelGroup.ModelAddedNotification, null);
}

public void modelAdded(NSNotification n) {

NSLog.out.appendln("Notification ModelAdded: ");
EOModel m = (EOModel) n.object();
String dbhost = System.getProperty("app.dbhost");
String db = System.getProperty("app.db");
if (db == null || dbhost == null)
NSLog.out.appendln("No app.dbhost or app.db set, using defaults");
else {
if (m.name().equals("MODELNAME")) {
NSLog.out.appendln("Overriding host: " + dbhost + " db: " + db);
NSMutableDictionary<String, Object> c = new NSMutableDictionary<String, Object>(
m.connectionDictionary());
c.setObjectForKey("jdbc:postgresql://" + dbhost + "/" + db,
"URL");
m.setConnectionDictionary(c);
}
}
}

Then I set the app lunch parameters on JavaMonitor to set those properties :

-Dapp.dbhost=server -Dapp.db=dbname


I guess you can do something similar with the login/password. The beauty of it is that you can launch the same app with connections strings, no recompile/rebuild needed.

Of course, being new here I invite comments about this approach....


Henrique Gomes

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Question: Best practice for switching db connections as build time (From: William Sandner <email@hidden>)

  • Prev by Date: Flattened Relationships and storedValueForkey()
  • Next by Date: Re: Running tests from ant on a continuous integration server
  • Previous by thread: Re: Question: Best practice for switching db connections as build time
  • Next by thread: Re: Question: Best practice for switching db connections as build time
  • Index(es):
    • Date
    • Thread