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);
}
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));
}
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);
}
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());
}
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);
}
});
}
Aggregations