use of org.apache.cayenne.DataObject in project cayenne by apache.
the class ObjectStoreIT method testObjectsUnregistered.
@Test
public void testObjectsUnregistered() 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.getObjectStore().objectsUnregistered(Collections.singletonList(object));
assertEquals(oid, object.getObjectId());
assertNull(context.getObjectStore().getNode(oid));
// in the future this may not be the case
assertNull(context.getObjectStore().getCachedSnapshot(oid));
}
use of org.apache.cayenne.DataObject in project cayenne by apache.
the class ObjectStoreIT method testRegisteredObjectsCount.
@Test
public void testRegisteredObjectsCount() throws Exception {
assertEquals(0, context.getObjectStore().registeredObjectsCount());
DataObject o1 = new MockDataObject();
o1.setObjectId(new ObjectId("T", "key1", "v1"));
context.getObjectStore().registerNode(o1.getObjectId(), o1);
assertEquals(1, context.getObjectStore().registeredObjectsCount());
// test object with same id
DataObject o2 = new MockDataObject();
o2.setObjectId(new ObjectId("T", "key1", "v1"));
context.getObjectStore().registerNode(o2.getObjectId(), o2);
assertEquals(1, context.getObjectStore().registeredObjectsCount());
// test new object
DataObject o3 = new MockDataObject();
o3.setObjectId(new ObjectId("T", "key3", "v3"));
context.getObjectStore().registerNode(o3.getObjectId(), o3);
assertEquals(2, context.getObjectStore().registeredObjectsCount());
}
use of org.apache.cayenne.DataObject in project cayenne by apache.
the class DataContextExtrasIT method testPartialObjectFromDataRow.
@Test
public void testPartialObjectFromDataRow() {
DataRow row = new DataRow(10);
row.put("ARTIST_ID", 100001);
row.put("ARTIST_NAME", "ArtistXYZ");
DataObject obj = context.objectFromDataRow(Artist.class, row);
assertNotNull(obj);
assertTrue(context.getGraphManager().registeredNodes().contains(obj));
assertEquals(PersistenceState.HOLLOW, obj.getPersistenceState());
assertNull(context.getObjectStore().getCachedSnapshot(obj.getObjectId()));
}
use of org.apache.cayenne.DataObject 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));
}
use of org.apache.cayenne.DataObject in project cayenne by apache.
the class DataContextIT method testInvalidateObjects_Vararg.
@Test
public void testInvalidateObjects_Vararg() 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(object);
assertSame(oid, object.getObjectId());
assertNull(context.getObjectStore().getCachedSnapshot(oid));
assertSame(object, context.getObjectStore().getNode(oid));
}
Aggregations