use of org.apache.cayenne.reflect.LifecycleCallbackRegistry in project cayenne by apache.
the class EJBQLQueryIT method testNullObjectsCallback.
@Test
public void testNullObjectsCallback() throws Exception {
tArtist.insert(1, "a1");
tArtist.insert(2, "a2");
tArtist.insert(3, "a3");
tPainting.insert(1, 2, "title1");
tPainting.insert(2, 1, "title2");
tPainting.insert(3, 1, "title3");
// set callback to be called
LifecycleCallbackRegistry registry = runtime.getDataDomain().getEntityResolver().getCallbackRegistry();
registry.addCallback(LifecycleEvent.POST_LOAD, Painting.class, "postAddCallback");
// select Paintings, where one of it will be null
EJBQLQuery query = new EJBQLQuery("select a.paintingArray+ from Artist a order by a.artistName");
List<Painting> result1 = context.performQuery(query);
assertEquals(4, result1.size());
assertNull(result1.get(3));
for (int i = 0; i < 3; i++) {
assertNotNull(result1.get(i));
assertTrue(result1.get(i).isPostAdded());
}
}
use of org.apache.cayenne.reflect.LifecycleCallbackRegistry in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPostAddCallback.
@Test
public void testPostAddCallback() throws Exception {
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) {
flag[0] = true;
}
public void preRemove(Object entity) {
}
public void preUpdate(Object entity) {
}
public void prePersist(Object entity) {
}
});
clientContext.newObject(ClientMtTable1.class);
assertFalse(flag[0]);
clientContext.commitChanges();
assertTrue(flag[0]);
} finally {
callbackRegistry.clear();
}
}
Aggregations