Search in sources :

Example 81 with ClientMtTable1

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

the class NestedCayenneContextIT method testQueriesOnTemporaryObject.

/**
 * CAY1714
 */
@Test
public void testQueriesOnTemporaryObject() throws Exception {
    ObjectContext clientContext = runtime.newContext((DataChannel) this.clientContext);
    ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
    ObjectContext childContext = runtime.newContext((DataChannel) clientContext);
    ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(childContext, parentMt.getObjectId());
    childMt.setGlobalAttribute1("1183");
    ClientMtTable2 childMt2 = childContext.newObject(ClientMtTable2.class);
    childMt2.setGlobalAttribute("1183");
    childMt2.setTable1(childMt);
    childContext.commitChangesToParent();
    assertNull(childMt2.getTable3());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 82 with ClientMtTable1

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

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

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

the class ClientServerChannelIT method testGetEntityResolver.

@Test
public void testGetEntityResolver() throws Exception {
    EntityResolver resolver = clientServerChannel.getEntityResolver();
    assertNotNull(resolver);
    assertNull(resolver.getObjEntity(ClientMtTable1.class));
    assertNotNull(resolver.getClientEntityResolver().getObjEntity(ClientMtTable1.class));
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 85 with ClientMtTable1

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

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