Search in sources :

Example 86 with ClientMtTable1

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

the class ClientServerChannelQueryIT method testPaginatedQueryServerCacheOverflow.

@SuppressWarnings("deprecation")
@Test
public void testPaginatedQueryServerCacheOverflow() throws Exception {
    createSevenMtTable1sDataSet();
    SelectQuery query = new SelectQuery(ClientMtTable1.class);
    query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    query.setPageSize(3);
    List<?> results = context.performQuery(query);
    // read page 1
    assertTrue(results.get(0) instanceof ClientMtTable1);
    assertTrue(results.get(3) instanceof ClientMtTable1);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 87 with ClientMtTable1

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

the class ClientServerChannelQueryIT method testSelectQueryClientClassRoot.

@Test
public void testSelectQueryClientClassRoot() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class);
    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 88 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 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());
}
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 89 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 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());
}
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 90 with ClientMtTable1

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

the class ClientExpressionIT method testListInASTList.

@Test
public void testListInASTList() throws Exception {
    ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
    ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
    context.commitChanges();
    List<ClientMtTable1> table1List = new ArrayList<ClientMtTable1>();
    table1List.add(t1);
    table1List.add(t2);
    // send list in expression factory
    Expression list = ExpressionFactory.inExp(ClientMtTable2.TABLE1_PROPERTY, table1List);
    Object[] values = (Object[]) ((ASTList) list.getOperand(1)).getOperand(0);
    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 copies of object
    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) ArrayList(java.util.ArrayList) 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