use of org.apache.cayenne.reflect.LifecycleCallbackRegistry in project cayenne by apache.
the class CayenneContextReflexiveIT method testCAY830.
@Test
public void testCAY830() throws Exception {
// an exception was triggered within POST_LOAD callback
LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addListener(Reflexive.class, new LifecycleListener() {
public void postLoad(Object entity) {
}
public void postPersist(Object entity) {
}
public void postRemove(Object entity) {
}
public void postUpdate(Object entity) {
}
public void postAdd(Object entity) {
}
public void preRemove(Object entity) {
}
public void preUpdate(Object entity) {
}
public void prePersist(Object entity) {
}
});
ClientReflexive o1 = clientContext.newObject(ClientReflexive.class);
o1.setName("parent");
ClientReflexive o2 = clientContext.newObject(ClientReflexive.class);
o2.setName("child");
o2.setToParent(o1);
clientContext.commitChanges();
clientContext.deleteObjects(o1);
clientContext.deleteObjects(o2);
clientContext.commitChanges();
// per CAY-830 an exception is thrown here
} finally {
callbackRegistry.clear();
}
}
use of org.apache.cayenne.reflect.LifecycleCallbackRegistry 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();
}
}
use of org.apache.cayenne.reflect.LifecycleCallbackRegistry 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();
}
}
use of org.apache.cayenne.reflect.LifecycleCallbackRegistry in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPostAddOnObjectCallback.
@Test
public void testPostAddOnObjectCallback() throws Exception {
final DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
LifecycleCallbackRegistry callbackRegistry = serverContext.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addCallback(LifecycleEvent.POST_ADD, MtTable1.class, "prePersistMethod");
final Persistent clientObject = clientContext.newObject(ClientMtTable1.class);
clientContext.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
// find peer
MtTable1 peer = (MtTable1) serverContext.getGraphManager().getNode(clientObject.getObjectId());
assertNotNull(peer);
assertTrue(peer.isPrePersisted());
}
}.runTest(1000);
} finally {
callbackRegistry.clear();
}
}
use of org.apache.cayenne.reflect.LifecycleCallbackRegistry in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPreRemoveCallback.
@Test
public void testPreRemoveCallback() throws Exception {
// an exception was triggered within POST_LOAD callback
LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
final boolean[] flag = new boolean[1];
try {
callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {
public void postLoad(Object entity) {
}
public void postPersist(Object entity) {
}
public void postRemove(Object entity) {
}
public void postUpdate(Object entity) {
}
public void postAdd(Object entity) {
}
public void preRemove(Object entity) {
flag[0] = true;
}
public void preUpdate(Object entity) {
}
public void prePersist(Object entity) {
}
});
ClientMtTable1 object = clientContext.newObject(ClientMtTable1.class);
assertFalse(flag[0]);
clientContext.commitChanges();
assertFalse(flag[0]);
clientContext.deleteObjects(object);
clientContext.commitChanges();
assertTrue(flag[0]);
} finally {
callbackRegistry.clear();
}
}
Aggregations