use of org.hisp.dhis.commons.util.SqlHelper in project dhis2-core by dhis2.
the class DefaultSqlViewService method getSqlForQuery.
private String getSqlForQuery(Grid grid, SqlView sqlView, Map<String, String> criteria, Map<String, String> variables, List<String> filters, List<String> fields) {
boolean hasCriteria = criteria != null && !criteria.isEmpty();
boolean hasFilter = filters != null && !filters.isEmpty();
String sql = SqlViewUtils.substituteSqlVariables(sqlView.getSqlQuery(), variables);
if (hasCriteria || hasFilter) {
sql = SqlViewUtils.removeQuerySeparator(sql);
String outerSql = "select " + QueryUtils.parseSelectFields(fields) + " from " + "(" + sql + ") as qry ";
SqlHelper sqlHelper = new SqlHelper();
if (hasCriteria) {
outerSql += getCriteriaSqlClause(criteria, sqlHelper);
}
if (hasFilter) {
outerSql += parseFilters(filters, sqlHelper);
}
sql = outerSql;
}
return sql;
}
use of org.hisp.dhis.commons.util.SqlHelper in project dhis2-core by dhis2.
the class JdbcAnalyticsManager method getPartitionSql.
/**
* If preAggregationMeasureCriteria is specified, generates a query which
* provides a filtered view of the data according to the criteria .If not,
* returns the full view of the partition.
*/
private String getPartitionSql(DataQueryParams params, String partition) {
if (params.isDataType(DataType.NUMERIC) && !params.getPreAggregateMeasureCriteria().isEmpty()) {
SqlHelper sqlHelper = new SqlHelper();
String sql = "";
sql += "(select * from " + partition + " ";
for (MeasureFilter filter : params.getPreAggregateMeasureCriteria().keySet()) {
Double criterion = params.getPreAggregateMeasureCriteria().get(filter);
sql += sqlHelper.whereAnd() + " value " + OPERATOR_SQL_MAP.get(filter) + " " + criterion + " ";
}
sql += ") as " + partition;
return sql;
} else {
return partition;
}
}
Aggregations