use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class ClientExpressionIT method testExpressionFactoryOperators.
@Test
public void testExpressionFactoryOperators() throws Exception {
createDataSet();
SelectQuery<ClientMtTable1> table1Query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
List<ClientMtTable1> table1List = context.select(table1Query);
ClientMtTable1 element_7 = table1List.get(6);
// greater than, ">"
Expression exp = ExpressionFactory.greaterExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
List<ClientMtTable2> table2List = context.select(table2Query);
assertEquals(6, table2List.size());
// greater than or equal, ">="
exp = ExpressionFactory.greaterOrEqualExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
table2List = context.select(table2Query);
assertEquals(8, table2List.size());
// less than, "<"
exp = ExpressionFactory.lessExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
table2List = context.select(table2Query);
assertEquals(12, table2List.size());
// less than or equal, "<="
exp = ExpressionFactory.lessOrEqualExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
table2List = context.select(table2Query);
assertEquals(14, table2List.size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class ClientChannelServerDiffsIT method testReturnDiffClientArcChanges.
@Test
public void testReturnDiffClientArcChanges() {
final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler();
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false) {
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
GraphDiff serverDiff = super.onSync(originatingContext, changes, syncType);
assertNotNull(serverDiff);
serverDiff.apply(diffReader);
return serverDiff;
}
};
CayenneContext context = new CayenneContext(channel);
ClientMtTable1 o = context.newObject(ClientMtTable1.class);
ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
o.addToTable2Array(o2);
context.commitChanges();
assertEquals(2, diffReader.size);
diffReader.reset();
ClientMtTable2 o3 = context.newObject(ClientMtTable2.class);
o3.setTable1(o);
context.commitChanges();
assertEquals(1, diffReader.size);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedToOneRelationship.
@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
ClientMtTable1 altA = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 p = clientContext.newObject(ClientMtTable2.class);
p.setTable1(a);
p.setGlobalAttribute("PPP");
a.setGlobalAttribute1("X");
altA.setGlobalAttribute1("Y");
clientContext.commitChanges();
ObjectContext peer1 = runtime.newContext(clientContext);
ClientMtTable2 p1 = peer1.localObject(p);
ClientMtTable1 altA1 = peer1.localObject(altA);
ObjectContext peer2 = runtime.newContext(clientContext);
ClientMtTable2 p2 = peer2.localObject(p);
ClientMtTable1 altA2 = peer2.localObject(altA);
ClientMtTable1 a2 = peer2.localObject(a);
p1.setTable1(altA1);
assertSame(a2, p2.getTable1());
peer1.commitChangesToParent();
assertEquals(altA2, p2.getTable1());
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class RelationshipChangeIT method testChange.
@Test
public void testChange() {
ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 o2 = clientContext.newObject(ClientMtTable2.class);
ClientMtTable1 o3 = clientContext.newObject(ClientMtTable1.class);
o2.setTable1(o1);
assertEquals(1, o1.getTable2Array().size());
clientContext.commitChanges();
o2.setTable1(o3);
assertEquals(0, o1.getTable2Array().size());
assertEquals(1, o3.getTable2Array().size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class RemoteRollbackIT method testRollbackWithMultipleNewObjects.
// Catches a bug where new objects were unregistered within an object iterator, thus
// modifying the
// collection the iterator was iterating over (ConcurrentModificationException)
@Test
public void testRollbackWithMultipleNewObjects() {
String o1Name = "rollbackTestClientMtTable1";
String o2Title = "rollbackTestClientMtTable2";
ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1(o1Name);
ClientMtTable2 o2 = clientContext.newObject(ClientMtTable2.class);
o2.setGlobalAttribute(o2Title);
o2.setTable1(o1);
try {
clientContext.rollbackChanges();
} catch (Exception e) {
e.printStackTrace();
fail("rollbackChanges should not have caused the exception " + e.getMessage());
}
assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
}
Aggregations