Search in sources :

Example 1 with Address

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

the class SingleTableInheritanceIT method testEmployeeAddress.

/**
 * Tests that to-one relationship produces correct subclass.
 */
@Test
public void testEmployeeAddress() throws Exception {
    createEmployeeAddressDataSet();
    List<?> addresses = context.performQuery(new SelectQuery(Address.class));
    assertEquals(1, addresses.size());
    Address address = (Address) addresses.get(0);
    assertSame(Employee.class, address.getToEmployee().getClass());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Address(org.apache.cayenne.testdo.inheritance_people.Address) Test(org.junit.Test)

Example 2 with Address

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

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

the class DataContextEJBQLConditionsPeopleIT method setUp.

@Before
public void setUp() {
    // TODO: use TableHelper to create test data
    Department d1 = context.newObject(Department.class);
    d1.setName("d1");
    Department d2 = context.newObject(Department.class);
    d2.setName("d2");
    Department d3 = context.newObject(Department.class);
    d3.setName("d3");
    context.commitChanges();
    Manager m1 = context.newObject(Manager.class);
    m1.setName("m1");
    m1.setPersonType("EM");
    Manager m2 = context.newObject(Manager.class);
    m2.setName("m2");
    m2.setPersonType("EM");
    Manager m3 = context.newObject(Manager.class);
    m3.setName("m3");
    m3.setPersonType("EM");
    Address a1 = context.newObject(Address.class);
    m1.addToAddresses(a1);
    Address a2 = context.newObject(Address.class);
    m2.addToAddresses(a2);
    Address a3 = context.newObject(Address.class);
    m3.addToAddresses(a3);
    d1.addToEmployees(m1);
    d1.addToEmployees(m2);
    d3.addToEmployees(m3);
    context.commitChanges();
    d1.setToManager(m1);
    d2.setToManager(m2);
    d3.setToManager(m3);
    context.commitChanges();
}
Also used : Department(org.apache.cayenne.testdo.inheritance_people.Department) Address(org.apache.cayenne.testdo.inheritance_people.Address) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Before(org.junit.Before)

Example 4 with Address

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

Aggregations

Address (org.apache.cayenne.testdo.inheritance_people.Address)4 SelectQuery (org.apache.cayenne.query.SelectQuery)3 Test (org.junit.Test)3 Employee (org.apache.cayenne.testdo.inheritance_people.Employee)2 Department (org.apache.cayenne.testdo.inheritance_people.Department)1 Manager (org.apache.cayenne.testdo.inheritance_people.Manager)1 Before (org.junit.Before)1