use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextEJBQLUpdateIT method testUpdateNoQualifierNull.
@Test
public void testUpdateNoQualifierNull() throws Exception {
createThreeArtistsTwoPaintings();
EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p " + "WHERE p.estimatedPrice is not null");
Object notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(2l), notUpdated);
String ejbql = "UPDATE Painting AS p SET p.estimatedPrice = NULL";
EJBQLQuery query = new EJBQLQuery(ejbql);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(2, count[0]);
notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(0l), notUpdated);
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextEJBQLUpdateIT method testUpdateNoQualifierToOne.
@Test
public void testUpdateNoQualifierToOne() throws Exception {
createThreeArtistsTwoPaintings();
Artist object = Cayenne.objectForPK(context, Artist.class, 33003);
EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p " + "WHERE p.toArtist <> :artist");
check.setParameter("artist", object);
Object notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(2l), notUpdated);
String ejbql = "UPDATE Painting AS p SET p.toArtist = :artist";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("artist", object);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(2, count[0]);
notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(0l), notUpdated);
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextQueryChainIT method testSelectQuery.
@Test
public void testSelectQuery() {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("X");
context.commitChanges();
QueryChain chain = new QueryChain();
chain.addQuery(new SelectQuery(Artist.class));
chain.addQuery(new SelectQuery(Artist.class));
QueryResponse r = context.performGenericQuery(chain);
// data comes back as datarows
assertEquals(2, r.size());
r.reset();
r.next();
List<?> l1 = r.currentList();
r.next();
List<?> l2 = r.currentList();
assertTrue(l1.get(0) instanceof DataRow);
assertTrue(l2.get(0) instanceof DataRow);
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataDomainFiltersIT method testOnQuery_FilterOrdering.
@Test
public void testOnQuery_FilterOrdering() {
DataDomain domain = runtime.getDataDomain();
final List<String> results = new ArrayList<String>();
DataChannelFilter f1 = new MockDataChannelFilter() {
@Override
public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
results.add("f1start");
QueryResponse response = filterChain.onQuery(originatingContext, query);
results.add("f1end");
return response;
}
};
DataChannelFilter f2 = new MockDataChannelFilter() {
@Override
public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
results.add("f2start");
QueryResponse response = filterChain.onQuery(originatingContext, query);
results.add("f2end");
return response;
}
};
domain.filters.add(f1);
domain.filters.add(f2);
SelectQuery query = new SelectQuery(Artist.class);
QueryResponse response = domain.onQuery(context, query);
assertNotNull(response);
assertEquals(4, results.size());
assertEquals("f2start", results.get(0));
assertEquals("f1start", results.get(1));
assertEquals("f1end", results.get(2));
assertEquals("f2end", results.get(3));
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class MappedExec method execute.
public QueryResult execute(ObjectContext context) {
// TODO: switch ObjectContext to QueryResult instead of QueryResponse
// and create its own 'exec' method
QueryResponse response = context.performGenericQuery(this);
QueryResultBuilder builder = QueryResultBuilder.builder(response.size());
for (response.reset(); response.next(); ) {
if (response.isList()) {
builder.addSelectResult(response.currentList());
} else {
builder.addBatchUpdateResult(response.currentUpdateCount());
}
}
return builder.build();
}
Aggregations