map.addDbEntity(dbEntity);
assertTokensAndExecute(node, map, 1, 0);
assertTokensAndExecute(node, map, 0, 0);
ObjEntity objEntity = new ObjEntity("NewTable");
objEntity.setDbEntity(dbEntity);
ObjAttribute oatr1 = new ObjAttribute("name");
oatr1.setDbAttributePath(column2.getName());
oatr1.setType("java.lang.String");
objEntity.addAttribute(oatr1);
map.addObjEntity(objEntity);
// try to insert some rows to check that pk stuff is working
DataContext ctxt = createDataContext();
DataMap sourceMap = map;//ctxt.getEntityResolver().getDataMap("testmap");
try {
sourceMap.addDbEntity(dbEntity);
sourceMap.addObjEntity(objEntity);
for (int i = 0; i < 5; i++) {
CayenneDataObject dao = (CayenneDataObject) ctxt.newObject(objEntity
.getName());
dao.writeProperty(oatr1.getName(), "test " + i);
}
ctxt.commitChanges();
}
finally {
sourceMap.removeObjEntity(objEntity.getName(), true);
sourceMap.removeDbEntity(dbEntity.getName(), true);
}
// clear up
map.removeObjEntity(objEntity.getName(), true);
map.removeDbEntity(dbEntity.getName(), true);
ctxt.getEntityResolver().clearCache();
assertNull(map.getObjEntity(objEntity.getName()));
assertNull(map.getDbEntity(dbEntity.getName()));
assertFalse(map.getDbEntities().contains(dbEntity));
assertTokensAndExecute(node, map, 1, 0);
assertTokensAndExecute(node, map, 0, 0);