On 08/30/2011 04:09 PM, Andrus Adamchik wrote:
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



Thanks for the ideas. I haven't had a chance to do much with Cayenne since we talked at ApacheCon last year. But what I have done with it I like very much.

Richard

Reply via email to