Search in sources :

Example 1 with ClientChannelServerDiffsListener1

use of org.apache.cayenne.remote.ClientChannelServerDiffsListener1 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 2 with ClientChannelServerDiffsListener1

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

Example 3 with ClientChannelServerDiffsListener1

use of org.apache.cayenne.remote.ClientChannelServerDiffsListener1 in project cayenne by apache.

the class CayenneContextServerDiffsIT method testReturnDiffInPreUpdate.

@Test
public void testReturnDiffInPreUpdate() {
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.PRE_UPDATE, MtTable1.class, new ClientChannelServerDiffsListener1(), "preUpdate");
        ClientMtTable1 o = context.newObject(ClientMtTable1.class);
        o.setServerAttribute1("YY");
        context.commitChanges();
        assertNull(o.getGlobalAttribute1());
        o.setServerAttribute1("XX");
        context.commitChanges();
        assertFalse(o.getObjectId().isTemporary());
        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
        assertEquals("111", 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 4 with ClientChannelServerDiffsListener1

use of org.apache.cayenne.remote.ClientChannelServerDiffsListener1 in project cayenne by apache.

the class CayenneContextServerDiffsIT method testReturnDiffClientArcChanges.

@Test
public void testReturnDiffClientArcChanges() {
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
        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("XXX", o.getGlobalAttribute1());
    } 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

LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)4 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)4 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)4 Test (org.junit.Test)4 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)2