use of org.apache.cayenne.testdo.inheritance_people.AbstractPerson in project cayenne by apache.
the class SingleTableInheritanceIT method testPaginatedQueries.
@Test
public void testPaginatedQueries() throws Exception {
create5PersonDataSet();
SelectQuery select = new SelectQuery(AbstractPerson.class);
select.addOrdering("db:" + AbstractPerson.PERSON_ID_PK_COLUMN, SortOrder.ASCENDING);
select.setPageSize(3);
List<AbstractPerson> results = context.performQuery(select);
assertEquals(5, results.size());
assertTrue(results.get(0) instanceof Employee);
// this is where things would blow up per CAY-1142
assertTrue(results.get(1) instanceof Manager);
assertTrue(results.get(3) instanceof Manager);
assertTrue(results.get(4) instanceof Employee);
}
use of org.apache.cayenne.testdo.inheritance_people.AbstractPerson 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.testdo.inheritance_people.AbstractPerson 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.testdo.inheritance_people.AbstractPerson in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache_AfterCayenneInsert.
@Test
public void testPolymorphicSharedCache_AfterCayenneInsert() throws SQLException {
// see CAY-2101... we are trying to get a snapshot from a new object in the shared cache, and then read this
// object via a relationship, so that shared cache is consulted
Employee e = context1.newObject(Employee.class);
e.setName("E1");
e.setSalary(1234.01f);
context1.commitChanges();
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", Cayenne.intPKForObject(e)), false, ObjectIdQuery.CACHE);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use different context to ensure we hit shared cache
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
assertTrue(ap1 instanceof Employee);
}
});
}
use of org.apache.cayenne.testdo.inheritance_people.AbstractPerson in project cayenne by apache.
the class SingleTableInheritanceIT method testRelationshipAbstractFromSuperPrefetchingJoint.
@Test
public void testRelationshipAbstractFromSuperPrefetchingJoint() {
context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (3, 'AA', 'EE')"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'AA', 3)"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (4, 'BB', 3)"));
SelectQuery query = new SelectQuery(AbstractPerson.class);
query.addPrefetch(AbstractPerson.NOTES.joint());
final AbstractPerson person = (AbstractPerson) Cayenne.objectForQuery(context, query);
assertTrue(person instanceof Employee);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, person.getNotes().size());
String[] names = new String[2];
names[0] = person.getNotes().get(0).getNotes();
names[1] = person.getNotes().get(1).getNotes();
List<String> nameSet = Arrays.asList(names);
assertTrue(nameSet.contains("AA"));
assertTrue(nameSet.contains("BB"));
}
});
}
Aggregations