Hi Andrus,

when it comes to the generic persistence data objects, how I have to define it?

        DataMap map = new DataMap(mapName);

        DbEntity entity = new DbEntity("projects");
        DbAttribute attr = new DbAttribute("ora_uname");
        attr.setMaxLength(20);
        attr.setMandatory(true);
        entity.addAttribute(attr);
        map.addDbEntity(entity);

        ObjEntity objEntity = new ObjEntity("Projects");
        objEntity.setDbEntity(entity);
        objEntity.setClassName(// ??);

Should I set the name explicitly to "org.apache.cayenne.CayenneDataObject" (or subclasses)?

Thanks
André


Andrus Adamchik <[email protected]> wrote:

Hi André,

Yes, if you wish you can create the entire Cayenne stack via API, loading parts of it from XML files, etc.

* To load DataMap from XML, use MapLoader:

http://cayenne.apache.org/doc30/api/org/apache/cayenne/map/MapLoader.html

* To create a DataContext, use DataDomain.createDataContext().

* To change loaded DataMap, use DataMap methods to access and manipulate the entities:

http://cayenne.apache.org/doc30/api/org/apache/cayenne/map/DataMap.html

Andrus

On Jan 21, 2011, at 11:26 AM, André Rothe wrote:

Hello,

I try to write a short test program, which can use multiple data sources dynamically with Cayenne. At the moment I have finished the replacement for the driver.xml and cayenne.xml (I think):

--------------------------------

// init a connection
DataSourceInfo properties = new DataSourceInfo();
properties.setDataSourceUrl("jdbc:oracle:thin:@test:1521:play");
properties.setJdbcDriver("oracle.jdbc.OracleDriver");
properties.setMinConnections(1);
properties.setMaxConnections(1);
properties.setUserName("scott");
properties.setPassword("testme");

PoolManager pmA = new PoolManager(
                   properties.getJdbcDriver(),
                   properties.getDataSourceUrl(),
                   properties.getMinConnections(),
                   properties.getMaxConnections(),
                   properties.getUserName(),
                   properties.getPassword());

DataMap map = new DataMap("test_db");
//??

DataNode node = new DataNode("dev_db");
node.addDataMap(map);
node.setDataSource(pmA);

DataDomain domainA = new DataDomain();
domainA.addNode(node);
domainA.addMap(map);

// get the context ??


// init another connection
properties.setDataSourceUrl("jdbc:oracle:thin:@test:1521:test");

PoolManager pmB = new PoolManager(
                   properties.getJdbcDriver(),
                   properties.getDataSourceUrl(),
                   properties.getMinConnections(),
                   properties.getMaxConnections(),
                   properties.getUserName(),
                   properties.getPassword());

map = new DataMap("test_db");
//??

node = new DataNode("test_db");
node.addDataMap(map);
node.setDataSource(pmB);

DataDomain domainB = new DataDomain();
domainB.addNode(node);
domainB.addMap(map);

// get the context ??


---------------------

The questions:

How I can load a predefined data map from a map.xml into my DataMap object without affecting the already defined objects (node, domain etc.)? Can I define the map dynamically? How I can create a DataContext for the domains I have?

I have a lot of different data sources, which are defined by some other parts of the application. The DataSourceInfo object must be changeable by the user and it can be, that I get changes on the database structure, so it must be possible to react on them with a new data-map at runtime.

Is it possible with Cayenne?

Tanks
André




Reply via email to