use of java.sql.ResultSet in project elastic-job by dangdangdotcom.
the class JobEventRdbSearch method getJobStatusTraceEvents.
private List<JobStatusTraceEvent> getJobStatusTraceEvents(final Condition condition) {
List<JobStatusTraceEvent> result = new LinkedList<>();
try (Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = createDataPreparedStatement(conn, TABLE_JOB_STATUS_TRACE_LOG, FIELDS_JOB_STATUS_TRACE_LOG, condition);
ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
JobStatusTraceEvent jobStatusTraceEvent = new JobStatusTraceEvent(resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5), Source.valueOf(resultSet.getString(6)), ExecutionType.valueOf(resultSet.getString(7)), resultSet.getString(8), State.valueOf(resultSet.getString(9)), resultSet.getString(10), new Date(resultSet.getTimestamp(11).getTime()));
result.add(jobStatusTraceEvent);
}
} catch (final SQLException ex) {
// TODO 记录失败直接输出日志,未来可考虑配置化
log.error("Fetch JobStatusTraceEvent from DB error:", ex);
}
return result;
}
use of java.sql.ResultSet in project elastic-job by dangdangdotcom.
the class StatisticRdbRepository method findLatestTaskResultStatistics.
/**
* 获取最近一条任务运行结果统计数据.
*
* @param statisticInterval 统计时间间隔
* @return 任务运行结果统计数据对象
*/
public Optional<TaskResultStatistics> findLatestTaskResultStatistics(final StatisticInterval statisticInterval) {
TaskResultStatistics result = null;
String sql = String.format("SELECT id, success_count, failed_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1", TABLE_TASK_RESULT_STATISTICS + "_" + statisticInterval);
try (Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
result = new TaskResultStatistics(resultSet.getLong(1), resultSet.getInt(2), resultSet.getInt(3), statisticInterval, new Date(resultSet.getTimestamp(4).getTime()), new Date(resultSet.getTimestamp(5).getTime()));
}
} catch (final SQLException ex) {
// TODO 记录失败直接输出日志,未来可考虑配置化
log.error("Fetch latest taskResultStatistics from DB error:", ex);
}
return Optional.fromNullable(result);
}
use of java.sql.ResultSet in project elastic-job by dangdangdotcom.
the class StatisticRdbRepository method findLatestJobRegisterStatistics.
/**
* 获取最近一条作业注册统计数据.
*
* @return 作业注册统计数据对象
*/
public Optional<JobRegisterStatistics> findLatestJobRegisterStatistics() {
JobRegisterStatistics result = null;
String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1", TABLE_JOB_REGISTER_STATISTICS);
try (Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
result = new JobRegisterStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime()));
}
} catch (final SQLException ex) {
// TODO 记录失败直接输出日志,未来可考虑配置化
log.error("Fetch latest jobRegisterStatistics from DB error:", ex);
}
return Optional.fromNullable(result);
}
use of java.sql.ResultSet in project elastic-job by dangdangdotcom.
the class StatisticRdbRepository method getSummedTaskResultStatistics.
/**
* 获取合计后的任务运行结果统计数据.
*
* @param from 统计开始时间
* @param statisticInterval 统计时间间隔
* @return 合计后的任务运行结果统计数据对象
*/
public TaskResultStatistics getSummedTaskResultStatistics(final Date from, final StatisticInterval statisticInterval) {
TaskResultStatistics result = new TaskResultStatistics(0, 0, statisticInterval, new Date());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sql = String.format("SELECT sum(success_count), sum(failed_count) FROM %s WHERE statistics_time >= '%s'", TABLE_TASK_RESULT_STATISTICS + "_" + statisticInterval, formatter.format(from));
try (Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
result = new TaskResultStatistics(resultSet.getInt(1), resultSet.getInt(2), statisticInterval, new Date());
}
} catch (final SQLException ex) {
// TODO 记录失败直接输出日志,未来可考虑配置化
log.error("Fetch summed taskResultStatistics from DB error:", ex);
}
return result;
}
use of java.sql.ResultSet in project elastic-job by dangdangdotcom.
the class StatisticRdbRepository method findLatestJobRunningStatistics.
/**
* 获取最近一条运行中的任务统计数据.
*
* @return 运行中的任务统计数据对象
*/
public Optional<JobRunningStatistics> findLatestJobRunningStatistics() {
JobRunningStatistics result = null;
String sql = String.format("SELECT id, running_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1", TABLE_JOB_RUNNING_STATISTICS);
try (Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
result = new JobRunningStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime()));
}
} catch (final SQLException ex) {
// TODO 记录失败直接输出日志,未来可考虑配置化
log.error("Fetch latest jobRunningStatistics from DB error:", ex);
}
return Optional.fromNullable(result);
}
Aggregations