cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject Re: Switching data nodes at runtime
Date Mon, 26 Sep 2011 20:11:52 GMT
Thanks for help.

To document this for future users, the DI approach then looks something like
this:

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

public class AppModule implements Module {
  public void configure(Binder binder) {
    binder.bindMap(DefaultRuntimeProperties.PROPERTIES_MAP)
      .put("cayenne.jdbc.driver.MyDomain.mynode", "org.postgresql.Driver")
      .put("cayenne.jdbc.url.MyDomain.mynode",
"jdbc:postgresql://localhost/my_db")
      .put("cayenne.jdbc.username.MyDomain.mynode", "postgres")
      .put("cayenne.jdbc.password.MyDomain.mynode", "mypassword");
    }
  }
}

On Mon, Sep 26, 2011 at 12:05 PM, Andrus Adamchik <andrus@objectstyle.org>wrote:

> This is a good recipe for 3.0. In 3.1 you are allowed to merge multiple
> projects when creating a ServerRuntime, so you can merge multiple mappings
> to get the behavior that you need. However... Are you sure you want to
> switch DataNodes? DataNodes by themselves don't have many configuration
> properties. All the DB connection info is really about the underlying
> javax.sql.DataSource and that can be tweaked differently. Earlier you wrote:
>
> > Yeah, I'm mainly interested in supporting the same schema on multiple
> databases
>
> So this means 1 database in a given app, just a different database between
> the apps (or app executions)? In this case you can either use JNDI to map
> the DataSource, without changing anything in Cayenne (there is a nifty thing
> called AutoAdapter that automatically installs the right DbAdapter depending
> on the target DB type, so no need to know the adapter upfront). Or check
> this PDF (Chapter 11 and Appendix A) for properties that allow to specify
> the DB connection in runtime:
>
> http://people.apache.org/~aadamchik/misc/cayenne-guide-08302011.pdf
>
> AutoAdapter is at play here is well.
>
> Andrus
>
>
>
> On Sep 26, 2011, at 6:35 PM, Michael Gentry wrote:
> > Hi John,
> >
> > This is completely untested, but try something like:
> >
> > Configuration  configuration = Configuration.getSharedConfiguration();
> > DataDomain  dataDomain = configuration.getDomain();
> > DataMap  dataMap = dataDomain.getMap("my map name");
> > DataNode  oldNode = dataDomain.getNode("old node name);
> > DataNode  newNode = dataDomain.getNode("new node name);
> >
> > oldNode.removeDataMap(dataMap);
> > newNode.addDataMap(dataMap);
> > dataDomain.reindexNodes(); // maybe
> >
> > mrg
> >
> >
> > On Mon, Sep 26, 2011 at 10:49 AM, John Huss <johnthuss@gmail.com> wrote:
> >> At runtime how do I switch my model to use a different data node that
> was
> >> previously defined in the in model?  I'm using trunk.
> >>
> >> Thanks,
> >> John
> >>
> >
>
>

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