This worked great. Thanks for the tip.
public boolean setDataMapSchema(DataMap dataMap, String schema) {
try {
for (DbEntity dbEntity : dataMap.getDbEntities()) {
dbEntity.setSchema(schema);
}
} catch (Exception e) {
System.out.println(e.toString());
return false;
}
return true;
}
Lawrence
On Jan 5, 2009, at 11:11 PM, Andrus Adamchik wrote:
Hi Lawrence,
Yeah, the "default schema" is ignored in runtime, and only per
DbEntity schema is consulted. Looking back, it would've been better
to use the default if DbEntity schema is not set, and we may change
the behavior at some point, but for now "default schema" is only
used by the Modeler.
So to change schema you would need to iterate through all DbEntities
and set it per entity.
Andrus
On Jan 6, 2009, at 3:57 AM, Lawrence Gerstley wrote:
Hello,
I've been using Cayenne and allowing for changing backends at
runtime--representing the same schema in MySQL, Oracle, Apache
Derby, and have had success changing the backend with:
DataSource dataSource = new PoolManager(
jdbcDriverDetails.getDriverClass(),
myURL,
1,
5,
myUser,
myPassword);
Configuration config =
Configuration.getSharedConfiguration();
DataDomain domain = config.getDomain();
DataNode node = domain.getNode("MyDomain");
node.setDataSource(dataSource);
My problem is that I need to also allow a user to select the schema
that the datamap should be applied to. For example, in Oracle, the
same schema design might be in multiple instances (in my example,
KTMI3D, KTMI3M, KTMI3X, etc.). I can change these with the modeler
and have it work, but I need to change it at runtime. I've tried
changing it with:
dataMap.setDefaultSchema(schema);
But haven't had much luck changing at runtime. Is there some way to
do this with my approach, or is there a better approach to take if
you want to switch back-ends multiple time at runtime?
Thanks for reading,
Lawrence