Search in sources :

Example 96 with ClientMtTable1

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

the class CayenneContextDeletionIT method testDeletion.

@Test
public void testDeletion() {
    ClientMtTable1 object = clientContext.newObject(ClientMtTable1.class);
    clientContext.commitChanges();
    clientContext.deleteObjects(object);
    // now check that the object is unregistered
    clientContext.commitChanges();
    assertNull(clientContext.getGraphManager().getNode(object.getObjectId()));
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 97 with ClientMtTable1

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

the class ClientChannelServerDiffsIT method testReturnDiffClientArcChanges.

@Test
public void testReturnDiffClientArcChanges() {
    final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler();
    ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false) {

        @Override
        public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
            GraphDiff serverDiff = super.onSync(originatingContext, changes, syncType);
            assertNotNull(serverDiff);
            serverDiff.apply(diffReader);
            return serverDiff;
        }
    };
    CayenneContext context = new CayenneContext(channel);
    ClientMtTable1 o = context.newObject(ClientMtTable1.class);
    ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
    o.addToTable2Array(o2);
    context.commitChanges();
    assertEquals(2, diffReader.size);
    diffReader.reset();
    ClientMtTable2 o3 = context.newObject(ClientMtTable2.class);
    o3.setTable1(o);
    context.commitChanges();
    assertEquals(1, diffReader.size);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectContext(org.apache.cayenne.ObjectContext) CayenneContext(org.apache.cayenne.CayenneContext) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Example 98 with ClientMtTable1

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

the class NestedObjectContextLocalIT method testLocalCacheStaysLocal.

@Test
public void testLocalCacheStaysLocal() {
    SelectQuery<ClientMtTable1> query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
    query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    BaseContext child1 = (BaseContext) runtime.newContext(clientContext);
    assertNull(child1.getQueryCache().get(query.getMetaData(child1.getEntityResolver())));
    assertNull(clientContext.getQueryCache().get(query.getMetaData(clientContext.getEntityResolver())));
    List<?> results = child1.performQuery(query);
    assertSame(results, child1.getQueryCache().get(query.getMetaData(child1.getEntityResolver())));
    assertNull(clientContext.getQueryCache().get(query.getMetaData(clientContext.getEntityResolver())));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) BaseContext(org.apache.cayenne.BaseContext) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 99 with ClientMtTable1

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

the class NestedObjectContextParentEventsIT method testParentUpdatedId.

@Test
public void testParentUpdatedId() throws Exception {
    ObjectContext child = runtime.newContext(clientContext);
    ClientMtTable1 ac = child.newObject(ClientMtTable1.class);
    ac.setGlobalAttribute1("X");
    child.commitChangesToParent();
    ClientMtTable1 ap = (ClientMtTable1) clientContext.getGraphManager().getNode(ac.getObjectId());
    assertNotNull(ap);
    assertTrue(ap.getObjectId().isTemporary());
    clientContext.commitChanges();
    assertFalse(ap.getObjectId().isTemporary());
    assertEquals(ap.getObjectId(), ac.getObjectId());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 100 with ClientMtTable1

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

the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedSimpleProperty.

@Test
public void testPeerObjectUpdatedSimpleProperty() throws Exception {
    ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
    a.setGlobalAttribute1("X");
    clientContext.commitChanges();
    ObjectContext peer1 = runtime.newContext(clientContext);
    ClientMtTable1 a1 = peer1.localObject(a);
    ObjectContext peer2 = runtime.newContext(clientContext);
    ClientMtTable1 a2 = peer2.localObject(a);
    a1.setGlobalAttribute1("Y");
    assertEquals("X", a2.getGlobalAttribute1());
    peer1.commitChangesToParent();
    assertEquals("Y", a2.getGlobalAttribute1());
    assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectContext(org.apache.cayenne.ObjectContext) 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