use of org.springframework.jdbc.support.rowset.SqlRowSet in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getRectangle.
@Override
public Rectangle getRectangle(EventQueryParams params) {
String clusterField = params.getCoordinateField();
String sql = "select count(psi) as " + COL_COUNT + ", ST_Extent(" + clusterField + ") as " + COL_EXTENT + " ";
sql += getFromWhereClause(params, Lists.newArrayList("psi", clusterField));
log.debug(String.format("Analytics event count and extent SQL: %s", sql));
Rectangle rectangle = new Rectangle();
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
if (rowSet.next()) {
Object extent = rowSet.getObject(COL_EXTENT);
rectangle.setCount(rowSet.getLong(COL_COUNT));
rectangle.setExtent(extent != null ? String.valueOf(rowSet.getObject(COL_EXTENT)) : null);
}
return rectangle;
}
use of org.springframework.jdbc.support.rowset.SqlRowSet in project perun by CESNET.
the class PerunNotifObjectDaoImpl method isObjectRelation.
@Override
public boolean isObjectRelation(int templateId, Integer objectId) {
logger.debug("IsObjectRelation for templateId: {}, objectId: {}", Arrays.asList(templateId, objectId));
try {
SqlRowSet rowSet = this.getJdbcTemplate().queryForRowSet("select * from pn_regex_object where regex_id = ? AND object_id = ?", templateId, objectId);
logger.debug("Relation between templateId: {} and objectId: {}, found.", Arrays.asList(templateId, objectId));
return rowSet.next();
} catch (EmptyResultDataAccessException ex) {
//This exception signals empty row
logger.debug("Relation between templateId: {}, and objectId: {}, not found", Arrays.asList(templateId, objectId));
return false;
}
}
use of org.springframework.jdbc.support.rowset.SqlRowSet in project perun by CESNET.
the class PerunNotifRegexDaoImpl method isRegexRelation.
@Override
public boolean isRegexRelation(int templateId, Integer regexId) {
logger.debug("Trying to load relation between template: {}, and regex: {}", Arrays.asList(templateId, regexId));
SqlRowSet rowSet = this.getJdbcTemplate().queryForRowSet("select * from pn_template_regex where template_id = ? AND regex_id = ?", templateId, regexId);
return rowSet.next();
}
use of org.springframework.jdbc.support.rowset.SqlRowSet in project dhis2-core by dhis2.
the class JdbcEnrollmentAnalyticsManager method getAggregatedEventData.
private void getAggregatedEventData(Grid grid, EventQueryParams params, String sql) {
log.debug("Analytics event aggregate SQL: " + sql);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
while (rowSet.next()) {
grid.addRow();
if (params.isAggregateData()) {
if (params.hasValueDimension()) {
String itemId = params.getProgram().getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + params.getValue().getUid();
grid.addValue(itemId);
} else if (params.hasProgramIndicatorDimension()) {
grid.addValue(params.getProgramIndicator().getUid());
}
} else {
for (QueryItem queryItem : params.getItems()) {
String itemValue = rowSet.getString(queryItem.getItemName());
String gridValue = params.isCollapseDataDimensions() ? getCollapsedDataItemValue(params, queryItem, itemValue) : itemValue;
grid.addValue(gridValue);
}
}
for (DimensionalObject dimension : params.getDimensions()) {
String dimensionValue = rowSet.getString(dimension.getDimensionName());
grid.addValue(dimensionValue);
}
if (params.hasValueDimension()) {
double value = rowSet.getDouble("value");
grid.addValue(params.isSkipRounding() ? value : getRounded(value));
} else if (params.hasProgramIndicatorDimension()) {
double value = rowSet.getDouble("value");
ProgramIndicator indicator = params.getProgramIndicator();
grid.addValue(AnalyticsUtils.getRoundedValue(params, indicator.getDecimals(), value));
} else {
int value = rowSet.getInt("value");
grid.addValue(value);
}
if (params.isIncludeNumDen()) {
grid.addNullValues(3);
}
}
}
use of org.springframework.jdbc.support.rowset.SqlRowSet in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getEventClusters.
@Override
public Grid getEventClusters(EventQueryParams params, Grid grid, int maxLimit) {
String clusterField = params.getCoordinateField();
List<String> columns = Lists.newArrayList("count(psi) as count", "ST_AsText(ST_Centroid(ST_Collect(" + clusterField + "))) as center", "ST_Extent(" + clusterField + ") as extent");
columns.add(params.isIncludeClusterPoints() ? "array_to_string(array_agg(psi), ',') as points" : "case when count(psi) = 1 then array_to_string(array_agg(psi), ',') end as points");
String sql = "select " + StringUtils.join(columns, ",") + " ";
sql += getFromWhereClause(params, Lists.newArrayList("psi", clusterField));
sql += "group by ST_SnapToGrid(ST_Transform(" + clusterField + ", 3785), " + params.getClusterSize() + ") ";
log.debug(String.format("Analytics event cluster SQL: %s", sql));
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
while (rowSet.next()) {
grid.addRow().addValue(rowSet.getLong("count")).addValue(rowSet.getString("center")).addValue(rowSet.getString("extent")).addValue(rowSet.getString("points"));
}
return grid;
}
Aggregations