Search in sources :

Example 16 with SelectQuery

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) PersistentObjectList(org.apache.cayenne.util.PersistentObjectList) Test(org.junit.Test)

Example 17 with SelectQuery

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);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 18 with SelectQuery

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);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 19 with SelectQuery

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);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 20 with SelectQuery

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);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) PersistentObjectHolder(org.apache.cayenne.util.PersistentObjectHolder) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ValueHolder(org.apache.cayenne.ValueHolder) Test(org.junit.Test)

Aggregations

SelectQuery (org.apache.cayenne.query.SelectQuery)360 Test (org.junit.Test)348 Artist (org.apache.cayenne.testdo.testmap.Artist)128 Painting (org.apache.cayenne.testdo.testmap.Painting)75 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)64 Expression (org.apache.cayenne.exp.Expression)47 List (java.util.List)43 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)26 ValueHolder (org.apache.cayenne.ValueHolder)21 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)13 DataRow (org.apache.cayenne.DataRow)12 ObjectContext (org.apache.cayenne.ObjectContext)12 DbEntity (org.apache.cayenne.map.DbEntity)12 SQLTemplate (org.apache.cayenne.query.SQLTemplate)11 ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)11 HashMap (java.util.HashMap)10 ObjectId (org.apache.cayenne.ObjectId)10 Query (org.apache.cayenne.query.Query)10