use of org.apache.cayenne.testdo.inheritance_people.Manager in project cayenne by apache.
the class DeepMergeOperationInheritanceIT method testDeepMergeExistingSubclass.
@Test
public void testDeepMergeExistingSubclass() {
final Department d1 = context.newObject(Department.class);
d1.setName("D1");
// need to do double commit as Ashwood sorter blows on Employees/Departments ordering...
context.commitChanges();
Employee e1 = context.newObject(Employee.class);
e1.setName("E1");
e1.setPersonType("EE");
d1.addToEmployees(e1);
Manager e2 = context.newObject(Manager.class);
e2.setName("E2");
e2.setPersonType("EM");
d1.addToEmployees(e2);
context.commitChanges();
// need to make sure source relationship is resolved as a result of some Ashwood strangeness...
d1.getEmployees().size();
// resolve Employees
context1.performQuery(new SelectQuery<>(Employee.class));
final DeepMergeOperation op = new DeepMergeOperation(context1);
assertMergeResult(d1, op);
}
use of org.apache.cayenne.testdo.inheritance_people.Manager in project cayenne by apache.
the class SingleTableInheritanceIT method testMatchingOnSuperAttributes.
@Test
public void testMatchingOnSuperAttributes() throws Exception {
create2PersonDataSet();
// fetch on leaf, but match on a super attribute
SelectQuery select = new SelectQuery(Manager.class);
select.andQualifier(AbstractPerson.NAME.eq("E2"));
List<Manager> results = context.performQuery(select);
assertEquals(1, results.size());
assertEquals("E2", results.get(0).getName());
}
use of org.apache.cayenne.testdo.inheritance_people.Manager 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.Manager 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.Manager 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);
}
});
}
Aggregations