use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testRollbackChanges.
@Test
public void testRollbackChanges() throws Exception {
ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
o.setGlobalAttribute1("1");
clientContext.commitChanges();
assertEquals("1", o.getGlobalAttribute1());
o.setGlobalAttribute1("2");
assertEquals("2", o.getGlobalAttribute1());
clientContext.rollbackChanges();
assertEquals("1", o.getGlobalAttribute1());
assertTrue(clientContext.modifiedObjects().isEmpty());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPerformPaginatedQuery.
@Test
public void testPerformPaginatedQuery() throws Exception {
createEightMtTable1s();
SelectQuery query = new SelectQuery(ClientMtTable1.class);
query.setPageSize(5);
List<ClientMtTable1> objects = clientContext.performQuery(query);
assertNotNull(objects);
assertTrue(objects instanceof RemoteIncrementalFaultList);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testOIDQueryInterception.
@Test
public void testOIDQueryInterception() throws Exception {
final ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
o.setGlobalAttribute1("aaa");
// fetch new
final ObjectIdQuery q1 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> objects = clientContext.performQuery(q1);
assertEquals(1, objects.size());
assertSame(o, objects.get(0));
}
});
clientContext.commitChanges();
// fetch committed
final ObjectIdQuery q2 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> objects = clientContext.performQuery(q2);
assertEquals(1, objects.size());
assertSame(o, objects.get(0));
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class NestedCayenneContextIT method testChangeRel.
@Test
public void testChangeRel() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 a = child.newObject(ClientMtTable1.class);
ClientMtTable2 b = child.newObject(ClientMtTable2.class);
child.commitChanges();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
a.addToTable2Array(b);
assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());
child.commitChangesToParent();
ClientMtTable1 parentA = (ClientMtTable1) clientContext.getGraphManager().getNode(a.getObjectId());
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
assertEquals(1, parentA.getTable2Array().size());
clientContext.commitChanges();
assertEquals(PersistenceState.COMMITTED, parentA.getPersistenceState());
a.removeFromTable2Array(b);
assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());
child.commitChangesToParent();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
assertEquals(0, parentA.getTable2Array().size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class NestedCayenneContextIT method testCommitChangesToParentOneToMany.
@Test
public void testCommitChangesToParentOneToMany() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 master = child.newObject(ClientMtTable1.class);
ClientMtTable2 dep = child.newObject(ClientMtTable2.class);
master.addToTable2Array(dep);
child.commitChangesToParent();
ClientMtTable1 masterParent = (ClientMtTable1) clientContext.getGraphManager().getNode(master.getObjectId());
ClientMtTable2 depParent = (ClientMtTable2) clientContext.getGraphManager().getNode(dep.getObjectId());
assertNotNull(masterParent);
assertNotNull(depParent);
assertSame(masterParent, depParent.getTable1());
assertTrue(masterParent.getTable2Array().contains(depParent));
// check that arc changes got recorded in the parent context
GraphDiff diffs = clientContext.internalGraphManager().getDiffs();
final int[] arcDiffs = new int[1];
final int[] newNodes = 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) {
newNodes[0]++;
}
public void nodeIdChanged(Object nodeId, Object newId) {
}
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
}
public void nodeRemoved(Object nodeId) {
newNodes[0]--;
}
});
assertEquals(2, newNodes[0]);
assertEquals(2, arcDiffs[0]);
}
Aggregations