use of org.apache.cayenne.ObjectId 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.ObjectId 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.ObjectId in project cayenne by apache.
the class DataContextExtrasIT method testManualIdProcessingOnCommit.
@Test
public void testManualIdProcessingOnCommit() throws Exception {
Artist object = context.newObject(Artist.class);
object.setArtistName("ABC");
assertEquals(PersistenceState.NEW, object.getPersistenceState());
// do a manual ID substitution
ObjectId manualId = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 77777);
object.setObjectId(manualId);
context.commitChanges();
assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
assertSame(object, context.getGraphManager().getNode(manualId));
assertEquals(manualId, object.getObjectId());
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextIT method testBeforeHollowDeleteShouldChangeStateToCommited.
@Test
public void testBeforeHollowDeleteShouldChangeStateToCommited() throws Exception {
createSingleArtistDataSet();
Artist hollow = Cayenne.objectForPK(context, Artist.class, 33001);
context.invalidateObjects(hollow);
assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
// testing this...
context.deleteObjects(hollow);
assertSame(hollow, context.getGraphManager().getNode(new ObjectId("Artist", "ARTIST_ID", 33001)));
assertEquals("artist1", hollow.getArtistName());
assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextIT method testInvalidateObjects.
@Test
public void testInvalidateObjects() throws Exception {
DataRow row = new DataRow(10);
row.put("ARTIST_ID", new Integer(1));
row.put("ARTIST_NAME", "ArtistXYZ");
row.put("DATE_OF_BIRTH", new Date());
DataObject object = context.objectFromDataRow(Artist.class, row);
ObjectId oid = object.getObjectId();
// insert object into the ObjectStore
context.getObjectStore().registerNode(oid, object);
assertSame(object, context.getObjectStore().getNode(oid));
assertNotNull(context.getObjectStore().getCachedSnapshot(oid));
context.invalidateObjects(Collections.singleton(object));
assertSame(oid, object.getObjectId());
assertNull(context.getObjectStore().getCachedSnapshot(oid));
assertSame(object, context.getObjectStore().getNode(oid));
}
Aggregations