Search in sources :

Example 31 with ClientMtTable1

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

the class ClientServerChannelIT method testPerformQueryObjectIDInjection.

@Test
public void testPerformQueryObjectIDInjection() throws Exception {
    tMtTable1.insert(55, "g1", "s1");
    Query query = new SelectQuery("MtTable1");
    QueryResponse response = clientServerChannel.onQuery(null, query);
    assertNotNull(response);
    List<?> results = response.firstList();
    assertNotNull(results);
    assertEquals(1, results.size());
    Object result = results.get(0);
    assertTrue(result instanceof ClientMtTable1);
    ClientMtTable1 clientObject = (ClientMtTable1) result;
    assertNotNull(clientObject.getObjectId());
    assertEquals(new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 55), clientObject.getObjectId());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) SelectQuery(org.apache.cayenne.query.SelectQuery) MockQuery(org.apache.cayenne.query.MockQuery) Query(org.apache.cayenne.query.Query) ObjectId(org.apache.cayenne.ObjectId) QueryResponse(org.apache.cayenne.QueryResponse) Test(org.junit.Test)

Example 32 with ClientMtTable1

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

the class ClientServerChannelIT method testOnQueryPrefetchingToManyEmpty.

@Test
public void testOnQueryPrefetchingToManyEmpty() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class);
    q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
    final List<?> results = clientServerChannel.onQuery(null, q).firstList();
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
            assertNull(o2.getObjectContext());
            List<?> children2 = o2.getTable2Array();
            assertNotNull(children2);
            assertFalse(((ValueHolder) children2).isFault());
            assertEquals(0, children2.size());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Test(org.junit.Test)

Example 33 with ClientMtTable1

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

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

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

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