use of org.apache.cayenne.testdo.generated.GeneratedColumnCompMaster in project cayenne by apache.
the class IdentityColumnsIT method testCompoundPKWithGeneratedColumn.
@Test
public void testCompoundPKWithGeneratedColumn() throws Exception {
if (adapter.supportsGeneratedKeys()) {
// only works for generated keys, as the entity tested has one
// Cayenne
// auto-pk and one generated key
String masterName = "m_" + System.currentTimeMillis();
String depName1 = "dep1_" + System.currentTimeMillis();
String depName2 = "dep2_" + System.currentTimeMillis();
GeneratedColumnCompMaster master = context.newObject(GeneratedColumnCompMaster.class);
master.setName(masterName);
GeneratedColumnCompKey dep1 = context.newObject(GeneratedColumnCompKey.class);
dep1.setName(depName1);
dep1.setToMaster(master);
GeneratedColumnCompKey dep2 = context.newObject(GeneratedColumnCompKey.class);
dep2.setName(depName2);
dep2.setToMaster(master);
context.commitChanges();
int masterId = Cayenne.intPKForObject(master);
ObjectId id2 = dep2.getObjectId();
// check propagated id
Number propagatedID2 = (Number) id2.getIdSnapshot().get(GeneratedColumnCompKey.PROPAGATED_PK_PK_COLUMN);
assertNotNull(propagatedID2);
assertEquals(masterId, propagatedID2.intValue());
// check Cayenne-generated ID
Number cayenneGeneratedID2 = (Number) id2.getIdSnapshot().get(GeneratedColumnCompKey.AUTO_PK_PK_COLUMN);
assertNotNull(cayenneGeneratedID2);
// check DB-generated ID
Number dbGeneratedID2 = (Number) id2.getIdSnapshot().get(GeneratedColumnCompKey.GENERATED_COLUMN_PK_COLUMN);
assertNotNull(dbGeneratedID2);
context.invalidateObjects(master, dep1, dep2);
Object fetchedDep2 = Cayenne.objectForPK(context, id2);
assertNotNull(fetchedDep2);
}
}
Aggregations