nice feature, I don't longer need any XML file to configure Cayenne.
Thanks a lot
André
Andrus Adamchik wrote:
Actually this is good result - you are getting there. I think you
also need to add attributes for the columns in your table to
DbEntity and ObjEntity.
Andrus
also need to add attributes for the columns in your table to
DbEntity and ObjEntity.
Andrus
On Jan 21, 2011, at 5:09 PM, André Rothe wrote:
Hm, it doesn't work. I can perform a SQL query, it returns the
correct number of records, but the properties are NULL.
SelectQuery q = new SelectQuery("Projects");
List projectsTest = this.context.get("test").performQuery(q);
for (Object o : projectsTest) {
DataObject dObj = (DataObject) o;
System.out.println(dObj.readProperty("columnname"));
}
I have defined a DataContext "test" as:
DataMap map = new DataMap(mapName + " map");
DbEntity entity = new DbEntity("tablename");
map.addDbEntity(entity);
DbAttribute attr = new CharacterDbAttribute("columnname", 20, true);
entity.addAttribute(attr);
// more attributes here
// ...
ObjEntity objEntity = new ObjEntity("Projects");
objEntity.setDbEntity(entity);
objEntity.setClassName(CayenneDataObject.class.getName()); // default
map.addObjEntity(objEntity);
DataNode node = new DataNode(mapName + " node");
node.addDataMap(map);
node.setDataSource(store.getDataSource());
node.setAdapter(new AutoAdapter(store.getDataSource()));
DataDomain domain = new DataDomain(mapName + " domain");
domain.addNode(node);
domain.addMap(map);
this.context.put(mapName, domain.createDataContext());
The class CharacterDbAttribute sets the type to VARCHAR, mandatory
and length properties. The field "store" holds the data sources
(instances of PoolManager). mapName = "test".
I think, I don't need a full-defined ObjectEntity, because it is
dynamic. I set only the class name (default) and the DbEntity
instance. So where I have forgotten a call?
Thanks a lot
André
Andrus Adamchik wrote:
the default). If you want to use your own subclass, definitely
call objEntity.setClassName(MyClass.class.getName()).
Andrus
Hm, it doesn't work. I can perform a SQL query, it returns the
correct number of records, but the properties are NULL.
SelectQuery q = new SelectQuery("Projects");
List projectsTest = this.context.get("test").performQuery(q);
for (Object o : projectsTest) {
DataObject dObj = (DataObject) o;
System.out.println(dObj.readProperty("columnname"));
}
I have defined a DataContext "test" as:
DataMap map = new DataMap(mapName + " map");
DbEntity entity = new DbEntity("tablename");
map.addDbEntity(entity);
DbAttribute attr = new CharacterDbAttribute("columnname", 20, true);
entity.addAttribute(attr);
// more attributes here
// ...
ObjEntity objEntity = new ObjEntity("Projects");
objEntity.setDbEntity(entity);
objEntity.setClassName(CayenneDataObject.class.getName()); // default
map.addObjEntity(objEntity);
DataNode node = new DataNode(mapName + " node");
node.addDataMap(map);
node.setDataSource(store.getDataSource());
node.setAdapter(new AutoAdapter(store.getDataSource()));
DataDomain domain = new DataDomain(mapName + " domain");
domain.addNode(node);
domain.addMap(map);
this.context.put(mapName, domain.createDataContext());
The class CharacterDbAttribute sets the type to VARCHAR, mandatory
and length properties. The field "store" holds the data sources
(instances of PoolManager). mapName = "test".
I think, I don't need a full-defined ObjectEntity, because it is
dynamic. I set only the class name (default) and the DbEntity
instance. So where I have forgotten a call?
Thanks a lot
André
Andrus Adamchik wrote:
On Jan 21, 2011, at 2:53 PM, André Rothe wrote:
Should I set the name explicitly to
"org.apache.cayenne.CayenneDataObject" (or subclasses)?
Setting org.apache.cayenne.CayenneDataObject is optional (this isShould I set the name explicitly to
"org.apache.cayenne.CayenneDataObject" (or subclasses)?
the default). If you want to use your own subclass, definitely
call objEntity.setClassName(MyClass.class.getName()).
Andrus