Search in sources :

Example 71 with ClientMtTable1

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

the class CayenneContextWithDataContextIT method testRollbackChanges.

@Test
public void testRollbackChanges() throws Exception {
    ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
    o.setGlobalAttribute1("1");
    clientContext.commitChanges();
    assertEquals("1", o.getGlobalAttribute1());
    o.setGlobalAttribute1("2");
    assertEquals("2", o.getGlobalAttribute1());
    clientContext.rollbackChanges();
    assertEquals("1", o.getGlobalAttribute1());
    assertTrue(clientContext.modifiedObjects().isEmpty());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 72 with ClientMtTable1

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

the class CayenneContextWithDataContextIT method testPerformPaginatedQuery.

@Test
public void testPerformPaginatedQuery() throws Exception {
    createEightMtTable1s();
    SelectQuery query = new SelectQuery(ClientMtTable1.class);
    query.setPageSize(5);
    List<ClientMtTable1> objects = clientContext.performQuery(query);
    assertNotNull(objects);
    assertTrue(objects instanceof RemoteIncrementalFaultList);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) RemoteIncrementalFaultList(org.apache.cayenne.remote.RemoteIncrementalFaultList) Test(org.junit.Test)

Example 73 with ClientMtTable1

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

the class CayenneContextWithDataContextIT method testOIDQueryInterception.

@Test
public void testOIDQueryInterception() throws Exception {
    final ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
    o.setGlobalAttribute1("aaa");
    // fetch new
    final ObjectIdQuery q1 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> objects = clientContext.performQuery(q1);
            assertEquals(1, objects.size());
            assertSame(o, objects.get(0));
        }
    });
    clientContext.commitChanges();
    // fetch committed
    final ObjectIdQuery q2 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> objects = clientContext.performQuery(q2);
            assertEquals(1, objects.size());
            assertSame(o, objects.get(0));
        }
    });
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) RemoteIncrementalFaultList(org.apache.cayenne.remote.RemoteIncrementalFaultList) List(java.util.List) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 74 with ClientMtTable1

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

the class NestedCayenneContextIT method testChangeRel.

@Test
public void testChangeRel() throws Exception {
    ObjectContext child = runtime.newContext(clientContext);
    ClientMtTable1 a = child.newObject(ClientMtTable1.class);
    ClientMtTable2 b = child.newObject(ClientMtTable2.class);
    child.commitChanges();
    assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
    a.addToTable2Array(b);
    assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());
    child.commitChangesToParent();
    ClientMtTable1 parentA = (ClientMtTable1) clientContext.getGraphManager().getNode(a.getObjectId());
    assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
    assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
    assertEquals(1, parentA.getTable2Array().size());
    clientContext.commitChanges();
    assertEquals(PersistenceState.COMMITTED, parentA.getPersistenceState());
    a.removeFromTable2Array(b);
    assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());
    child.commitChangesToParent();
    assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
    assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
    assertEquals(0, parentA.getTable2Array().size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 75 with ClientMtTable1

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

the class NestedCayenneContextIT method testCommitChangesToParentOneToMany.

@Test
public void testCommitChangesToParentOneToMany() throws Exception {
    ObjectContext child = runtime.newContext(clientContext);
    ClientMtTable1 master = child.newObject(ClientMtTable1.class);
    ClientMtTable2 dep = child.newObject(ClientMtTable2.class);
    master.addToTable2Array(dep);
    child.commitChangesToParent();
    ClientMtTable1 masterParent = (ClientMtTable1) clientContext.getGraphManager().getNode(master.getObjectId());
    ClientMtTable2 depParent = (ClientMtTable2) clientContext.getGraphManager().getNode(dep.getObjectId());
    assertNotNull(masterParent);
    assertNotNull(depParent);
    assertSame(masterParent, depParent.getTable1());
    assertTrue(masterParent.getTable2Array().contains(depParent));
    // check that arc changes got recorded in the parent context
    GraphDiff diffs = clientContext.internalGraphManager().getDiffs();
    final int[] arcDiffs = new int[1];
    final int[] newNodes = new int[1];
    diffs.apply(new GraphChangeHandler() {

        public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
            arcDiffs[0]++;
        }

        public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
            arcDiffs[0]--;
        }

        public void nodeCreated(Object nodeId) {
            newNodes[0]++;
        }

        public void nodeIdChanged(Object nodeId, Object newId) {
        }

        public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
        }

        public void nodeRemoved(Object nodeId) {
            newNodes[0]--;
        }
    });
    assertEquals(2, newNodes[0]);
    assertEquals(2, arcDiffs[0]);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) GraphDiff(org.apache.cayenne.graph.GraphDiff) GraphChangeHandler(org.apache.cayenne.graph.GraphChangeHandler) 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