Search in sources :

Example 1 with ModuleNotLoadedException

use of com.serotonin.ModuleNotLoadedException in project ma-core-public by infiniteautomation.

the class AbstractBasicDao method customizedQuery.

protected void customizedQuery(SelectJoinStep<Record> select, Condition condition, List<SortField<Object>> sort, Integer limit, Integer offset, MappedRowCallback<T> callback) {
    SelectConnectByStep<Record> afterWhere = condition == null ? select : select.where(condition);
    SelectLimitStep<Record> afterSort = sort == null ? afterWhere : afterWhere.orderBy(sort);
    Select<Record> offsetStep = afterSort;
    if (limit != null) {
        if (offset != null) {
            offsetStep = afterSort.limit(offset, limit);
        } else {
            offsetStep = afterSort.limit(limit);
        }
    }
    String sql = offsetStep.getSQL();
    List<Object> arguments = offsetStep.getBindValues();
    Object[] argumentsArray = arguments.toArray(new Object[arguments.size()]);
    LogStopWatch stopWatch = null;
    if (useMetrics) {
        stopWatch = new LogStopWatch();
    }
    // this.query(sql, argumentsArray, this.getRowMapper(), callback );
    this.query(sql, argumentsArray, new ResultSetExtractor<Void>() {

        @Override
        public Void extractData(ResultSet rs) throws SQLException, DataAccessException {
            RowMapper<T> rowMapper = getRowMapper();
            int rowNum = 0;
            while (rs.next()) {
                try {
                    callback.row(rowMapper.mapRow(rs, rowNum), rowNum);
                } catch (Exception e) {
                    if (e.getCause() instanceof ModuleNotLoadedException)
                        LOG.error(e.getCause().getMessage(), e.getCause());
                    else
                        LOG.error(e.getMessage(), e);
                } finally {
                    rowNum++;
                }
            }
            return null;
        }
    });
    if (stopWatch != null) {
        stopWatch.stop("customizedQuery(): " + this.create.renderInlined(offsetStep), metricsThreshold);
    }
}
Also used : SQLException(java.sql.SQLException) DataAccessException(org.springframework.dao.DataAccessException) ModuleNotLoadedException(com.serotonin.ModuleNotLoadedException) SQLException(java.sql.SQLException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ModuleNotLoadedException(com.serotonin.ModuleNotLoadedException) ResultSet(java.sql.ResultSet) Record(org.jooq.Record) LogStopWatch(com.serotonin.log.LogStopWatch) DataAccessException(org.springframework.dao.DataAccessException) RowMapper(org.springframework.jdbc.core.RowMapper)

Aggregations

ModuleNotLoadedException (com.serotonin.ModuleNotLoadedException)1 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 LogStopWatch (com.serotonin.log.LogStopWatch)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Record (org.jooq.Record)1 DataAccessException (org.springframework.dao.DataAccessException)1 RowMapper (org.springframework.jdbc.core.RowMapper)1