Search in sources :

Example 1 with Employee

use of org.apache.cayenne.testdo.inheritance_people.Employee 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 Employee

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

the class SingleTableInheritanceIT method testSave.

@Test
public void testSave() throws Exception {
    ClientCompany company = context.newObject(ClientCompany.class);
    company.setName("Boeing");
    CustomerRepresentative rep = context.newObject(CustomerRepresentative.class);
    rep.setName("Joe Schmoe");
    rep.setToClientCompany(company);
    rep.setPersonType("C");
    Employee employee = context.newObject(Employee.class);
    employee.setName("Our Joe Schmoe");
    employee.setPersonType("E");
    context.commitChanges();
    context.invalidateObjects(company, rep, employee);
    SelectQuery query = new SelectQuery(CustomerRepresentative.class);
    List<?> reps = context2.performQuery(query);
    assertEquals(1, reps.size());
    assertEquals(1, countObjectOfClass(reps, CustomerRepresentative.class));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientCompany(org.apache.cayenne.testdo.inheritance_people.ClientCompany) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) CustomerRepresentative(org.apache.cayenne.testdo.inheritance_people.CustomerRepresentative) Test(org.junit.Test)

Example 3 with Employee

use of org.apache.cayenne.testdo.inheritance_people.Employee 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 Employee

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

the class SingleTableInheritanceIT method testManagerAddress.

/**
 * Tests that to-one relationship produces correct subclass.
 */
@Test
public void testManagerAddress() 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();
    assertSame(Manager.class, e.getClass());
}
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 5 with Employee

use of org.apache.cayenne.testdo.inheritance_people.Employee 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);
        }
    });
}
Also used : Employee(org.apache.cayenne.testdo.inheritance_people.Employee) PersonNotes(org.apache.cayenne.testdo.inheritance_people.PersonNotes) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) 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