cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Using two different DBs
Date Tue, 30 Aug 2011 21:09:30 GMT
Hi Richard,

To avoid copy/pasting, you can probably start 2 Cayenne stacks. If you are on Cayenne 3.0,
this will be 2 Configuration objects and you can add a correct DataNode via API to each stack.


In 3.1 it is a bit more elegant. In 3.1M2 2 stacks will correspond to 2 ServerRuntime's. In
one of them you can override the Db connection settings via a custom configuration module
like this:

class MyModule implements Module {
   public void configure(Binder binder) {
     binder.bindMap(DefaultRuntimeProperties.PROPERTIES_MAP).put("cayenne.jdbc.url", "alturl").put(...);

     // see PropertyDataSourceFactory for details on property names, etc.
   }
}


Finally in yet unreleased 3.1M3 it will be even easier (this code exists on trunk already).
Cayenne can merge multiple mappings in runtime, so you may create 2 projects in the Modeler:

1. A common DataMap + one of DataNodes, say cayenne-map.xml
2. A project with only a DataNode using the same name as DataNode from project 1, say cayenne-map-db2.xml

and then load 2 stacks as this:

   ServerRuntime r1 = new ServerRuntime("cayenne-map.xml");
   ServerRuntime r2 = new ServerRuntime(new String[] { "cayenne-map.xml", "cayenne-map-db2.xml"});

Andrus


On Aug 30, 2011, at 4:45 PM, Richard Frovarp wrote:

> I'm working on something now where I'm using two separate DBs. I'm actually trying to
compare data between the two systems. So my maps should be identical, just two different nodes.
> 
> Is there an easy way to do this? Right now it seems that I do a copy and paste, then
change the prefix or other such identifier between the two. Am I missing something where this
is easy to setup?
> 
> Thanks,
> Richard
> 


Mime
View raw message