Search in sources :

Example 6 with GeneratedColumnTestEntity

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

the class IdentityColumnsIT method testPropagateToDependent.

@Test
public void testPropagateToDependent() throws Exception {
    GeneratedColumnTestEntity idObject = context.newObject(GeneratedColumnTestEntity.class);
    idObject.setName("aaa");
    GeneratedColumnDep dependent = idObject.getObjectContext().newObject(GeneratedColumnDep.class);
    dependent.setName("aaa");
    dependent.setToMaster(idObject);
    context.commitChanges();
    // this will throw an exception if id wasn't generated
    int id1 = Cayenne.intPKForObject(idObject);
    assertTrue(id1 >= 0);
    int id2 = Cayenne.intPKForObject(dependent);
    assertTrue(id2 >= 0);
    assertEquals(id1, id2);
    // refetch from DB
    context.invalidateObjects(idObject, dependent);
    assertNotNull(Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, id1));
    assertNotNull(Cayenne.objectForPK(context, GeneratedColumnDep.class, id2));
}
Also used : GeneratedColumnDep(org.apache.cayenne.testdo.generated.GeneratedColumnDep) GeneratedColumnTestEntity(org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity) Test(org.junit.Test)

Example 7 with GeneratedColumnTestEntity

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

the class IdentityColumnsIT method testNewObject.

@Test
public void testNewObject() throws Exception {
    GeneratedColumnTestEntity idObject = context.newObject(GeneratedColumnTestEntity.class);
    String name = "n_" + System.currentTimeMillis();
    idObject.setName(name);
    idObject.getObjectContext().commitChanges();
    // this will throw an exception if id wasn't generated one way or
    // another
    int id = Cayenne.intPKForObject(idObject);
    assertTrue(id >= 0);
    // make sure that id is the same as id in the DB
    context.invalidateObjects(idObject);
    GeneratedColumnTestEntity object = Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, id);
    assertNotNull(object);
    assertEquals(name, object.getName());
}
Also used : GeneratedColumnTestEntity(org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity) Test(org.junit.Test)

Aggregations

GeneratedColumnTestEntity (org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity)7 Test (org.junit.Test)7 GeneratedColumnDep (org.apache.cayenne.testdo.generated.GeneratedColumnDep)3 ObjectId (org.apache.cayenne.ObjectId)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 GeneratedColumnTest2 (org.apache.cayenne.testdo.generated.GeneratedColumnTest2)1