Search in sources :

Example 1 with GeneratedF2

use of org.apache.cayenne.testdo.generated.GeneratedF2 in project cayenne by apache.

the class IdentityColumnsIT method testGeneratedJoinInFlattenedRelationship.

@Test
public void testGeneratedJoinInFlattenedRelationship() throws Exception {
    // before saving objects, let's manually access PKGenerator to get a
    // base PK value
    // for comparison
    DbEntity joinTableEntity = context.getEntityResolver().getDbEntity(joinTable.getTableName());
    DbAttribute pkAttribute = joinTableEntity.getAttribute("ID");
    Number pk = (Number) adapter.getPkGenerator().generatePk(node, pkAttribute);
    GeneratedF1 f1 = context.newObject(GeneratedF1.class);
    GeneratedF2 f2 = context.newObject(GeneratedF2.class);
    f1.addToF2(f2);
    context.commitChanges();
    int id = joinTable.getInt("ID");
    assertTrue(id > 0);
    // base value
    if (adapter.supportsGeneratedKeys()) {
        assertFalse("Looks like auto-increment wasn't used for the join table. ID: " + id, id == pk.intValue() + 1);
    } else {
        assertEquals(id, pk.intValue() + 1);
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) GeneratedF1(org.apache.cayenne.testdo.generated.GeneratedF1) GeneratedF2(org.apache.cayenne.testdo.generated.GeneratedF2) Test(org.junit.Test)

Aggregations

DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 GeneratedF1 (org.apache.cayenne.testdo.generated.GeneratedF1)1 GeneratedF2 (org.apache.cayenne.testdo.generated.GeneratedF2)1 Test (org.junit.Test)1