Search in sources :

Example 36 with ClientMtTable2

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

the class PersistentObjectInContextIT method testToOneRelationship.

@Test
public void testToOneRelationship() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    ObjectId gid = new ObjectId("MtTable2", MtTable2.TABLE2_ID_PK_COLUMN, new Integer(1));
    ClientMtTable2 mtTable21 = (ClientMtTable2) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
    assertNotNull(mtTable21);
    ClientMtTable1 mtTable1 = mtTable21.getTable1();
    assertNotNull("To one relationship incorrectly resolved to null", mtTable1);
    assertEquals("g1", mtTable1.getGlobalAttribute1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 37 with ClientMtTable2

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

the class PersistentObjectInContextIT method testResolveToManyReverseResolved.

@Test
public void testResolveToManyReverseResolved() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    ObjectId gid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, new Integer(1));
    ClientMtTable1 t1 = (ClientMtTable1) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
    assertNotNull(t1);
    List<ClientMtTable2> t2s = t1.getTable2Array();
    assertEquals(2, t2s.size());
    for (ClientMtTable2 t2 : t2s) {
        PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
        assertFalse(holder.isFault());
        assertSame(t1, holder.getValue());
    }
}
Also used : PersistentObjectHolder(org.apache.cayenne.util.PersistentObjectHolder) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 38 with ClientMtTable2

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

the class ClientServerChannelIT method testOnQueryPrefetchingToMany.

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

        public void execute() {
            ClientMtTable1 o1 = (ClientMtTable1) results.get(0);
            assertNull(o1.getObjectContext());
            List<ClientMtTable2> children1 = o1.getTable2Array();
            assertEquals(2, children1.size());
            for (ClientMtTable2 o : children1) {
                assertNull(o.getObjectContext());
            }
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) Test(org.junit.Test)

Example 39 with ClientMtTable2

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

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

Aggregations

ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)48 Test (org.junit.Test)48 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)46 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)9 Expression (org.apache.cayenne.exp.Expression)7 SelectQuery (org.apache.cayenne.query.SelectQuery)7 ObjectContext (org.apache.cayenne.ObjectContext)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 Iterator (java.util.Iterator)3 List (java.util.List)3 GraphDiff (org.apache.cayenne.graph.GraphDiff)3 PersistentObjectHolder (org.apache.cayenne.util.PersistentObjectHolder)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)2 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)2 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)2 ROPSerializationService (org.apache.cayenne.rop.ROPSerializationService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CayenneContext (org.apache.cayenne.CayenneContext)1 ValueHolder (org.apache.cayenne.ValueHolder)1