use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class PersistentObjectInContextIT method testResolveToManyReverseResolved.
@Test
public void testResolveToManyReverseResolved() throws Exception {
createTwoMtTable1sAnd2sDataSet();
ObjectId gid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, new Integer(1));
ClientMtTable1 t1 = (ClientMtTable1) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
assertNotNull(t1);
List<ClientMtTable2> t2s = t1.getTable2Array();
assertEquals(2, t2s.size());
for (ClientMtTable2 t2 : t2s) {
PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
assertFalse(holder.isFault());
assertSame(t1, holder.getValue());
}
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class ShallowMergeOperation_ClientIT method testMerge_NoOverride.
@Test
public void testMerge_NoOverride() throws Exception {
ObjectContext childContext = runtime.newContext(context);
final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
final ClientMtTable1 modified = context.newObject(ClientMtTable1.class);
context.commitChanges();
final ClientMtTable1 peerModified = (ClientMtTable1) Cayenne.objectForQuery(childContext, new ObjectIdQuery(modified.getObjectId()));
modified.setGlobalAttribute1("M1");
peerModified.setGlobalAttribute1("M2");
assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Persistent peerModified2 = op.merge(modified);
assertSame(peerModified, peerModified2);
assertEquals(PersistenceState.MODIFIED, peerModified2.getPersistenceState());
assertEquals("M2", peerModified.getGlobalAttribute1());
assertEquals("M1", modified.getGlobalAttribute1());
}
});
}
Aggregations