use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class ProcedureCall method call.
public ProcedureResult<T> call(ObjectContext context) {
QueryResponse response = context.performGenericQuery(this);
ProcedureResultBuilder<T> builder = ProcedureResultBuilder.builder(response.size(), resultClass);
for (response.reset(); response.next(); ) {
if (response.isList()) {
builder.addSelectResult(response.currentList());
} else {
builder.addBatchUpdateResult(response.currentUpdateCount());
}
}
return builder.build();
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class SQLExec 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();
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextEJBQLDeleteIT method testDeleteNoQualifier.
@Test
public void testDeleteNoQualifier() throws Exception {
createPaintingsDataSet();
String ejbql = "delete from Painting AS p";
EJBQLQuery query = new EJBQLQuery(ejbql);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(2, count[0]);
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextEJBQLDeletePKIT method testDeleteIdVar.
@Test
public void testDeleteIdVar() throws Exception {
createMeaningfulPKDataSet();
EJBQLQuery q = new EJBQLQuery("select m.pkAttribute from MeaningfulPKTest1 m");
List<Integer> id = context.performQuery(q);
String ejbql = "delete from MeaningfulPKTest1 m WHERE m.pkAttribute in (:id)";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("id", id);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(33, count[0]);
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextEJBQLNumericalFunctionalIT method testUpdateNoQualifierBoolean.
@Test
public void testUpdateNoQualifierBoolean() throws Exception {
BooleanTestEntity o1 = context.newObject(BooleanTestEntity.class);
o1.setBooleanColumn(Boolean.TRUE);
BooleanTestEntity o2 = context.newObject(BooleanTestEntity.class);
o2.setBooleanColumn(Boolean.FALSE);
BooleanTestEntity o3 = context.newObject(BooleanTestEntity.class);
o3.setBooleanColumn(Boolean.FALSE);
context.commitChanges();
EJBQLQuery check = new EJBQLQuery("select count(p) from BooleanTestEntity p " + "WHERE p.booleanColumn = true");
Object notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(1l), notUpdated);
String ejbql = "UPDATE BooleanTestEntity AS p SET p.booleanColumn = true";
EJBQLQuery query = new EJBQLQuery(ejbql);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(3, count[0]);
notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(3l), notUpdated);
}
Aggregations