use of org.apache.cayenne.DataObject 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.DataObject 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));
}
use of org.apache.cayenne.DataObject in project cayenne by apache.
the class DataContextDelegateSharedCacheIT method testBlockedShouldMergeChanges.
/**
* Test case to prove that delegate method can block changes made by ObjectStore.
*
* @throws Exception
*/
@Test
public void testBlockedShouldMergeChanges() throws Exception {
String oldName = artist.getArtistName();
DataContextDelegate delegate = new MockDataContextDelegate() {
@Override
public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore) {
return false;
}
};
context1.setDelegate(delegate);
// make sure we have a fully resolved copy of an artist object
// in the second context
Artist altArtist = context1.localObject(artist);
assertNotNull(altArtist);
assertFalse(altArtist == artist);
assertEquals(oldName, altArtist.getArtistName());
assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
// Update and save artist in peer context
artist.setArtistName("version2");
context.commitChanges();
// assert that delegate was able to block the merge
assertEquals(oldName, altArtist.getArtistName());
}
use of org.apache.cayenne.DataObject in project cayenne by apache.
the class SimpleIdIncrementalFaultListPrefetchIT method testPrefetch4.
/**
* Test that a to-one relationship is initialized.
*/
@Test
public void testPrefetch4() throws Exception {
createArtistsAndPaintingsDataSet();
SelectQuery q = new SelectQuery(Painting.class);
q.setPageSize(3);
q.addPrefetch("toArtist");
IncrementalFaultList<?> result = (IncrementalFaultList) context.performQuery(q);
// get an objects from the second page
final DataObject p1 = (DataObject) result.get(q.getPageSize());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Object toOnePrefetch = p1.readNestedProperty("toArtist");
assertNotNull(toOnePrefetch);
assertTrue("Expected DataObject, got: " + toOnePrefetch.getClass().getName(), toOnePrefetch instanceof DataObject);
DataObject a1 = (DataObject) toOnePrefetch;
assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
}
});
}
use of org.apache.cayenne.DataObject in project cayenne by apache.
the class Expression_ParamsTest method testInParameter_AsValues.
@Test
public void testInParameter_AsValues() throws Exception {
Expression inExp = ExpressionFactory.exp("k1 in ($ap, $bp)");
String e1String = "k1 in (\"a\", \"b\")";
Expression e1 = ExpressionFactory.exp(e1String);
Map<String, Object> params = new HashMap<String, Object>();
params.put("ap", "a");
params.put("bp", "b");
Expression transformed = inExp.params(params);
TstTraversalHandler.compareExps(e1, transformed);
assertEquals(e1String, transformed.toString());
// just in case manually check params
DataObject o1 = new CayenneDataObject();
o1.writePropertyDirectly("k1", "a");
assertTrue(transformed.match(o1));
DataObject o2 = new CayenneDataObject();
o2.writePropertyDirectly("k1", "x");
assertFalse(transformed.match(o2));
}
Aggregations