Search in sources :

Example 1 with QueryRuntimeException

use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.

the class AbstractJdbcEventAnalyticsManager method getAggregatedEventData.

public Grid getAggregatedEventData(EventQueryParams params, Grid grid, int maxLimit) {
    String countClause = getAggregateClause(params);
    String sql = TextUtils.removeLastComma("select " + countClause + " as value," + StringUtils.join(getSelectColumns(params), ",") + " ");
    // ---------------------------------------------------------------------
    // Criteria
    // ---------------------------------------------------------------------
    sql += getFromClause(params);
    sql += getWhereClause(params);
    // ---------------------------------------------------------------------
    // Group by
    // ---------------------------------------------------------------------
    List<String> selectColumnNames = getGroupByColumnNames(params);
    if (selectColumnNames.size() > 0) {
        sql += "group by " + StringUtils.join(selectColumnNames, ",") + " ";
    }
    if (params.hasSortOrder()) {
        sql += "order by value " + params.getSortOrder().toString().toLowerCase() + " ";
    }
    if (params.hasLimit()) {
        sql += "limit " + params.getLimit();
    } else if (maxLimit > 0) {
        sql += "limit " + (maxLimit + 1);
    }
    try {
        if (params.analyzeOnly()) {
            executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
        } else {
            getAggregatedEventData(grid, params, sql);
        }
    } catch (BadSqlGrammarException ex) {
        log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
    } catch (DataAccessResourceFailureException ex) {
        log.warn(ErrorCode.E7131.getMessage(), ex);
        throw new QueryRuntimeException(ErrorCode.E7131, ex);
    }
    return grid;
}
Also used : BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) QueryRuntimeException(org.hisp.dhis.common.QueryRuntimeException)

Example 2 with QueryRuntimeException

use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.

the class JdbcEventAnalyticsManager method getEventCount.

@Override
public long getEventCount(EventQueryParams params) {
    String sql = "select count(psi) ";
    sql += getFromClause(params);
    sql += getWhereClause(params);
    long count = 0;
    try {
        log.debug("Analytics event count SQL: " + sql);
        if (params.analyzeOnly()) {
            executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
        } else {
            count = jdbcTemplate.queryForObject(sql, Long.class);
        }
    } catch (BadSqlGrammarException ex) {
        log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
    } catch (DataAccessResourceFailureException ex) {
        log.warn(E7131.getMessage(), ex);
        throw new QueryRuntimeException(E7131, ex);
    } catch (DataIntegrityViolationException ex) {
        log.warn(E7132.getMessage(), ex);
        throw new QueryRuntimeException(E7132, ex);
    }
    return count;
}
Also used : BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) QueryRuntimeException(org.hisp.dhis.common.QueryRuntimeException) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 3 with QueryRuntimeException

use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.

the class JdbcAnalyticsManager method getAggregatedDataValues.

// -------------------------------------------------------------------------
// AnalyticsManager implementation
// -------------------------------------------------------------------------
@Override
@Async
public Future<Map<String, Object>> getAggregatedDataValues(DataQueryParams params, AnalyticsTableType tableType, int maxLimit) {
    assertQuery(params);
    try {
        ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = params.getDataPeriodAggregationPeriodMap();
        if (params.isDisaggregation() && params.hasDataPeriodType()) {
            params = DataQueryParams.newBuilder(params).withDataPeriodsForAggregationPeriods(dataPeriodAggregationPeriodMap).build();
            params = queryPlanner.assignPartitionsFromQueryPeriods(params, tableType);
        }
        String sql = getSelectClause(params);
        sql += getFromClause(params);
        sql += getWhereClause(params, tableType);
        sql += getGroupByClause(params);
        if (params.hasMeasureCriteria() && params.isDataType(DataType.NUMERIC)) {
            sql += getMeasureCriteriaSql(params);
        }
        log.debug(sql);
        if (params.analyzeOnly()) {
            executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
            return new AsyncResult<>(Maps.newHashMap());
        }
        Map<String, Object> map;
        try {
            map = getKeyValueMap(params, sql, maxLimit);
        } catch (BadSqlGrammarException ex) {
            log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
            return new AsyncResult<>(Maps.newHashMap());
        }
        replaceDataPeriodsWithAggregationPeriods(map, params, dataPeriodAggregationPeriodMap);
        return new AsyncResult<>(map);
    } catch (DataAccessResourceFailureException ex) {
        log.warn(ErrorCode.E7131.getMessage(), ex);
        throw new QueryRuntimeException(ErrorCode.E7131, ex);
    } catch (RuntimeException ex) {
        log.error(DebugUtils.getStackTrace(ex));
        throw ex;
    }
}
Also used : BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) QueryRuntimeException(org.hisp.dhis.common.QueryRuntimeException) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) QueryRuntimeException(org.hisp.dhis.common.QueryRuntimeException) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) Async(org.springframework.scheduling.annotation.Async)

Example 4 with QueryRuntimeException

use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.

the class JdbcEnrollmentAnalyticsManager method getEnrollmentCount.

@Override
public long getEnrollmentCount(EventQueryParams params) {
    String sql = "select count(pi) ";
    sql += getFromClause(params);
    sql += getWhereClause(params);
    long count = 0;
    try {
        log.debug("Analytics enrollment count SQL: " + sql);
        if (params.analyzeOnly()) {
            executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
        } else {
            count = jdbcTemplate.queryForObject(sql, Long.class);
        }
    } catch (BadSqlGrammarException ex) {
        log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
    } catch (DataAccessResourceFailureException ex) {
        log.warn(ErrorCode.E7131.getMessage(), ex);
        throw new QueryRuntimeException(ErrorCode.E7131, ex);
    }
    return count;
}
Also used : BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) QueryRuntimeException(org.hisp.dhis.common.QueryRuntimeException) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString)

Aggregations

QueryRuntimeException (org.hisp.dhis.common.QueryRuntimeException)4 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)4 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)4 TextUtils.getQuotedCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString)3 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 Async (org.springframework.scheduling.annotation.Async)1 AsyncResult (org.springframework.scheduling.annotation.AsyncResult)1