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());
}
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);
}
}
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));
}
}
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);
}
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"));
}
Aggregations