use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testToManyRelationshipWithMeaningfulPK1.
@Test
public void testToManyRelationshipWithMeaningfulPK1() {
MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
obj.setPkAttribute(1000);
obj.setDescr("aaa-aaa");
context.commitChanges();
// must be able to resolve to-many relationship
ObjectContext context = runtime.newContext();
List<MeaningfulPKTest1> objects = ObjectSelect.query(MeaningfulPKTest1.class).select(context);
assertEquals(1, objects.size());
obj = objects.get(0);
assertEquals(0, obj.getMeaningfulPKDepArray().size());
}
use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testChangeKey.
@Test
public void testChangeKey() {
MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
obj.setPkAttribute(1000);
obj.setDescr("aaa-aaa");
context.commitChanges();
obj.setPkAttribute(2000);
context.commitChanges();
// assert that object id got fixed
ObjectId id = obj.getObjectId();
assertEquals(2000, id.getIdSnapshot().get("PK_ATTRIBUTE"));
}
use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testInsertWithMeaningfulPK.
@Test
public void testInsertWithMeaningfulPK() {
MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
obj.setPkAttribute(1000);
obj.setDescr("aaa-aaa");
context.commitChanges();
ObjectId objId = new ObjectId("MeaningfulPKTest1", MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN, 1000);
ObjectIdQuery q = new ObjectIdQuery(objId, true, ObjectIdQuery.CACHE_REFRESH);
@SuppressWarnings("unchecked") List<DataRow> result = (List<DataRow>) context.performQuery(q);
assertEquals(1, result.size());
assertEquals(1000, result.get(0).get(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
}
use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testGeneratedIntPK.
@Test
public void testGeneratedIntPK() {
MeaningfulPKTest1 obj1 = context.newObject(MeaningfulPKTest1.class);
obj1.setIntAttribute(10);
MeaningfulPKTest1 obj2 = context.newObject(MeaningfulPKTest1.class);
obj2.setIntAttribute(20);
context.commitChanges();
ObjectContext context = runtime.newContext();
List<MeaningfulPKTest1> objects = ObjectSelect.query(MeaningfulPKTest1.class).select(context);
assertEquals(2, objects.size());
assertNotEquals(0, obj1.getPkAttribute());
assertNotEquals(0, obj2.getPkAttribute());
assertNotEquals(obj1.getPkAttribute(), obj2.getPkAttribute());
}
use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1 in project cayenne by apache.
the class DataContextEntityWithMeaningfulPKIT method testGeneratedKey.
@Test
public void testGeneratedKey() {
MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
obj.setDescr("aaa-aaa");
context.commitChanges();
assertNotEquals(0, obj.getPkAttribute());
assertSame(obj, Cayenne.objectForPK(context, MeaningfulPKTest1.class, obj.getPkAttribute()));
int id = Cayenne.intPKForObject(obj);
Map snapshot = context.getObjectStore().getDataRowCache().getCachedSnapshot(obj.getObjectId());
assertNotNull(snapshot);
assertTrue(snapshot.containsKey(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
assertEquals(id, snapshot.get(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
}
Aggregations