use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache.
@Test
public void testPolymorphicSharedCache() throws SQLException {
tPerson.insert(1, "P1", "EM");
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", 1), false, ObjectIdQuery.CACHE);
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
assertTrue(ap1 instanceof Manager);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use different context to ensure we hit shared cache
AbstractPerson ap2 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
assertTrue(ap2 instanceof Manager);
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicLocalCache.
@Test
public void testPolymorphicLocalCache() throws SQLException {
tPerson.insert(1, "P1", "EM");
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", 1), false, ObjectIdQuery.CACHE);
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
assertTrue(ap1 instanceof Manager);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use same context to ensure we hit local cache
// note that this does not guarantee test correctness. If local
// cache polymorphic ID lookup is broken, shared cache will pick
// it up
AbstractPerson ap2 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
assertTrue(ap2 instanceof Manager);
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextPerformQueryAPIIT method testObjectQueryWithLocalCache.
@Test
public void testObjectQueryWithLocalCache() throws Exception {
createTwoArtists();
List<?> artists = context.performQuery("QueryWithLocalCache", true);
assertEquals(2, artists.size());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> artists1 = context.performQuery("QueryWithLocalCache", false);
assertEquals(2, artists1.size());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure 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.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetch_ToManyNoReverseWithQualifier.
@Test
public void testPrefetch_ToManyNoReverseWithQualifier() throws Exception {
createTwoArtistsAndTwoPaintingsDataSet();
ObjEntity paintingEntity = context.getEntityResolver().getObjEntity(Painting.class);
ObjRelationship relationship = paintingEntity.getRelationship("toArtist");
paintingEntity.removeRelationship("toArtist");
try {
SelectQuery q = new SelectQuery(Artist.class);
q.setQualifier(ExpressionFactory.matchExp("artistName", "artist2"));
q.addPrefetch(Artist.PAINTING_ARRAY.disjoint());
final List<Artist> result = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Artist a1 = result.get(0);
List<?> toMany = (List<?>) a1.readPropertyDirectly("paintingArray");
assertNotNull(toMany);
assertFalse(((ValueHolder) toMany).isFault());
}
});
} finally {
paintingEntity.addRelationship(relationship);
}
}
Aggregations