use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class NestedCayenneContextIT method testPrefetchingToMany.
@Test
public void testPrefetchingToMany() throws Exception {
ClientMtTable1 mt11 = clientContext.newObject(ClientMtTable1.class);
mt11.setGlobalAttribute1("1");
ClientMtTable1 mt12 = clientContext.newObject(ClientMtTable1.class);
mt12.setGlobalAttribute1("2");
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<ClientMtTable1> q = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
q.addOrdering("globalAttribute1", SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<ClientMtTable1> results = child.select(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o1 = results.get(0);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(child, o1.getObjectContext());
List<ClientMtTable2> children1 = o1.getTable2Array();
assertEquals(2, children1.size());
Iterator<ClientMtTable2> it = children1.iterator();
while (it.hasNext()) {
ClientMtTable2 o = it.next();
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(child, o.getObjectContext());
assertEquals(o1, o.getTable1());
}
ClientMtTable1 o2 = results.get(1);
assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
assertSame(child, o2.getObjectContext());
List<?> children2 = o2.getTable2Array();
assertEquals(0, children2.size());
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class PersistentObjectInContextIT method testResolveToOneReverseResolved.
@Test
public void testResolveToOneReverseResolved() 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);
List<ClientMtTable2> list = mtTable1.getTable2Array();
assertNotNull(list);
assertTrue(list instanceof ValueHolder);
assertTrue(((ValueHolder) list).isFault());
// resolve it here...
assertEquals(2, list.size());
for (ClientMtTable2 t2 : list) {
PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
assertFalse(holder.isFault());
assertSame(mtTable1, holder.getValue());
}
assertEquals("g1", mtTable1.getGlobalAttribute1());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryPrefetchToOne.
@Test
public void testSelectQueryPrefetchToOne() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable2.class, ExpressionFactory.exp("globalAttribute = 'g1'"));
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
ClientMtTable2 result = (ClientMtTable2) results.get(0);
ValueHolder holder = result.getTable1Direct();
assertNotNull(holder);
assertTrue(holder instanceof PersistentObjectHolder);
PersistentObjectHolder objectHolder = (PersistentObjectHolder) holder;
assertFalse(objectHolder.isFault());
ClientMtTable1 target = (ClientMtTable1) objectHolder.getValue();
assertNotNull(target);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class ClientExpressionIT method testExpressionFactoryMatch.
@Test
public void testExpressionFactoryMatch() 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);
assertNotNull(table1List);
ClientMtTable1 element_1 = table1List.get(0);
ClientMtTable1 element_2 = table1List.get(1);
Expression exp = ExpressionFactory.matchExp(ClientMtTable2.TABLE1_PROPERTY, element_1);
SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
List<ClientMtTable2> table2List = context.select(table2Query);
assertNotNull(table2List);
assertEquals(2, table2List.size());
exp = ExpressionFactory.matchExp(element_2);
table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
table2List = context.select(table2Query);
assertNotNull(table2List);
assertEquals(2, table2List.size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 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());
}
Aggregations