use of org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity in project cayenne by apache.
the class IdentityColumnsIT method testMultipleNewObjectsSeparateTables.
/**
* Tests that insert in two tables with identity pk does not generate a
* conflict. See CAY-341 for the original bug.
*/
@Test
public void testMultipleNewObjectsSeparateTables() throws Exception {
GeneratedColumnTestEntity idObject1 = context.newObject(GeneratedColumnTestEntity.class);
idObject1.setName("o1");
GeneratedColumnTest2 idObject2 = context.newObject(GeneratedColumnTest2.class);
idObject2.setName("o2");
context.commitChanges();
}
use of org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity in project cayenne by apache.
the class IdentityColumnsIT method testUnrelatedUpdate.
/**
* Tests CAY-422 bug.
*/
@Test
public void testUnrelatedUpdate() throws Exception {
GeneratedColumnTestEntity m = context.newObject(GeneratedColumnTestEntity.class);
m.setName("m");
GeneratedColumnDep d = context.newObject(GeneratedColumnDep.class);
d.setName("d");
d.setToMaster(m);
context.commitChanges();
context.invalidateObjects(m, d);
context.prepareForAccess(d, null, false);
// this line caused CAY-422 error
d.getToMaster();
d.setName("new name");
context.commitChanges();
}
use of org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity in project cayenne by apache.
the class IdentityColumnsIT method testCAY823.
/**
* Tests a bug casued by the ID Java type mismatch vs the default JDBC type
* of the ID column.
*/
@Test
public void testCAY823() throws Exception {
GeneratedColumnTestEntity idObject = context.newObject(GeneratedColumnTestEntity.class);
String name = "n_" + System.currentTimeMillis();
idObject.setName(name);
idObject.getObjectContext().commitChanges();
ObjectId id = idObject.getObjectId();
context.invalidateObjects(idObject);
SelectQuery q = new SelectQuery(GeneratedColumnTestEntity.class);
q.setPageSize(10);
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
// per CAY-823 an attempt to resolve an object results in an exception
assertEquals(id, ((Persistent) results.get(0)).getObjectId());
}
use of org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity in project cayenne by apache.
the class IdentityColumnsIT method testMultipleNewObjects.
@Test
public void testMultipleNewObjects() throws Exception {
String[] names = new String[] { "n1_" + System.currentTimeMillis(), "n2_" + System.currentTimeMillis(), "n3_" + System.currentTimeMillis() };
GeneratedColumnTestEntity[] idObjects = new GeneratedColumnTestEntity[] { context.newObject(GeneratedColumnTestEntity.class), context.newObject(GeneratedColumnTestEntity.class), context.newObject(GeneratedColumnTestEntity.class) };
for (int i = 0; i < idObjects.length; i++) {
idObjects[i].setName(names[i]);
}
context.commitChanges();
int[] ids = new int[idObjects.length];
for (int i = 0; i < idObjects.length; i++) {
ids[i] = Cayenne.intPKForObject(idObjects[i]);
assertTrue(ids[i] > 0);
}
context.invalidateObjects(idObjects);
for (int i = 0; i < ids.length; i++) {
GeneratedColumnTestEntity object = Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, ids[i]);
assertNotNull(object);
assertEquals(names[i], object.getName());
}
}
use of org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity in project cayenne by apache.
the class IdentityColumnsIT method testUpdateDependentWithNewMaster.
@Test
public void testUpdateDependentWithNewMaster() throws Exception {
GeneratedColumnTestEntity master1 = context.newObject(GeneratedColumnTestEntity.class);
master1.setName("aaa");
GeneratedColumnDep dependent = context.newObject(GeneratedColumnDep.class);
dependent.setName("aaa");
dependent.setToMaster(master1);
context.commitChanges();
// change master
GeneratedColumnTestEntity master2 = context.newObject(GeneratedColumnTestEntity.class);
master2.setName("bbb");
// TESTING THIS
dependent.setToMaster(master2);
context.commitChanges();
int id1 = Cayenne.intPKForObject(master2);
assertTrue(id1 >= 0);
int id2 = Cayenne.intPKForObject(dependent);
assertTrue(id2 >= 0);
assertEquals(id1, id2);
context.invalidateObjects(master2, dependent);
assertNotNull(Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, id1));
assertNotNull(Cayenne.objectForPK(context, GeneratedColumnDep.class, id2));
}
Aggregations