use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class PersistentObjectInContextIT method testToOneRelationship.
@Test
public void testToOneRelationship() throws Exception {
createTwoMtTable1sAnd2sDataSet();
ObjectId gid = new ObjectId("MtTable2", MtTable2.TABLE2_ID_PK_COLUMN, new Integer(1));
ClientMtTable2 mtTable21 = (ClientMtTable2) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
assertNotNull(mtTable21);
ClientMtTable1 mtTable1 = mtTable21.getTable1();
assertNotNull("To one relationship incorrectly resolved to null", mtTable1);
assertEquals("g1", mtTable1.getGlobalAttribute1());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 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.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class ClientServerChannelIT method testOnQueryPrefetchingToMany.
@Test
public void testOnQueryPrefetchingToMany() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery query = new SelectQuery(ClientMtTable1.class);
query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
query.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<?> results = clientServerChannel.onQuery(null, query).firstList();
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o1 = (ClientMtTable1) results.get(0);
assertNull(o1.getObjectContext());
List<ClientMtTable2> children1 = o1.getTable2Array();
assertEquals(2, children1.size());
for (ClientMtTable2 o : children1) {
assertNull(o.getObjectContext());
}
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class ClientExpressionIT method testExpressionFactoryMatchAll.
@Test
public void testExpressionFactoryMatchAll() throws Exception {
createDataSet();
SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class);
table2Query.addOrdering(new Ordering("db:TABLE2_ID", SortOrder.ASCENDING));
List<ClientMtTable2> table2List = context.select(table2Query);
ClientMtTable2 element_1 = table2List.get(0);
ClientMtTable2 element_2 = table2List.get(10);
assertEquals(element_1.getTable1(), element_2.getTable1());
Expression exp = ExpressionFactory.matchAllExp("|" + ClientMtTable1.TABLE2ARRAY_PROPERTY, Arrays.asList(element_1, element_2));
SelectQuery<ClientMtTable1> table1Query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class, exp);
List<ClientMtTable1> table1List = context.select(table1Query);
assertEquals(1, table1List.size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class ClientExpressionIT method testExpressionFactoryIn.
@Test
public void testExpressionFactoryIn() 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_3 = table1List.get(2);
ClientMtTable1 element_8 = table1List.get(7);
// IN expression via Collection
Expression exp = ExpressionFactory.inExp(ClientMtTable2.TABLE1_PROPERTY, table1List.subList(3, 6));
SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
List<ClientMtTable2> table2List = context.select(table2Query);
assertEquals(6, table2List.size());
// IN expression via Array
exp = ExpressionFactory.inExp(ClientMtTable2.TABLE1_PROPERTY, element_3, element_8);
table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
table2List = context.select(table2Query);
assertEquals(4, table2List.size());
}
Aggregations