use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class NumericTypesIT method testDecimalPK.
@Test
public void testDecimalPK() throws Exception {
// populate (testing insert as well)
DecimalPKTestEntity object = context.newObject(DecimalPKTestEntity.class);
object.setName("o1");
object.setDecimalPK(new BigDecimal("1.25"));
context.commitChanges();
ObjectId syntheticId = new ObjectId("DecimalPKTestEntity", "DECIMAL_PK", new BigDecimal("1.25"));
assertSame(object, context.getGraphManager().getNode(syntheticId));
context.deleteObjects(object);
context.commitChanges();
}
use of org.apache.cayenne.ObjectId 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.ObjectId 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.ObjectId in project cayenne by apache.
the class ObjectStoreTest method testRegisterNode.
@Test
public void testRegisterNode() {
ObjectId id = new ObjectId("E1", "ID", 500);
Persistent object = mock(Persistent.class);
objectStore.registerNode(id, object);
assertSame(object, objectStore.getNode(id));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ObjectStoreTest method testUnregisterNode.
@Test
public void testUnregisterNode() {
ObjectId id = new ObjectId("E1", "ID", 500);
Persistent object = mock(Persistent.class);
objectStore.registerNode(id, object);
Object unregistered = objectStore.unregisterNode(id);
assertSame(object, unregistered);
verify(object, times(0)).setObjectId(null);
verify(object).setObjectContext(null);
verify(object).setPersistenceState(PersistenceState.TRANSIENT);
}
Aggregations