use of org.apache.cayenne.ObjectId 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));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextObjectIdQueryIT method testNoRefreshValuesNew.
@Test
public void testNoRefreshValuesNew() {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
context.commitChanges();
context.performGenericQuery(new SQLTemplate(Artist.class, "UPDATE ARTIST SET ARTIST_NAME = 'Y'"));
long id = Cayenne.longPKForObject(a);
ObjectIdQuery query = new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, id), false, ObjectIdQuery.CACHE);
Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
assertEquals("X", a1.getArtistName());
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache_AfterCayenneInsert.
@Test
public void testPolymorphicSharedCache_AfterCayenneInsert() throws SQLException {
// see CAY-2101... we are trying to get a snapshot from a new object in the shared cache, and then read this
// object via a relationship, so that shared cache is consulted
Employee e = context1.newObject(Employee.class);
e.setName("E1");
e.setSalary(1234.01f);
context1.commitChanges();
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", Cayenne.intPKForObject(e)), false, ObjectIdQuery.CACHE);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use different context to ensure we hit shared cache
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
assertTrue(ap1 instanceof Employee);
}
});
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextObjectTrackingIT method testInvalidateObjects_Vararg.
@Test
public void testInvalidateObjects_Vararg() {
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 obj = context.objectFromDataRow(Artist.class, row);
ObjectId oid = obj.getObjectId();
assertEquals(PersistenceState.COMMITTED, obj.getPersistenceState());
assertSame(context, obj.getObjectContext());
assertSame(obj, context.getGraphManager().getNode(oid));
context.invalidateObjects(obj);
assertEquals(PersistenceState.HOLLOW, obj.getPersistenceState());
assertSame(context, obj.getObjectContext());
assertSame(oid, obj.getObjectId());
assertNull(context.getObjectStore().getCachedSnapshot(oid));
assertNotNull(context.getGraphManager().getNode(oid));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextObjectTrackingIT method testUnregisterObject.
@Test
public void testUnregisterObject() {
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 obj = context.objectFromDataRow(Artist.class, row);
ObjectId oid = obj.getObjectId();
assertEquals(PersistenceState.COMMITTED, obj.getPersistenceState());
assertSame(context, obj.getObjectContext());
assertSame(obj, context.getGraphManager().getNode(oid));
context.unregisterObjects(Collections.singletonList(obj));
assertEquals(PersistenceState.TRANSIENT, obj.getPersistenceState());
assertNull(obj.getObjectContext());
assertEquals(oid, obj.getObjectId());
assertNull(context.getGraphManager().getNode(oid));
assertNull(context.getObjectStore().getCachedSnapshot(oid));
}
Aggregations