Search in sources :

Example 96 with ObjectContext

use of org.apache.cayenne.ObjectContext 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 97 with ObjectContext

use of org.apache.cayenne.ObjectContext 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)

Example 98 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedTempOID.

@Test
public void testPeerObjectUpdatedTempOID() throws Exception {
    ObjectContext peer1 = runtime.newContext(clientContext);
    ClientMtTable1 a1 = peer1.newObject(ClientMtTable1.class);
    a1.setGlobalAttribute1("Y");
    ObjectId a1TempId = a1.getObjectId();
    ObjectContext peer2 = runtime.newContext(clientContext);
    ClientMtTable1 a2 = peer2.localObject(a1);
    assertEquals(a1TempId, a2.getObjectId());
    peer1.commitChanges();
    assertFalse(a1.getObjectId().isTemporary());
    assertFalse(a2.getObjectId().isTemporary());
    assertEquals(a2.getObjectId(), a1.getObjectId());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectId(org.apache.cayenne.ObjectId) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 99 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedToOneRelationship.

@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
    ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable1 altA = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable2 p = clientContext.newObject(ClientMtTable2.class);
    p.setTable1(a);
    p.setGlobalAttribute("PPP");
    a.setGlobalAttribute1("X");
    altA.setGlobalAttribute1("Y");
    clientContext.commitChanges();
    ObjectContext peer1 = runtime.newContext(clientContext);
    ClientMtTable2 p1 = peer1.localObject(p);
    ClientMtTable1 altA1 = peer1.localObject(altA);
    ObjectContext peer2 = runtime.newContext(clientContext);
    ClientMtTable2 p2 = peer2.localObject(p);
    ClientMtTable1 altA2 = peer2.localObject(altA);
    ClientMtTable1 a2 = peer2.localObject(a);
    p1.setTable1(altA1);
    assertSame(a2, p2.getTable1());
    peer1.commitChangesToParent();
    assertEquals(altA2, p2.getTable1());
    assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 100 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class NestedObjectContextRollbackIT method testRollbackChangesLocally.

@Test
public void testRollbackChangesLocally() {
    ObjectContext child1 = runtime.newContext(clientContext);
    assertFalse(clientContext.hasChanges());
    assertFalse(child1.hasChanges());
    clientContext.newObject(ClientMtTable1.class);
    child1.newObject(ClientMtTable1.class);
    assertTrue(clientContext.hasChanges());
    assertTrue(child1.hasChanges());
    child1.rollbackChangesLocally();
    assertTrue(clientContext.hasChanges());
    assertFalse(child1.hasChanges());
    clientContext.rollbackChanges();
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)127 Test (org.junit.Test)116 Artist (org.apache.cayenne.testdo.testmap.Artist)35 Painting (org.apache.cayenne.testdo.testmap.Painting)14 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 Table1 (org.apache.cayenne.crypto.db.Table1)10 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)10 ObjectId (org.apache.cayenne.ObjectId)8 GraphDiff (org.apache.cayenne.graph.GraphDiff)8 Table2 (org.apache.cayenne.crypto.db.Table2)7 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)7 HashMap (java.util.HashMap)6 Persistent (org.apache.cayenne.Persistent)6 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)6 IvImpl (org.apache.cayenne.testdo.inheritance_vertical.IvImpl)5 CayenneContext (org.apache.cayenne.CayenneContext)4 DataChannel (org.apache.cayenne.DataChannel)4 QueryResponse (org.apache.cayenne.QueryResponse)4 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)4 EntityResolver (org.apache.cayenne.map.EntityResolver)4