Search in sources :

Example 6 with ClientMtTable1

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

the class CayenneContextClientChannelEventsIT method testSyncSimpleProperty.

@Test
public void testSyncSimpleProperty() throws Exception {
    tMtTable1.insert(1, "g1", "s1");
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    assertNotSame(c1, c2);
    ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    ClientMtTable1 o2 = (ClientMtTable1) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    assertEquals("g1", o1.getGlobalAttribute1());
    assertEquals("g1", o2.getGlobalAttribute1());
    o1.setGlobalAttribute1("X");
    c1.commitChanges();
    // let the events propagate to peers
    Thread.sleep(500);
    assertEquals("X", o2.getGlobalAttribute1());
    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)

Example 7 with ClientMtTable1

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

the class CayenneContextClientChannelEventsIT method testSyncNewObjectIntoDirtyContext.

@Test
public void testSyncNewObjectIntoDirtyContext() throws Exception {
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    assertNotSame(c1, c2);
    // make sure c2 has uncommitted changes
    c2.newObject(ClientMtTable1.class);
    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());
    assertTrue(c2.internalGraphManager().hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 8 with ClientMtTable1

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

the class CayenneContextEJBQLIT method testEJBQLSelectMixed.

@Test
public void testEJBQLSelectMixed() throws Exception {
    createTwoRecords();
    EJBQLQuery query = new EJBQLQuery("SELECT COUNT(a), a, a.serverAttribute1 FROM MtTable1 a Group By a ORDER BY a.serverAttribute1");
    List<Object[]> results = context.performQuery(query);
    assertEquals(2, results.size());
    assertEquals(Long.valueOf(1), results.get(0)[0]);
    assertTrue(results.get(0)[1] instanceof ClientMtTable1);
    assertEquals("s1", results.get(0)[2]);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 9 with ClientMtTable1

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

the class CayenneContextGraphDiffCompressorIT method testMultipleSimpleProperties.

@Test
public void testMultipleSimpleProperties() {
    ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1("v1");
    o1.setGlobalAttribute1("v2");
    DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {

        public void execute() {
            context.commitChanges();
        }
    });
    assertEquals(1, stats.nodePropertiesChanged);
    assertEquals(1, stats.nodesCreated);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) DataChannelSyncStats(org.apache.cayenne.unit.di.DataChannelSyncStats) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 10 with ClientMtTable1

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

the class CayenneContextGraphDiffCompressorIT method testComplimentaryArcs.

@Test
public void testComplimentaryArcs() {
    ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
    ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
    o2.setTable1(o1);
    o2.setTable1(null);
    DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {

        public void execute() {
            context.commitChanges();
        }
    });
    assertEquals(0, stats.nodePropertiesChanged);
    assertEquals(2, stats.nodesCreated);
    assertEquals(0, stats.arcsCreated);
    assertEquals(0, stats.arcsDeleted);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) DataChannelSyncStats(org.apache.cayenne.unit.di.DataChannelSyncStats) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) 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