You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Lon Varscsak <lo...@gmail.com> on 2014/08/13 23:21:35 UTC

Alternate connection for prod/dev

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

Re: Alternate connection for prod/dev

Posted by Michael Gentry <mg...@masslight.net>.
Hi Lon,

In a Tapestry (or other web-based applications), you typically want to use
JNDI for database connections.  To do this you tell Cayenne to use JNDI in
the Modeler, then you configure the JNDI database connection (the JDBC URL,
username, and passord) in your application server (Jetty, Tomcat, etc).
This way neither Cayenne nor Tapestry need to know about the database
specifics since that is maintained by the application server and is
therefore more portable.  This is how we do all of our web-based work.

If this appeals to you, let us know and we can give you further details.

mrg



On Wed, Aug 13, 2014 at 5:21 PM, Lon Varscsak <lo...@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
>

Re: Alternate connection for prod/dev

Posted by John Huss <jo...@gmail.com>.
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 <lo...@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
>