use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ManyToManyCandidateEntityTest method testOptimisationForManyToManyEntity.
@Test
public void testOptimisationForManyToManyEntity() {
ObjEntity manyToManyEntity = map.getObjEntity("Table1Table2");
ManyToManyCandidateEntity.build(manyToManyEntity).optimizeRelationships(new DefaultObjectNameGenerator(NoStemStemmer.getInstance()));
ObjEntity table1Entity = map.getObjEntity("Table1");
ObjEntity table2Entity = map.getObjEntity("Table2");
assertEquals(1, table1Entity.getRelationships().size());
assertEquals(table2Entity, new ArrayList<Relationship>(table1Entity.getRelationships()).get(0).getTargetEntity());
assertEquals(1, table2Entity.getRelationships().size());
assertEquals(table1Entity, new ArrayList<Relationship>(table2Entity.getRelationships()).get(0).getTargetEntity());
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class CreateTableToModelIT method testAddTable.
@Test
public void testAddTable() throws Exception {
dropTableIfPresent("NEW_TABLE");
assertTokensAndExecute(0, 0);
DbEntity dbEntity = new DbEntity("NEW_TABLE");
DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
column1.setMandatory(true);
column1.setPrimaryKey(true);
dbEntity.addAttribute(column1);
DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
column2.setMaxLength(10);
column2.setMandatory(false);
dbEntity.addAttribute(column2);
// for the new entity to the db
execute(mergerFactory().createCreateTableToDb(dbEntity));
List<MergerToken> tokens = createMergeTokens();
assertEquals(1, tokens.size());
MergerToken token = tokens.get(0);
if (token.getDirection().isToDb()) {
token = token.createReverse(mergerFactory());
}
assertTrue(token.getClass().getName(), token instanceof CreateTableToModel);
execute(token);
ObjEntity objEntity = null;
for (ObjEntity candidate : map.getObjEntities()) {
if (dbEntity.getName().equalsIgnoreCase(candidate.getDbEntityName())) {
objEntity = candidate;
break;
}
}
assertNotNull(objEntity);
assertEquals(objEntity.getClassName(), map.getDefaultPackage() + "." + objEntity.getName());
assertEquals(objEntity.getSuperClassName(), map.getDefaultSuperclass());
assertEquals(objEntity.getClientClassName(), map.getDefaultClientPackage() + "." + objEntity.getName());
assertEquals(objEntity.getClientSuperClassName(), map.getDefaultClientSuperclass());
assertEquals(1, objEntity.getAttributes().size());
assertEquals("java.lang.String", objEntity.getAttributes().iterator().next().getType());
// clear up
// fix psql case issue
map.removeDbEntity(objEntity.getDbEntity().getName(), true);
map.removeObjEntity(objEntity.getName(), true);
map.removeDbEntity(dbEntity.getName(), true);
resolver.refreshMappingCache();
assertNull(map.getObjEntity(objEntity.getName()));
assertNull(map.getDbEntity(dbEntity.getName()));
assertFalse(map.getDbEntities().contains(dbEntity));
assertTokensAndExecute(1, 0);
assertTokensAndExecute(0, 0);
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class NameBuilderTest method testName_Callbacks_ObjEntityContext.
@Test
public void testName_Callbacks_ObjEntityContext() {
ObjEntity entity = new ObjEntity();
String c0 = NameBuilder.builderForCallbackMethod(entity).name();
assertEquals("onEvent", c0);
entity.getCallbackMap().getPostAdd().addCallbackMethod(c0);
String c1 = NameBuilder.builderForCallbackMethod(entity).name();
assertEquals("onEvent1", c1);
entity.getCallbackMap().getPostAdd().addCallbackMethod(c1);
entity.addAttribute(new ObjAttribute("untitledAttr"));
String c3 = NameBuilder.builderForCallbackMethod(entity).baseName("getUntitledAttr").name();
assertEquals("getUntitledAttr1", c3);
entity.getCallbackMap().getPostAdd().addCallbackMethod(c3);
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class DataDomainIndirectDiffBuilder method processArcChange.
private void processArcChange(ObjectId nodeId, ArcId arcId) {
ObjEntity entity = resolver.getObjEntity(nodeId.getEntityName());
ObjRelationship relationship = entity.getRelationship(arcId.getForwardArc());
if (relationship != null && relationship.isSourceIndependentFromTargetChange()) {
// do not record temporary id mods...
if (!nodeId.isTemporary()) {
if (indirectModifications == null) {
indirectModifications = new HashSet<>();
}
indirectModifications.add(nodeId);
}
if (relationship.isFlattened() && relationship.isReadOnly()) {
throw new CayenneRuntimeException("Cannot change the read-only flattened relationship %s in ObjEntity '%s'.", relationship.getName(), relationship.getSourceEntity().getName());
}
}
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class InheritanceAwareEntityRowReader method postprocessRow.
@Override
void postprocessRow(ResultSet resultSet, DataRow dataRow) throws Exception {
if (postProcessor != null) {
postProcessor.postprocessRow(resultSet, dataRow);
}
ObjEntity entity = entityInheritanceTree.entityMatchingRow(dataRow);
dataRow.setEntityName(entity != null ? entity.getName() : entityName);
}
Aggregations