Search in sources :

Example 1 with Manager

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);
}
Also used : Department(org.apache.cayenne.testdo.inheritance_people.Department) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Test(org.junit.Test)

Example 2 with Manager

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Test(org.junit.Test)

Example 3 with Manager

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);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 4 with Manager

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);
        }
    });
}
Also used : ObjectId(org.apache.cayenne.ObjectId) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 5 with 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);
        }
    });
}
Also used : ObjectId(org.apache.cayenne.ObjectId) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Aggregations

Manager (org.apache.cayenne.testdo.inheritance_people.Manager)10 Test (org.junit.Test)9 SelectQuery (org.apache.cayenne.query.SelectQuery)3 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)3 Department (org.apache.cayenne.testdo.inheritance_people.Department)3 Employee (org.apache.cayenne.testdo.inheritance_people.Employee)3 HashSet (java.util.HashSet)2 ObjectId (org.apache.cayenne.ObjectId)2 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)2 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)2 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)2 Address (org.apache.cayenne.testdo.inheritance_people.Address)1 Before (org.junit.Before)1