cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject Re: Alternate connection for prod/dev
Date Wed, 13 Aug 2014 21:29:39 GMT
You can configure the database connection in 3.1+ with a cayenne module
 like:

import org.apache.cayenne.configuration.Constants;
import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.Module;

public class AppModule implements Module {
 public void configure(Binder binder) {
binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_URL_PROPERTY,
"jdbc:postgresql://localhost/mydb");
binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_DRIVER_PROPERTY,
org.postgresql.Driver.class.getName());
}

}

You just have to list your module when creating the ServerRuntime:

CayenneRuntime runtime = new ServerRuntime("cayenne-MyDomain.xml", new
AppModule());

The module can also be specified in web.xml instead if you are using
CayenneFilter or something.

The JDBC_URL_PROPERTY will override the url for all databases.  If you have
more than one you'll want to override each independently by appending the
domain name and dataNode name to the property name, like:

binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_URL_PROPERTY +
".MyDomain.MyDataNode", "jdbc:postgresql://localhost/mydb");

The specific url value or driver value you are using doesn't have to be
hard coded.  You can read it from a file or from the system properties set
on the command line - whatever you want.


On Wed, Aug 13, 2014 at 4:21 PM, Lon Varscsak <lon.varscsak@gmail.com>
wrote:

> Hey guys, newb here...be gentlle. :P
>
> I'm using Tapestry (newb there too) to build an app that connects to
> Cayenne and it looks like they have these modules that
> "contributeApplicationDefaults" where you specify values and keys for
> things.  I have a module for Development/QA/Production.  I tried setting
> "cayenne.jdbc.url" in the development module to connect to my DEV db and
> another for my production db...but it looks like Cayenne doesn't honor
> this.
>
> How would I set different urls for different "modes" for the application?
>
> Thanks,
>
> Lon
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message