Search in sources :

Example 11 with ClientMtTable1

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

the class CayenneContextMergeHandlerIT method testNodePropertyChanged.

@Test
public void testNodePropertyChanged() {
    ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
    CayenneContextMergeHandler handler = new CayenneContextMergeHandler(context);
    assertNull(o1.getGlobalAttribute1Direct());
    handler.nodePropertyChanged(o1.getObjectId(), ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, null, "abc");
    assertEquals("abc", o1.getGlobalAttribute1Direct());
    handler.nodePropertyChanged(o1.getObjectId(), ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, "abc", "xyz");
    assertEquals("xyz", o1.getGlobalAttribute1Direct());
    // block if old value is different
    handler.nodePropertyChanged(o1.getObjectId(), ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, "123", "mnk");
    assertEquals("xyz", o1.getGlobalAttribute1Direct());
    handler.nodePropertyChanged(o1.getObjectId(), ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, "xyz", null);
    assertNull(o1.getGlobalAttribute1Direct());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 12 with ClientMtTable1

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

the class CayenneContextPaginatedListCachingIT method testLocalCache.

@Test
public void testLocalCache() throws Exception {
    createSevenMtTable1sDataSet();
    SelectQuery query = new SelectQuery(ClientMtTable1.class);
    query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    query.setPageSize(3);
    query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    List<ClientMtTable1> result1 = context.performQuery(query);
    assertEquals(7, result1.size());
    // ensure we can resolve all objects without a failure...
    for (ClientMtTable1 x : result1) {
        x.getGlobalAttribute1();
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 13 with ClientMtTable1

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

the class CayenneContextRelationshipsIT method testLostUncommittedToOneModifications_Client.

@Test
public void testLostUncommittedToOneModifications_Client() throws Exception {
    tMtTable1.insert(1, "G1", "S1");
    tMtTable1.insert(2, "G2", "S2");
    tMtTable2.insert(33, 1, "GX");
    ClientMtTable2 o = Cayenne.objectForPK(context, ClientMtTable2.class, 33);
    ClientMtTable1 r2 = Cayenne.objectForPK(context, ClientMtTable1.class, 2);
    ClientMtTable1 r1 = o.getTable1();
    o.setTable1(r2);
    assertSame(r2, o.getTable1());
    // see CAY-1757 - this used to reset our changes
    assertFalse(r1.getTable2Array().contains(o));
    assertSame(r2, o.getTable1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 14 with ClientMtTable1

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

the class CayenneContextServerDiffsIT method testReturnDiffInPrePersist.

@Test
public void testReturnDiffInPrePersist() {
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
        ClientMtTable1 o = context.newObject(ClientMtTable1.class);
        o.setServerAttribute1("YY");
        context.commitChanges();
        assertFalse(o.getObjectId().isTemporary());
        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
        assertEquals("XXX", o.getGlobalAttribute1());
    } finally {
        callbackRegistry.clear();
    }
}
Also used : ClientChannelServerDiffsListener1(org.apache.cayenne.remote.ClientChannelServerDiffsListener1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) Test(org.junit.Test)

Example 15 with ClientMtTable1

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

the class CayenneContextServerDiffsIT method testReturnDiffServerArcChanges.

@Test
public void testReturnDiffServerArcChanges() {
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersistAddRelationship");
        ClientMtTable1 o = context.newObject(ClientMtTable1.class);
        ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
        o.addToTable2Array(o1);
        context.commitChanges();
        assertFalse(o.getObjectId().isTemporary());
        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
        assertEquals(2, o.getTable2Array().size());
    } finally {
        callbackRegistry.clear();
    }
}
Also used : ClientChannelServerDiffsListener1(org.apache.cayenne.remote.ClientChannelServerDiffsListener1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) 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