use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataDomainCallbacksIT method testPostLoad_MixedResult.
@Test
public void testPostLoad_MixedResult() throws Exception {
LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
registry.addCallback(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
MockCallingBackListener listener = new MockCallingBackListener();
registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, listener, "publicCallback");
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XX");
context.commitChanges();
assertEquals(0, a1.getPostLoaded());
assertNull(listener.getPublicCalledbackEntity());
EJBQLQuery q = new EJBQLQuery("select a, a.artistName from Artist a");
context.performQuery(q);
assertEquals(1, a1.getPostLoaded());
assertSame(a1, listener.getPublicCalledbackEntity());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataDomainCallbacksIT method testPostLoad_LocalObject.
@Test
public void testPostLoad_LocalObject() throws Exception {
LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XX");
context.commitChanges();
registry.addCallback(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
MockCallingBackListener listener = new MockCallingBackListener();
registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, listener, "publicCallback");
Artist a2 = context1.localObject(a1);
assertEquals(PersistenceState.HOLLOW, a2.getPersistenceState());
assertEquals(0, a2.getPostLoaded());
assertNull(listener.getPublicCalledbackEntity());
a2.getArtistName();
assertEquals(1, a2.getPostLoaded());
assertSame(a2, listener.getPublicCalledbackEntity());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataDomainCallbacksIT method testPostPersist.
@Test
public void testPostPersist() {
LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XX");
context.commitChanges();
assertFalse(a1.isPostPersisted());
registry.addCallback(LifecycleEvent.POST_PERSIST, Artist.class, "postPersistCallback");
MockCallingBackListener listener2 = new MockCallingBackListener() {
@Override
public void publicCallback(Object entity) {
super.publicCallback(entity);
assertFalse(((Persistent) entity).getObjectId().isTemporary());
}
};
registry.addListener(LifecycleEvent.POST_PERSIST, Artist.class, listener2, "publicCallback");
Artist a2 = context.newObject(Artist.class);
a2.setArtistName("XX");
context.commitChanges();
assertFalse(a1.isPostPersisted());
assertTrue(a2.isPostPersisted());
assertSame(a2, listener2.getPublicCalledbackEntity());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataRowUtilsIT method testMerge.
@Test
public void testMerge() throws Exception {
createOneArtist();
String n1 = "changed";
String n2 = "changed again";
SelectQuery artistQ = new SelectQuery(Artist.class);
Artist a1 = (Artist) context.performQuery(artistQ).get(0);
a1.setArtistName(n1);
DataRow s2 = new DataRow(2);
s2.put("ARTIST_NAME", n2);
s2.put("DATE_OF_BIRTH", new java.util.Date());
ClassDescriptor d = context.getEntityResolver().getClassDescriptor("Artist");
DataRowUtils.mergeObjectWithSnapshot(context, d, a1, s2);
// name was modified, so it should not change during merge
assertEquals(n1, a1.getArtistName());
// date of birth came from database, it should be updated during merge
assertEquals(s2.get("DATE_OF_BIRTH"), a1.getDateOfBirth());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DeleteObjectIT method testDeleteObjectsRelationshipCollection.
@Test
public void testDeleteObjectsRelationshipCollection() throws Exception {
createObjectsRelationshipCollectionDataSet();
Artist artist = Cayenne.objectForPK(context, Artist.class, 1);
List<Painting> paintings = artist.getPaintingArray();
assertEquals(3, paintings.size());
// create a clone to be able to inspect paintings after deletion
List<Painting> paintingsClone = new ArrayList<Painting>(paintings);
for (Painting object : paintingsClone) {
assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
}
context.deleteObjects(paintings);
// as Painting -> Artist has Nullify rule, relationship list has to be
// cleaned up,
// and no exceptions thrown on concurrent modification...
ObjRelationship r = context.getEntityResolver().getObjEntity(Painting.class).getRelationship("toArtist");
assertEquals(DeleteRule.NULLIFY, r.getDeleteRule());
assertEquals(0, paintings.size());
for (Painting object : paintingsClone) {
assertEquals(PersistenceState.DELETED, object.getPersistenceState());
}
}
Aggregations