use of org.apache.cayenne.testdo.inheritance_people.PersonNotes in project cayenne by apache.
the class SingleTableInheritanceIT method testRelationshipAbstractToSuperPrefetchingDisjoint.
@Test
public void testRelationshipAbstractToSuperPrefetchingDisjoint() {
context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (2, 'AA', 'EE')"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (2, 'AA', 2)"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'BB', 2)"));
SelectQuery query = new SelectQuery(PersonNotes.class);
query.addPrefetch(PersonNotes.PERSON.disjoint());
query.addOrdering(PersonNotes.NOTES.asc());
List<PersonNotes> notes = context.performQuery(query);
assertEquals(2, notes.size());
final PersonNotes note = notes.get(0);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals("AA", note.getPerson().getName());
}
});
}
use of org.apache.cayenne.testdo.inheritance_people.PersonNotes in project cayenne by apache.
the class DataContextRelationshipQuery_PolymorphicIT method testPolymorphicSharedCache.
@Test
public void testPolymorphicSharedCache() 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);
PersonNotes n = context1.newObject(PersonNotes.class);
n.setNotes("N1");
n.setPerson(e);
context1.commitChanges();
// use different context to ensure we hit shared cache for relationship resolving
final PersonNotes nPeer = Cayenne.objectForPK(context2, PersonNotes.class, Cayenne.intPKForObject(n));
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
assertTrue(nPeer.getPerson() instanceof Employee);
}
});
}
use of org.apache.cayenne.testdo.inheritance_people.PersonNotes in project cayenne by apache.
the class SingleTableInheritanceIT method testRelationshipToAbstractSuper.
@Test
public void testRelationshipToAbstractSuper() {
context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (1, 'AA', 'EE')"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (1, 'AA', 1)"));
PersonNotes note = Cayenne.objectForPK(context, PersonNotes.class, 1);
assertNotNull(note);
assertNotNull(note.getPerson());
assertTrue(note.getPerson() instanceof Employee);
}
use of org.apache.cayenne.testdo.inheritance_people.PersonNotes in project cayenne by apache.
the class SingleTableInheritanceIT method testRelationshipAbstractToSuperPrefetchingJoint.
@Test
public void testRelationshipAbstractToSuperPrefetchingJoint() {
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)"));
SelectQuery query = new SelectQuery(PersonNotes.class);
query.addPrefetch(PersonNotes.PERSON.joint());
final PersonNotes note = (PersonNotes) Cayenne.objectForQuery(context, query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals("AA", note.getPerson().getName());
}
});
}
Aggregations