Search in sources :

Example 6 with Manager

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

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

the class DataContextEJBQLConditionsPeopleIT method testCollectionNotMemberOfId.

@Test
public void testCollectionNotMemberOfId() throws Exception {
    String ejbql = "SELECT DISTINCT m FROM Manager m JOIN m.managedDepartments d" + " WHERE m NOT MEMBER d.employees";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    Set<String> ids = new HashSet<String>();
    Iterator<?> it = objects.iterator();
    while (it.hasNext()) {
        Manager m = (Manager) it.next();
        ids.add(m.getName());
    }
    assertTrue(ids.contains("m2"));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Manager

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

the class DataContextEJBQLConditionsPeopleIT method testCollectionMemberOfId.

@Test
public void testCollectionMemberOfId() throws Exception {
    String ejbql = "SELECT DISTINCT m FROM Manager m JOIN m.managedDepartments d" + " WHERE m MEMBER d.employees";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> objects = context.performQuery(query);
    assertEquals(2, objects.size());
    Set<String> ids = new HashSet<String>();
    Iterator<?> it = objects.iterator();
    while (it.hasNext()) {
        Manager m = (Manager) it.next();
        ids.add(m.getName());
    }
    assertTrue(ids.contains("m1"));
    assertTrue(ids.contains("m3"));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Manager

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

the class SingleTableInheritanceIT method testMatchingOnSuperAttributesWithPrefetch.

@Test
public void testMatchingOnSuperAttributesWithPrefetch() throws Exception {
    create2PersonDataSet();
    // fetch on leaf, but match on a super attribute
    SelectQuery select = new SelectQuery(Employee.class);
    select.addPrefetch(Employee.TO_DEPARTMENT.disjoint());
    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 10 with Manager

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

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