Search in sources :

Example 11 with Employee

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

the class SingleTableInheritanceIT method testCAY592.

@Test
public void testCAY592() throws Exception {
    createManagerAddressDataSet();
    List<?> addresses = context.performQuery(new SelectQuery(Address.class));
    assertEquals(1, addresses.size());
    Address address = (Address) addresses.get(0);
    Employee e = address.getToEmployee();
    // CAY-592 - make sure modification of the address in a parallel context
    // doesn't mess up the Manager
    e = (Employee) Cayenne.objectForPK(context2, e.getObjectId());
    address = e.getAddresses().get(0);
    assertSame(e, address.getToEmployee());
    address.setCity("XYZ");
    assertSame(e, address.getToEmployee());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Address(org.apache.cayenne.testdo.inheritance_people.Address) Test(org.junit.Test)

Example 12 with Employee

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

the class DeepMergeOperationInheritanceIT method assertMergeResult.

private void assertMergeResult(Department d1, DeepMergeOperation op) {
    queryInterceptor.runWithQueriesBlocked(() -> {
        Department d2 = op.merge(d1);
        assertNotNull(d2);
        assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
        for (Employee ex : d2.getEmployees()) {
            if ("E2".equals(ex.getName())) {
                assertThat(ex, is(instanceOf(Manager.class)));
            } else {
                assertThat(ex, is(not(instanceOf(Manager.class))));
            }
        }
    });
}
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)

Example 13 with Employee

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

the class DeepMergeOperationInheritanceIT method testDeepMergeNonExistentSubclass.

@Test
public void testDeepMergeNonExistentSubclass() {
    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();
    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)

Aggregations

Employee (org.apache.cayenne.testdo.inheritance_people.Employee)13 Test (org.junit.Test)12 SelectQuery (org.apache.cayenne.query.SelectQuery)6 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)5 Manager (org.apache.cayenne.testdo.inheritance_people.Manager)5 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)4 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)4 SQLTemplate (org.apache.cayenne.query.SQLTemplate)3 Department (org.apache.cayenne.testdo.inheritance_people.Department)3 List (java.util.List)2 Address (org.apache.cayenne.testdo.inheritance_people.Address)2 CustomerRepresentative (org.apache.cayenne.testdo.inheritance_people.CustomerRepresentative)2 ObjectId (org.apache.cayenne.ObjectId)1 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)1 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)1 ClientCompany (org.apache.cayenne.testdo.inheritance_people.ClientCompany)1