use of org.apache.cayenne.query.SQLAction in project cayenne by apache.
the class SQLTemplateActionIT method testSelectSQLTimestamp.
@Test
public void testSelectSQLTimestamp() throws Exception {
createFourArtists();
String templateString = "SELECT #result('DATE_OF_BIRTH' 'java.sql.Timestamp' 'DOB') " + "FROM ARTIST WHERE ARTIST_ID = #bind($id)";
SQLTemplate template = new SQLTemplate(Object.class, templateString);
sqlTemplateCustomizer.updateSQLTemplate(template);
Map<String, Object> bindings = new HashMap<>();
bindings.put("id", 201);
template.setParameters(bindings);
SQLAction plan = adapter.getAction(template, node);
MockOperationObserver observer = new MockOperationObserver();
try (Connection c = dataSourceFactory.getSharedDataSource().getConnection()) {
plan.performAction(c, observer);
}
List<DataRow> rows = observer.rowsForQuery(template);
assertNotNull(rows);
assertEquals(1, rows.size());
DataRow row = rows.get(0);
assertNotNull(row.get("DOB"));
// Sybase returns a Timestamp subclass... so can't test equality
assertTrue(java.sql.Timestamp.class.isAssignableFrom(row.get("DOB").getClass()));
}
use of org.apache.cayenne.query.SQLAction in project cayenne by apache.
the class SQLTemplateActionIT method testExecuteUpdateNoParameters.
@Test
public void testExecuteUpdateNoParameters() throws Exception {
createFourArtists();
SQLTemplate template = new SQLTemplate(Object.class, "delete from ARTIST where ARTIST_NAME like 'a%'");
SQLAction action = adapter.getAction(template, node);
try (Connection c = dataSourceFactory.getSharedDataSource().getConnection()) {
MockOperationObserver observer = new MockOperationObserver();
action.performAction(c, observer);
int[] batches = observer.countsForQuery(template);
assertNotNull(batches);
assertEquals(1, batches.length);
assertEquals(4, batches[0]);
}
}
use of org.apache.cayenne.query.SQLAction in project cayenne by apache.
the class DataNodeQueryAction method runQuery.
public void runQuery(Connection connection, final Query originalQuery) throws SQLException, Exception {
// wrap to ensure that the result is mapped back to the original query, even if
// the underlying SQLAction uses query substitute...
OperationObserver wrapper = new OperationObserver() {
@Override
public void nextBatchCount(Query query, int[] resultCount) {
observer.nextBatchCount(originalQuery, resultCount);
}
@Override
public void nextCount(Query query, int resultCount) {
observer.nextCount(originalQuery, resultCount);
}
@Override
public void nextRows(Query query, List<?> dataRows) {
observer.nextRows(originalQuery, dataRows);
}
@Override
public void nextRows(Query q, ResultIterator it) {
observer.nextRows(originalQuery, it);
}
@Override
public void nextGeneratedRows(Query query, ResultIterator keys, ObjectId idToUpdate) {
observer.nextGeneratedRows(originalQuery, keys, idToUpdate);
}
@Override
public void nextGlobalException(Exception ex) {
observer.nextGlobalException(ex);
}
@Override
public void nextQueryException(Query query, Exception ex) {
observer.nextQueryException(originalQuery, ex);
}
@Override
public boolean isIteratedResult() {
return observer.isIteratedResult();
}
};
SQLAction action = node.getAdapter().getAction(originalQuery, node);
action.performAction(connection, wrapper);
}
Aggregations