use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPrefetchingToOne.
@Test
public void testPrefetchingToOne() throws Exception {
createTwoMtTable1sAnd2sDataSet();
final ObjectId prefetchedId = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 1);
SelectQuery q = new SelectQuery(ClientMtTable2.class);
q.addOrdering(ClientMtTable2.GLOBAL_ATTRIBUTE_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
final List<ClientMtTable2> results = clientContext.performQuery(q);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, results.size());
for (ClientMtTable2 o : results) {
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(clientContext, o.getObjectContext());
ClientMtTable1 o1 = o.getTable1();
assertNotNull(o1);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(clientContext, o1.getObjectContext());
assertEquals(prefetchedId, o1.getObjectId());
}
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testDeleteNew.
@Test
public void testDeleteNew() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
clientContext.commitChanges();
ClientMtTable2 p = child.newObject(ClientMtTable2.class);
ClientMtTable1 aChild = (ClientMtTable1) Cayenne.objectForPK(child, a.getObjectId());
p.setGlobalAttribute("X");
aChild.addToTable2Array(p);
child.commitChangesToParent();
child.deleteObjects(p);
aChild.removeFromTable2Array(p);
child.commitChangesToParent();
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testPrefetchingToOne.
@Test
public void testPrefetchingToOne() throws Exception {
final ClientMtTable1 mt11 = clientContext.newObject(ClientMtTable1.class);
clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 mt21 = clientContext.newObject(ClientMtTable2.class);
ClientMtTable2 mt22 = clientContext.newObject(ClientMtTable2.class);
mt21.setTable1(mt11);
mt22.setTable1(mt11);
clientContext.commitChanges();
final ObjectContext child = runtime.newContext(clientContext);
SelectQuery<ClientMtTable2> q = new SelectQuery<ClientMtTable2>(ClientMtTable2.class);
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
final List<ClientMtTable2> results = child.select(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, results.size());
Iterator<?> it = results.iterator();
while (it.hasNext()) {
ClientMtTable2 o = (ClientMtTable2) it.next();
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(child, o.getObjectContext());
ClientMtTable1 o1 = o.getTable1();
assertNotNull(o1);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(child, o1.getObjectContext());
assertEquals(mt11.getObjectId(), o1.getObjectId());
}
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testNullifyToOne.
/**
* A test case for CAY-698 bug.
*/
@Test
public void testNullifyToOne() throws Exception {
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 b = clientContext.newObject(ClientMtTable2.class);
a.addToTable2Array(b);
clientContext.commitChanges();
final ObjectContext child = runtime.newContext(clientContext);
ObjectContext childPeer = runtime.newContext(clientContext);
final ClientMtTable2 childP1 = (ClientMtTable2) Cayenne.objectForPK(child, b.getObjectId());
// trigger object creation in the peer nested DC
Cayenne.objectForPK(childPeer, b.getObjectId());
childP1.setTable1(null);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
child.commitChangesToParent();
assertEquals(PersistenceState.COMMITTED, childP1.getPersistenceState());
ClientMtTable2 parentP1 = (ClientMtTable2) clientContext.getGraphManager().getNode(childP1.getObjectId());
assertNotNull(parentP1);
assertEquals(PersistenceState.MODIFIED, parentP1.getPersistenceState());
assertNull(parentP1.getTable1());
// check that arc changes got recorded in the parent context
GraphDiff diffs = clientContext.internalGraphManager().getDiffs();
final int[] arcDiffs = new int[1];
diffs.apply(new GraphChangeHandler() {
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
arcDiffs[0]++;
}
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
arcDiffs[0]--;
}
public void nodeCreated(Object nodeId) {
}
public void nodeIdChanged(Object nodeId, Object newId) {
}
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
}
public void nodeRemoved(Object nodeId) {
}
});
assertEquals(-2, arcDiffs[0]);
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testAddRemove.
@Test
public void testAddRemove() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 a = child.newObject(ClientMtTable1.class);
a.setGlobalAttribute1("X");
child.commitChanges();
ClientMtTable2 p1 = child.newObject(ClientMtTable2.class);
p1.setGlobalAttribute("P1");
a.addToTable2Array(p1);
ClientMtTable2 p2 = child.newObject(ClientMtTable2.class);
p2.setGlobalAttribute("P2");
a.addToTable2Array(p2);
a.removeFromTable2Array(p2);
// this causes an error on commit
child.deleteObjects(p2);
child.commitChangesToParent();
}
Aggregations