use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class ClientExpressionIT method testPersistentValueInExpression.
@Test
public void testPersistentValueInExpression() throws Exception {
ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
context.commitChanges();
Expression scalar = ExpressionFactory.matchExp(null, t1);
Expression list = ExpressionFactory.matchAllExp("|", Arrays.asList(t1, t2));
assertEquals(t1.getObjectId(), scalar.getOperand(1));
assertEquals(t1.getObjectId(), ((ASTEqual) list.getOperand(0)).getOperand(1));
assertEquals(t2.getObjectId(), ((ASTEqual) list.getOperand(1)).getOperand(1));
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class ClientExpressionIT method testParams.
@Test
public void testParams() 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_1 = table1List.get(0);
ClientMtTable1 element_5 = table1List.get(4);
Expression exp = ExpressionFactory.exp("table1 = $attr");
exp = exp.params(Collections.singletonMap("attr", element_1));
SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
List<ClientMtTable2> table2List = context.select(table2Query);
assertEquals(2, table2List.size());
exp = exp.andExp(ExpressionFactory.exp("table1 = $attr")).params(Collections.singletonMap("attr", element_5));
table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
table2List = context.select(table2Query);
assertEquals(0, table2List.size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class ClientExpressionIT method testExpressionFactoryBetween.
@Test
public void testExpressionFactoryBetween() 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_1 = table1List.get(0);
ClientMtTable1 element_7 = table1List.get(6);
// between
Expression exp = ExpressionFactory.betweenExp(ClientMtTable2.TABLE1_PROPERTY, element_1, element_7);
SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
List<ClientMtTable2> table2List = context.select(table2Query);
assertEquals(14, table2List.size());
// not between
exp = ExpressionFactory.notBetweenExp(ClientMtTable2.TABLE1_PROPERTY, element_1, element_7);
table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
table2List = context.select(table2Query);
assertEquals(6, table2List.size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class ClientObjectSelectIT method testPageSelect.
@Test
public void testPageSelect() throws Exception {
final ObjectSelect<ClientMtTable1> objectSelect = ObjectSelect.query(ClientMtTable1.class).pageSize(5);
final List<ClientMtTable1> list = objectSelect.select(context);
assertNotNull(list);
assertEquals(RemoteIncrementalFaultList.class, list.getClass());
int count = serverCaseDataChannelInterceptor.runWithQueryCounter(new UnitTestClosure() {
@Override
public void execute() {
assertNotNull(list.get(0));
assertNotNull(list.get(4));
assertNotNull(list.get(5));
assertNotNull(list.get(6));
}
});
assertEquals(1, count);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class ClientChannelServerDiffsIT method testReturnDiffInPrePersist.
@Test
public void testReturnDiffInPrePersist() {
final List<GenericDiff> diffs = new ArrayList<GenericDiff>();
final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler() {
@Override
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
super.nodePropertyChanged(nodeId, property, oldValue, newValue);
diffs.add(new GenericDiff((ObjectId) nodeId, property, oldValue, newValue));
}
};
LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
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);
ObjectId tempId = o.getObjectId();
o.setServerAttribute1("YY");
context.commitChanges();
assertEquals(2, diffReader.size);
assertEquals(1, diffs.size());
assertEquals(tempId, diffs.get(0).sourceId);
assertEquals(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, diffs.get(0).property);
assertNull(diffs.get(0).oldValue);
assertEquals("XXX", diffs.get(0).newValue);
} finally {
callbackRegistry.clear();
}
}
Aggregations