Search in sources :

Example 76 with ClientMtTable1

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

the class NestedCayenneContextIT method testCAY1183.

@Test
public void testCAY1183() throws Exception {
    ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
    clientContext.commitChanges();
    ObjectContext child = runtime.newContext(clientContext);
    ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(child, parentMt.getObjectId());
    childMt.setGlobalAttribute1("1183");
    ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
    childMt2.setGlobalAttribute("1183");
    childMt2.setTable1(childMt);
    child.commitChangesToParent();
    // fetching other relationship... this fails per CAY-1183
    childMt2.getTable3();
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 77 with ClientMtTable1

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

the class NestedCayenneContextIT method testCAY1194.

@Test
public void testCAY1194() throws Exception {
    ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
    ObjectContext child = runtime.newContext(clientContext);
    ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
    childMt2.setGlobalAttribute("222");
    ClientMtTable1 localParentMt = child.localObject(parentMt);
    assertEquals(0, parentMt.getTable2Array().size());
    assertEquals(0, localParentMt.getTable2Array().size());
    childMt2.setTable1(localParentMt);
    assertEquals(0, parentMt.getTable2Array().size());
    assertEquals(1, localParentMt.getTable2Array().size());
    assertEquals(localParentMt.getTable2Array().get(0).getObjectContext(), child);
    child.commitChangesToParent();
    assertEquals(1, parentMt.getTable2Array().size());
    assertEquals(parentMt.getTable2Array().get(0).getObjectContext(), clientContext);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 78 with ClientMtTable1

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

the class NestedCayenneContextIT method testSelect.

@Test
public void testSelect() throws Exception {
    ObjectContext child = runtime.newContext(clientContext);
    ClientMtTable1 committed = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable1 deleted = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable1 modified = clientContext.newObject(ClientMtTable1.class);
    clientContext.commitChanges();
    int modifiedid = Cayenne.intPKForObject(modified);
    // test how different object states appear in the child on select
    clientContext.deleteObjects(deleted);
    modified.setGlobalAttribute1("a");
    ClientMtTable1 _new = clientContext.newObject(ClientMtTable1.class);
    assertEquals(PersistenceState.COMMITTED, committed.getPersistenceState());
    assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
    assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
    assertEquals(PersistenceState.NEW, _new.getPersistenceState());
    List<ClientMtTable1> objects = child.select(new SelectQuery<ClientMtTable1>(ClientMtTable1.class));
    assertEquals("All but NEW object must have been included", 3, objects.size());
    for (ClientMtTable1 next : objects) {
        assertEquals(PersistenceState.COMMITTED, next.getPersistenceState());
        int id = Cayenne.intPKForObject(next);
        if (id == modifiedid) {
            assertEquals("a", next.getGlobalAttribute1());
        }
    }
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 79 with ClientMtTable1

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

the class NestedCayenneContextIT method testCommitChanges.

@Test
public void testCommitChanges() throws Exception {
    clientContext.newObject(ClientMtTable1.class);
    clientContext.newObject(ClientMtTable1.class);
    clientContext.newObject(ClientMtTable1.class);
    clientContext.newObject(ClientMtTable1.class);
    clientContext.commitChanges();
    ObjectContext child = runtime.newContext(clientContext);
    // make sure we fetch in predictable order
    SelectQuery<ClientMtTable1> query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
    List<ClientMtTable1> objects = child.select(query);
    assertEquals(4, objects.size());
    ClientMtTable1 childNew = child.newObject(ClientMtTable1.class);
    childNew.setGlobalAttribute1("NNN");
    ClientMtTable1 childModified = objects.get(0);
    childModified.setGlobalAttribute1("MMM");
    ClientMtTable1 childCommitted = objects.get(1);
    // delete AND modify
    ClientMtTable1 childDeleted = objects.get(2);
    child.deleteObjects(childDeleted);
    childDeleted.setGlobalAttribute1("DDD");
    ClientMtTable1 childHollow = objects.get(3);
    child.invalidateObjects(childHollow);
    child.commitChanges();
    assertEquals(PersistenceState.COMMITTED, childNew.getPersistenceState());
    assertEquals(PersistenceState.COMMITTED, childModified.getPersistenceState());
    assertEquals(PersistenceState.COMMITTED, childCommitted.getPersistenceState());
    assertEquals(PersistenceState.TRANSIENT, childDeleted.getPersistenceState());
    assertEquals(PersistenceState.HOLLOW, childHollow.getPersistenceState());
    ClientMtTable1 parentNew = (ClientMtTable1) clientContext.getGraphManager().getNode(childNew.getObjectId());
    ClientMtTable1 parentModified = (ClientMtTable1) clientContext.getGraphManager().getNode(childModified.getObjectId());
    ClientMtTable1 parentCommitted = (ClientMtTable1) clientContext.getGraphManager().getNode(childCommitted.getObjectId());
    ClientMtTable1 parentDeleted = (ClientMtTable1) clientContext.getGraphManager().getNode(childDeleted.getObjectId());
    ClientMtTable1 parentHollow = (ClientMtTable1) clientContext.getGraphManager().getNode(childHollow.getObjectId());
    assertNotNull(parentNew);
    assertEquals(PersistenceState.COMMITTED, parentNew.getPersistenceState());
    assertEquals("NNN", parentNew.getGlobalAttribute1());
    assertNotNull(parentModified);
    assertEquals(PersistenceState.COMMITTED, parentModified.getPersistenceState());
    assertEquals("MMM", parentModified.getGlobalAttribute1());
    assertNull("Deleted object should not be registered.", parentDeleted);
    assertNotNull(parentCommitted);
    assertEquals(PersistenceState.COMMITTED, parentCommitted.getPersistenceState());
    assertNotNull(parentHollow);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 80 with ClientMtTable1

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

the class NestedCayenneContextIT method testCommitChangesToParentDeleted.

@Test
public void testCommitChangesToParentDeleted() throws Exception {
    clientContext.newObject(ClientMtTable1.class);
    clientContext.newObject(ClientMtTable1.class);
    clientContext.newObject(ClientMtTable1.class);
    clientContext.newObject(ClientMtTable1.class);
    clientContext.commitChanges();
    ObjectContext child = runtime.newContext(clientContext);
    // make sure we fetch in predictable order
    SelectQuery<ClientMtTable1> query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
    List<ClientMtTable1> objects = child.select(query);
    assertEquals(4, objects.size());
    // delete AND modify
    ClientMtTable1 childDeleted = objects.get(2);
    child.deleteObjects(childDeleted);
    childDeleted.setGlobalAttribute1("DDD");
    // don't block queries - on delete Cayenne may need to resolve delete
    // rules via fetch
    child.commitChangesToParent();
    // * all modified child objects must be in committed state now
    // * all modifications should be propagated to the parent
    // * no actual commit should occur.
    assertEquals(PersistenceState.TRANSIENT, childDeleted.getPersistenceState());
    ClientMtTable1 parentDeleted = (ClientMtTable1) clientContext.getGraphManager().getNode(childDeleted.getObjectId());
    assertNotNull(parentDeleted);
    assertEquals(PersistenceState.DELETED, parentDeleted.getPersistenceState());
    assertEquals("DDD", parentDeleted.getGlobalAttribute1());
}
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