Search in sources :

Example 21 with QueryResponse

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();
}
Also used : QueryResponse(org.apache.cayenne.QueryResponse)

Example 22 with QueryResponse

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();
}
Also used : QueryResultBuilder(org.apache.cayenne.util.QueryResultBuilder) QueryResponse(org.apache.cayenne.QueryResponse)

Example 23 with QueryResponse

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]);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) QueryResponse(org.apache.cayenne.QueryResponse) Test(org.junit.Test)

Example 24 with QueryResponse

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]);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) QueryResponse(org.apache.cayenne.QueryResponse) Test(org.junit.Test)

Example 25 with QueryResponse

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);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BooleanTestEntity(org.apache.cayenne.testdo.numeric_types.BooleanTestEntity) QueryResponse(org.apache.cayenne.QueryResponse) Test(org.junit.Test)

Aggregations

QueryResponse (org.apache.cayenne.QueryResponse)31 Test (org.junit.Test)24 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)12 SelectQuery (org.apache.cayenne.query.SelectQuery)9 ObjectId (org.apache.cayenne.ObjectId)7 Query (org.apache.cayenne.query.Query)6 DataRow (org.apache.cayenne.DataRow)5 ObjectContext (org.apache.cayenne.ObjectContext)5 EntityResolver (org.apache.cayenne.map.EntityResolver)5 List (java.util.List)3 CayenneContext (org.apache.cayenne.CayenneContext)3 MockPersistentObject (org.apache.cayenne.MockPersistentObject)3 MockEventManager (org.apache.cayenne.event.MockEventManager)3 DataMap (org.apache.cayenne.map.DataMap)3 ObjEntity (org.apache.cayenne.map.ObjEntity)3 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)3 HashSet (java.util.HashSet)2 DataChannelFilter (org.apache.cayenne.DataChannelFilter)2 DataChannelFilterChain (org.apache.cayenne.DataChannelFilterChain)2 MockDataChannelFilter (org.apache.cayenne.MockDataChannelFilter)2