Search in sources :

Example 1 with ClientMtTable1

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

the class CayenneContextCayenneIT method testObjectForPK.

@Test
public void testObjectForPK() throws Exception {
    context.performGenericQuery(new SQLTemplate(ClientMtTable1.class, "insert into MT_TABLE1 " + "(TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) " + "values (1, 'g1', 's1')"));
    ClientMtTable1 o = Cayenne.objectForPK(context, ClientMtTable1.class, 1);
    assertNotNull(o);
    assertEquals("g1", o.getGlobalAttribute1());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 2 with ClientMtTable1

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

the class CayenneContextClientChannelEventsIT method testSyncToManyRelationship1.

@Test
public void testSyncToManyRelationship1() throws Exception {
    tMtTable1.insert(1, "g1", "s1");
    tMtTable2.insert(1, 1, "g1");
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    // do not resolve objects in question in the second context and see if the merge
    // causes any issues...
    assertEquals(1, o1.getTable2Array().size());
    ClientMtTable2 o1r = c1.newObject(ClientMtTable2.class);
    o1r.setGlobalAttribute("X");
    o1.addToTable2Array(o1r);
    c1.commitChanges();
    assertEquals(2, o1.getTable2Array().size());
    assertFalse(c1.internalGraphManager().hasChanges());
    assertFalse(c2.internalGraphManager().hasChanges());
    ClientMtTable1 o2 = (ClientMtTable1) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    assertEquals(2, o2.getTable2Array().size());
}
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 3 with ClientMtTable1

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

the class CayenneContextClientChannelEventsIT method testSyncNewDeletedObject.

@Test
public void testSyncNewDeletedObject() throws Exception {
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    assertNotSame(c1, c2);
    // insert, then delete - this shouldn't propagate via an event.
    ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1("X");
    c1.deleteObjects(o1);
    // introduce some other change so that commit can go ahead...
    ClientMtTable1 o1x = c1.newObject(ClientMtTable1.class);
    o1x.setGlobalAttribute1("Y");
    c1.commitChanges();
    ClientMtTable1 o2 = (ClientMtTable1) c2.getGraphManager().getNode(o1.getObjectId());
    assertNull(o2);
    assertFalse(c1.internalGraphManager().hasChanges());
    assertFalse(c2.internalGraphManager().hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 4 with ClientMtTable1

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

the class CayenneContextClientChannelEventsIT method testSyncToOneRelationship.

@Test
public void testSyncToOneRelationship() throws Exception {
    tMtTable1.insert(1, "g1", "s1");
    tMtTable1.insert(2, "g2", "s2");
    tMtTable2.insert(1, 1, "g1");
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    ClientMtTable2 o1 = (ClientMtTable2) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable2", "TABLE2_ID", 1)));
    ClientMtTable2 o2 = (ClientMtTable2) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable2", "TABLE2_ID", 1)));
    assertEquals("g1", o1.getTable1().getGlobalAttribute1());
    assertEquals("g1", o2.getTable1().getGlobalAttribute1());
    ClientMtTable1 o1r = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 2)));
    o1.setTable1(o1r);
    c1.commitChanges();
    // let the events propagate to peers
    Thread.sleep(500);
    assertEquals("g2", o2.getTable1().getGlobalAttribute1());
    assertEquals(o1r.getObjectId(), o2.getTable1().getObjectId());
    assertFalse(c1.internalGraphManager().hasChanges());
    assertFalse(c2.internalGraphManager().hasChanges());
}
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 5 with ClientMtTable1

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

the class CayenneContextClientChannelEventsIT method testSyncNewObject.

@Test
public void testSyncNewObject() throws Exception {
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    assertNotSame(c1, c2);
    ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1("X");
    c1.commitChanges();
    ClientMtTable1 o2 = (ClientMtTable1) c2.getGraphManager().getNode(o1.getObjectId());
    assertNull(o2);
    // now fetch it fresh
    o2 = (ClientMtTable1) c2.performQuery(new ObjectIdQuery(o1.getObjectId())).get(0);
    assertNotNull(o2);
    assertEquals("X", o2.getGlobalAttribute1());
    assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
    assertFalse(c1.internalGraphManager().hasChanges());
    assertFalse(c2.internalGraphManager().hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) 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