use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.
the class NestedDataContextWriteIT method testCommitChangesToParentPropagatedKey.
@Test
public void testCommitChangesToParentPropagatedKey() throws Exception {
final DataContext context = createDataContext();
final ObjectContext childContext = runtime.newContext(context);
final Painting childMaster = childContext.newObject(Painting.class);
childMaster.setPaintingTitle("Master");
final PaintingInfo childDetail1 = childContext.newObject(PaintingInfo.class);
childDetail1.setTextReview("Detail1");
childDetail1.setPainting(childMaster);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
childContext.commitChangesToParent();
assertEquals(PersistenceState.COMMITTED, childMaster.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, childDetail1.getPersistenceState());
Painting parentMaster = (Painting) context.getGraphManager().getNode(childMaster.getObjectId());
assertNotNull(parentMaster);
assertEquals(PersistenceState.NEW, parentMaster.getPersistenceState());
PaintingInfo parentDetail1 = (PaintingInfo) context.getGraphManager().getNode(childDetail1.getObjectId());
assertNotNull(parentDetail1);
assertEquals(PersistenceState.NEW, parentDetail1.getPersistenceState());
assertSame(parentMaster, parentDetail1.getPainting());
assertSame(parentDetail1, parentMaster.getToPaintingInfo());
}
});
}
use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchToOneWithBackRelationship.
@Test
public void testPrefetchToOneWithBackRelationship() throws Exception {
createArtistWithTwoPaintingsAndTwoInfosDataSet();
SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
query.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
query.addPrefetch(Painting.TO_PAINTING_INFO.dot(PaintingInfo.PAINTING).disjoint());
final List<Painting> results = context.select(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
Painting p0 = results.get(0);
PaintingInfo pi0 = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
assertNotNull(pi0);
assertNotNull(pi0.readPropertyDirectly(PaintingInfo.PAINTING.getName()));
}
});
}
use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchJointAndDisjointByIdTogether.
@Test
public void testPrefetchJointAndDisjointByIdTogether() throws Exception {
createArtistWithTwoPaintingsAndTwoInfosDataSet();
SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
query.addPrefetch(Painting.TO_ARTIST.joint());
query.addPrefetch(Painting.TO_PAINTING_INFO.disjointById());
final List<Painting> results = context.select(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
Painting p0 = results.get(0);
Artist a0 = (Artist) p0.readPropertyDirectly(Painting.TO_ARTIST.getName());
assertNotNull(a0);
PaintingInfo info = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
assertNotNull(info);
}
});
}
use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_OneToOneWithQualifier.
@Test
public void testPrefetch_OneToOneWithQualifier() throws Exception {
createArtistWithTwoPaintingsAndTwoInfosDataSet();
Expression e = ExpressionFactory.likeExp("toArtist.artistName", "a%");
SelectQuery q = new SelectQuery(Painting.class, e);
q.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
q.addOrdering(Painting.PAINTING_TITLE.asc());
final List<Painting> results = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, results.size());
// testing non-null to-one target
Painting p0 = results.get(0);
Object o2 = p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
assertTrue(o2 instanceof PaintingInfo);
PaintingInfo pi2 = (PaintingInfo) o2;
assertEquals(PersistenceState.COMMITTED, pi2.getPersistenceState());
assertEquals(Cayenne.intPKForObject(p0), Cayenne.intPKForObject(pi2));
// testing null to-one target
Painting p1 = results.get(1);
assertNull(p1.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName()));
// there was a bug marking an object as dirty when clearing the
// relationships
assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
}
});
}
use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.
the class CayenneDataObjectRelationshipsIT method testReadToOneRel2.
@Test
public void testReadToOneRel2() throws Exception {
// test chained calls to read relationships
createArtistWithPaintingAndInfoDataSet();
PaintingInfo pi1 = Cayenne.objectForPK(context, PaintingInfo.class, 6);
Painting p1 = pi1.getPainting();
p1.getPaintingTitle();
Artist a1 = p1.getToArtist();
assertNotNull(a1);
assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
assertEquals("aX", a1.getArtistName());
assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
}
Aggregations