use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryPrefetchToMany.
@Test
public void testSelectQueryPrefetchToMany() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class, ExpressionFactory.exp("globalAttribute1 = 'g1'"));
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
ClientMtTable1 result = (ClientMtTable1) results.get(0);
List<?> holder = result.getTable2ArrayDirect();
assertNotNull(holder);
assertTrue(holder instanceof PersistentObjectList);
PersistentObjectList objectHolder = (PersistentObjectList) holder;
assertFalse(objectHolder.isFault());
assertEquals(2, objectHolder.size());
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryToManyRelationshipQualifier.
@Test
public void testSelectQueryToManyRelationshipQualifier() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class, ExpressionFactory.exp("table2Array.globalAttribute = 'g1'"));
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
assertTrue(results.get(0) instanceof ClientMtTable1);
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryEntityNameRoot.
@Test
public void testSelectQueryEntityNameRoot() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery("MtTable1");
List<?> results = context.performQuery(q);
assertEquals(2, results.size());
assertTrue(results.get(0) instanceof ClientMtTable1);
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryOrdering.
@Test
public void testSelectQueryOrdering() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery("MtTable1");
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
List<?> results = context.performQuery(q);
assertEquals(2, results.size());
ClientMtTable1 o1 = (ClientMtTable1) results.get(0);
ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
assertTrue(o1.getGlobalAttribute1().compareTo(o2.getGlobalAttribute1()) < 0);
// now run the same query with reverse ordering to check that the first ordering
// result wasn't coincidental.
q.clearOrderings();
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.DESCENDING);
List<?> results1 = context.performQuery(q);
assertEquals(2, results1.size());
ClientMtTable1 o3 = (ClientMtTable1) results1.get(0);
ClientMtTable1 o4 = (ClientMtTable1) results1.get(1);
assertTrue(o3.getGlobalAttribute1().compareTo(o4.getGlobalAttribute1()) > 0);
}
use of org.apache.cayenne.query.SelectQuery 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);
}
Aggregations