Search in sources :

Example 1 with LogStopWatch

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

the class BaseSqlQuery method immediateQuery.

/**
 * Execute the quer
 * @return
 */
public List<T> immediateQuery() {
    LogStopWatch stopWatch = null;
    if (this.useMetrics)
        stopWatch = new LogStopWatch();
    List<T> list = this.dao.query(selectSql, selectArgs.toArray(), this.dao.getRowMapper());
    if (this.useMetrics)
        stopWatch.stop("Query: " + selectSql + " \nArgs: " + selectArgs.toString(), this.metricsThreshold);
    return list;
}
Also used : LogStopWatch(com.serotonin.log.LogStopWatch)

Example 2 with LogStopWatch

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

the class StreamableSqlQuery method count.

/**
 * Execute the Count if there is one
 */
public void count() throws IOException {
    if (countSql == null)
        return;
    LogStopWatch stopWatch = null;
    if (this.useMetrics)
        stopWatch = new LogStopWatch();
    try {
        PreparedStatement statement = this.dao.createPreparedStatement(countSql, countArgs, stream);
        try {
            ResultSet rs = statement.executeQuery();
            RowMapper<Long> mapper = SingleColumnRowMapper.newInstance(Long.class);
            int index = 0;
            while (rs.next()) {
                this.countCallback.row(mapper.mapRow(rs, index), index);
                index++;
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            statement.cancel();
            throw e;
        } finally {
            statement.getConnection().close();
            statement.close();
        }
    } catch (Exception e) {
        LOG.error(e.getMessage() + " For Query: " + countSql, e);
        throw new IOException(e);
    }
    if (this.useMetrics)
        stopWatch.stop("Count: " + countSql + " \nArgs: " + countArgs.toString(), this.metricsThreshold);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) LogStopWatch(com.serotonin.log.LogStopWatch) IOException(java.io.IOException)

Example 3 with LogStopWatch

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

the class StreamableSqlQuery method query.

/**
 * Execute the Query
 */
public void query() throws IOException {
    LogStopWatch stopWatch = null;
    if (this.useMetrics)
        stopWatch = new LogStopWatch();
    try {
        PreparedStatement statement = this.dao.createPreparedStatement(selectSql, selectArgs, stream);
        ResultSet rs = statement.executeQuery();
        RowMapper<T> mapper = this.dao.getRowMapper();
        int index = 0;
        try {
            while (rs.next()) {
                this.selectCallback.row(mapper.mapRow(rs, index), index);
                index++;
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            statement.cancel();
            throw e;
        } finally {
            statement.getConnection().close();
            statement.close();
        }
    } catch (Exception e) {
        LOG.error(e.getMessage() + " For Query: " + selectSql, e);
        throw new IOException(e);
    }
    if (this.useMetrics)
        stopWatch.stop("Streamable Query: " + selectSql + " \nArgs: " + selectArgs.toString(), this.metricsThreshold);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) LogStopWatch(com.serotonin.log.LogStopWatch) IOException(java.io.IOException)

Example 4 with LogStopWatch

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

the class AbstractBasicDao method customizedCount.

protected int customizedCount(SelectJoinStep<Record1<Integer>> input, Condition condition) {
    Select<Record1<Integer>> select = input;
    if (condition != null) {
        select = input.where(condition);
    }
    String sql = select.getSQL();
    List<Object> arguments = select.getBindValues();
    Object[] argumentsArray = arguments.toArray(new Object[arguments.size()]);
    LogStopWatch stopWatch = null;
    if (useMetrics) {
        stopWatch = new LogStopWatch();
    }
    int count = this.ejt.queryForInt(sql, argumentsArray, 0);
    if (stopWatch != null) {
        stopWatch.stop("customizedCount(): " + this.create.renderInlined(select), metricsThreshold);
    }
    return count;
}
Also used : LogStopWatch(com.serotonin.log.LogStopWatch) Record1(org.jooq.Record1)

Example 5 with LogStopWatch

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

the class PointValueDaoMetrics method deleteOrphanedPointValueAnnotations.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.PointValueDao#deleteOrphanedPointValueAnnotations()
	 */
@Override
public void deleteOrphanedPointValueAnnotations() {
    LogStopWatch LogStopWatch = new LogStopWatch();
    dao.deleteOrphanedPointValueAnnotations();
    LogStopWatch.stop("deleteOrphanedPointValueAnnotations()", this.metricsThreshold);
    return;
}
Also used : LogStopWatch(com.serotonin.log.LogStopWatch)

Aggregations

LogStopWatch (com.serotonin.log.LogStopWatch)45 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)9 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)9 ResultSet (java.sql.ResultSet)3 LogEvent (com.serotonin.m2m2.rt.console.LogEvent)2 IOException (java.io.IOException)2 PreparedStatement (java.sql.PreparedStatement)2 Simplify (com.goebl.simplify.Simplify)1 DataPointVOPointValueTimeBookend (com.infiniteautomation.mango.rest.v2.model.pointValue.DataPointVOPointValueTimeBookend)1 ModuleNotLoadedException (com.serotonin.ModuleNotLoadedException)1 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 UserEventCache (com.serotonin.m2m2.rt.event.UserEventCache)1 LongPair (com.serotonin.m2m2.vo.pair.LongPair)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Record (org.jooq.Record)1 Record1 (org.jooq.Record1)1 DataAccessException (org.springframework.dao.DataAccessException)1 RowMapper (org.springframework.jdbc.core.RowMapper)1