use of org.motechproject.mds.query.SqlQueryExecution in project motech by motech.
the class MdsBundleIT method verifyCustomQuery.
private void verifyCustomQuery() throws Exception {
List result = (List) service.executeQuery(new QueryExecution<List>() {
@Override
public List execute(Query query, InstanceSecurityRestriction restriction) {
query.setFilter("someString == param0");
query.declareParameters("java.lang.String param0");
return (List) QueryExecutor.execute(query, "anotherString", restriction);
}
});
assertEquals(1, result.size());
Class objClass = result.get(0).getClass();
assertInstanceOneDotOne(result.get(0), objClass);
List<String> names = (List<String>) service.executeSQLQuery(new SqlQueryExecution<List<String>>() {
@Override
public List<String> execute(Query query) {
Map<String, Integer> params = new HashMap<>();
params.put("param", 4);
return (List<String>) query.executeWithMap(params);
}
@Override
public String getSqlQuery() {
String driverName = sqlDBManager.getChosenSQLDriver();
if (driverName.equals(Constants.Config.MYSQL_DRIVER_CLASSNAME)) {
return "SELECT someString FROM MDS_FOO WHERE someInt = :param";
} else {
return "SELECT \"someString\" FROM \"MDS_FOO\" WHERE \"someInt\" = :param";
}
}
});
assertEquals(asList("notInSet"), names);
}
Aggregations