Search in sources :

Example 11 with SqlRowSet

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;
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) Rectangle(org.hisp.dhis.analytics.Rectangle) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString)

Example 12 with SqlRowSet

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;
    }
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 13 with SqlRowSet

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();
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet)

Example 14 with SqlRowSet

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);
        }
    }
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 15 with SqlRowSet

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;
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString)

Aggregations

SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)26 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)9 ArrayList (java.util.ArrayList)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)4 HashMap (java.util.HashMap)3 List (java.util.List)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 HashSet (java.util.HashSet)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 IdSchemes (org.hisp.dhis.common.IdSchemes)2 MapMapMap (org.hisp.dhis.common.MapMapMap)2 QueryItem (org.hisp.dhis.common.QueryItem)2 SqlHelper (org.hisp.dhis.commons.util.SqlHelper)2 TextUtils.getCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString)2 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)2 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)2 ProgramType (org.hisp.dhis.program.ProgramType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1