use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class SimpleIdIncrementalFaultListPrefetchIT method testPrefetch3.
/**
* Test that a to-many relationship is initialized.
*/
@Test
public void testPrefetch3() throws Exception {
createArtistsAndPaintingsDataSet();
Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
SelectQuery q = new SelectQuery("Artist", e);
q.addPrefetch("paintingArray");
q.setPageSize(3);
IncrementalFaultList result = (IncrementalFaultList) context.performQuery(q);
assertEquals(6, result.size());
// currently queries with prefetch do not resolve their first page
assertEquals(result.size(), result.getUnfetchedObjects());
// go through the second page objects and check their to many
for (int i = 3; i < 6; i++) {
Artist a = (Artist) result.get(i);
List paintings = a.getPaintingArray();
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(1, paintings.size());
}
}
use of org.apache.cayenne.query.SelectQuery in project cayenne by apache.
the class SimpleIdIncrementalFaultListPrefetchIT method testPrefetch1.
/**
* Test that all queries specified in prefetch are executed with a single prefetch
* path.
*/
@Test
public void testPrefetch1() throws Exception {
createArtistsAndPaintingsDataSet();
Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
SelectQuery q = new SelectQuery("Artist", e);
q.addPrefetch("paintingArray");
q.setPageSize(3);
final IncrementalFaultList<?> result = (IncrementalFaultList) context.performQuery(q);
assertEquals(6, result.size());
// currently queries with prefetch do not resolve their first page
assertEquals(result.size(), result.getUnfetchedObjects());
int count = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
// go through the second page objects and count queries
for (int i = 3; i < 6; i++) {
result.get(i);
}
}
});
// within the same page only one query should've been executed
assertEquals(1, count);
}
use of org.apache.cayenne.query.SelectQuery 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.query.SelectQuery in project cayenne by apache.
the class SingleTableInheritanceIT method testMatchingOnSuperAttributes.
@Test
public void testMatchingOnSuperAttributes() throws Exception {
create2PersonDataSet();
// fetch on leaf, but match on a super attribute
SelectQuery select = new SelectQuery(Manager.class);
select.andQualifier(AbstractPerson.NAME.eq("E2"));
List<Manager> results = context.performQuery(select);
assertEquals(1, results.size());
assertEquals("E2", results.get(0).getName());
}
use of org.apache.cayenne.query.SelectQuery 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);
}
Aggregations