Search in sources :

Example 36 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 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 37 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 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)

Example 38 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class ClientServerChannelQueryIT method testSelectQuerySimpleQualifier.

@Test
public void testSelectQuerySimpleQualifier() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class, ExpressionFactory.exp("globalAttribute1 = '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 39 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 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());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 40 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class ClientExpressionIT method testArrayInASTList.

@Test
public void testArrayInASTList() throws Exception {
    ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
    ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
    ClientMtTable1 t3 = context.newObject(ClientMtTable1.class);
    context.commitChanges();
    Object[] tArray = new Object[3];
    tArray[0] = t1;
    tArray[1] = t2;
    // send array in expression factory
    Expression list = ExpressionFactory.inExp(ClientMtTable2.TABLE1_PROPERTY, tArray);
    tArray[2] = t3;
    Object[] values = (Object[]) ((ASTList) list.getOperand(1)).getOperand(0);
    assertEquals(tArray.length, values.length);
    assertNotSame(tArray[2], values[2]);
    assertEquals(t1.getObjectId(), values[0]);
    assertEquals(t2.getObjectId(), values[1]);
    ObjectId t1Id = new ObjectId("MtTable1", "TABLE1_ID", 1);
    ObjectId t2Id = new ObjectId("MtTable1", "TABLE1_ID", 2);
    t1.setObjectId(t1Id);
    t2.setObjectId(t2Id);
    // Expression and client have different arrays
    assertNotSame(t1.getObjectId(), values[0]);
    assertNotSame(t2.getObjectId(), values[1]);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Expression(org.apache.cayenne.exp.Expression) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Aggregations

ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)112 Test (org.junit.Test)112 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)46 SelectQuery (org.apache.cayenne.query.SelectQuery)26 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)19 ObjectContext (org.apache.cayenne.ObjectContext)12 Expression (org.apache.cayenne.exp.Expression)12 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)11 List (java.util.List)8 ObjectId (org.apache.cayenne.ObjectId)7 EntityResolver (org.apache.cayenne.map.EntityResolver)7 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)7 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)6 GraphDiff (org.apache.cayenne.graph.GraphDiff)5 MockEventManager (org.apache.cayenne.event.MockEventManager)4 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)3 MtTable1 (org.apache.cayenne.testdo.mt.MtTable1)3