Search in sources :

Example 6 with AbstractPerson

use of org.apache.cayenne.testdo.inheritance_people.AbstractPerson in project cayenne by apache.

the class SingleTableInheritanceIT method testRelationshipAbstractFromSuperPrefetchingDisjoint.

@Test
public void testRelationshipAbstractFromSuperPrefetchingDisjoint() {
    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.disjoint());
    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"));
        }
    });
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) SelectQuery(org.apache.cayenne.query.SelectQuery) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) PersonNotes(org.apache.cayenne.testdo.inheritance_people.PersonNotes) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Aggregations

AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)6 Test (org.junit.Test)6 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)5 Employee (org.apache.cayenne.testdo.inheritance_people.Employee)4 ObjectId (org.apache.cayenne.ObjectId)3 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)3 SelectQuery (org.apache.cayenne.query.SelectQuery)3 Manager (org.apache.cayenne.testdo.inheritance_people.Manager)3 List (java.util.List)2 SQLTemplate (org.apache.cayenne.query.SQLTemplate)2 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)2