use of org.apache.cayenne.testdo.inheritance_people.Employee in project cayenne by apache.
the class DataContextEJBQLInheritanceIT method testSelect.
@Test
public void testSelect() throws Exception {
EJBQLQuery superclass = new EJBQLQuery("select p from AbstractPerson p ORDER BY p.name");
List<?> superclassResult = context.performQuery(superclass);
assertEquals(5, superclassResult.size());
assertEquals(Employee.class.getName(), superclassResult.get(0).getClass().getName());
assertEquals(Employee.class.getName(), superclassResult.get(1).getClass().getName());
assertEquals(Manager.class.getName(), superclassResult.get(2).getClass().getName());
assertEquals(Manager.class.getName(), superclassResult.get(3).getClass().getName());
assertEquals(CustomerRepresentative.class.getName(), superclassResult.get(4).getClass().getName());
EJBQLQuery subclass = new EJBQLQuery("select e from Employee e ORDER BY e.name");
List<?> subclassResult = context.performQuery(subclass);
assertEquals(4, subclassResult.size());
assertEquals(Employee.class.getName(), subclassResult.get(0).getClass().getName());
assertEquals(Employee.class.getName(), subclassResult.get(1).getClass().getName());
assertEquals(Manager.class.getName(), subclassResult.get(2).getClass().getName());
assertEquals(Manager.class.getName(), subclassResult.get(3).getClass().getName());
}
use of org.apache.cayenne.testdo.inheritance_people.Employee 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.Employee 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"));
}
});
}
use of org.apache.cayenne.testdo.inheritance_people.Employee 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.Employee 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"));
}
});
}
Aggregations