Search in sources :

Example 11 with Query

use of org.apache.cayenne.query.Query in project cayenne by apache.

the class SchemaUpdateStrategyIT method testCreateIfNoSchemaStrategy.

@Test
public void testCreateIfNoSchemaStrategy() throws Exception {
    setStrategy(CreateIfNoSchemaStrategy.class);
    String template = "SELECT #result('id' 'int') FROM SUS1";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    OperationObserver observer = new MockOperationObserver();
    node.performQueries(Collections.singletonList((Query) query), observer);
    Map<String, Boolean> nameTables = tablesMap();
    assertTrue(nameTables.get("SUS1"));
    assertEquals(2, existingTables().size());
    node.performQueries(Collections.singletonList(query), observer);
    assertEquals(2, existingTables().size());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Query(org.apache.cayenne.query.Query) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) OperationObserver(org.apache.cayenne.access.OperationObserver) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 12 with Query

use of org.apache.cayenne.query.Query in project cayenne by apache.

the class ThrowOnPartialSchemaStrategyIT method testThrowOnPartialStrategyTableNoExist.

@Test
public void testThrowOnPartialStrategyTableNoExist() throws Exception {
    String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
    SQLTemplate query = new SQLTemplate(Object.class, template);
    MockOperationObserver observer = new MockOperationObserver();
    setStrategy(ThrowOnPartialSchemaStrategy.class);
    try {
        node.performQueries(Collections.singletonList((Query) query), observer);
    } catch (CayenneRuntimeException e) {
        assertNotNull(e);
    }
    try {
        node.performQueries(Collections.singletonList((Query) query), observer);
    } catch (CayenneRuntimeException e) {
        assertNotNull(e);
    }
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Query(org.apache.cayenne.query.Query) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 13 with Query

use of org.apache.cayenne.query.Query in project cayenne by apache.

the class MockQueryEngine method initWithPresetResults.

private void initWithPresetResults(Collection queries, OperationObserver resultConsumer) {
    runCount++;
    // stick preset results to the consumer
    Iterator it = queries.iterator();
    while (it.hasNext()) {
        Query query = (Query) it.next();
        resultConsumer.nextRows(query, (List) results.get(query));
    }
}
Also used : Query(org.apache.cayenne.query.Query) Iterator(java.util.Iterator)

Example 14 with Query

use of org.apache.cayenne.query.Query in project cayenne by apache.

the class DataDomainFiltersIT method testOnQuery_Blocking.

@Test
public void testOnQuery_Blocking() {
    DataDomain domain = runtime.getDataDomain();
    final QueryResponse r1 = new ListResponse();
    final QueryResponse r2 = new ListResponse();
    DataChannelFilter f1 = new MockDataChannelFilter() {

        @Override
        public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
            return r1;
        }
    };
    DataChannelFilter f2 = new MockDataChannelFilter() {

        @Override
        public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
            return r2;
        }
    };
    domain.filters.add(f1);
    domain.filters.add(f2);
    SelectQuery query = new SelectQuery(Artist.class);
    QueryResponse response = domain.onQuery(context, query);
    assertSame(r2, response);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) ListResponse(org.apache.cayenne.util.ListResponse) SelectQuery(org.apache.cayenne.query.SelectQuery) Query(org.apache.cayenne.query.Query) QueryResponse(org.apache.cayenne.QueryResponse) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilterChain(org.apache.cayenne.DataChannelFilterChain) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 15 with Query

use of org.apache.cayenne.query.Query in project cayenne by apache.

the class DataNodeQueriesIT method testPerfomQueriesSelectingSQLTemplateAlias.

@Test
public void testPerfomQueriesSelectingSQLTemplateAlias() throws Exception {
    createFourArtists();
    String template = "SELECT #result('ARTIST_ID' 'int' 'A') FROM ARTIST ORDER BY ARTIST_ID";
    Query query = new SQLTemplate(Object.class, template);
    MockOperationObserver observer = new MockOperationObserver();
    node.performQueries(Collections.singletonList(query), observer);
    List<DataRow> data = observer.rowsForQuery(query);
    assertEquals(4, data.size());
    DataRow row = data.get(2);
    assertEquals(1, row.size());
    assertEquals(201, row.get("A"));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Query(org.apache.cayenne.query.Query) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Aggregations

Query (org.apache.cayenne.query.Query)43 Test (org.junit.Test)25 SelectQuery (org.apache.cayenne.query.SelectQuery)15 SQLTemplate (org.apache.cayenne.query.SQLTemplate)14 ArrayList (java.util.ArrayList)10 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)8 DataRow (org.apache.cayenne.DataRow)6 QueryResponse (org.apache.cayenne.QueryResponse)6 MockQuery (org.apache.cayenne.query.MockQuery)6 List (java.util.List)5 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 ObjectContext (org.apache.cayenne.ObjectContext)4 ObjectId (org.apache.cayenne.ObjectId)4 Persistent (org.apache.cayenne.Persistent)4 MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)4 Map (java.util.Map)3 DbEntity (org.apache.cayenne.map.DbEntity)3 EntityResolver (org.apache.cayenne.map.EntityResolver)3