@Test public void assertFindJobRegisterStatisticsWhenTableIsEmpty() { assertThat(repository.findJobRegisterStatistics(new Date()).size(), is(0)); }
public List<JobRegisterStatistics> findJobRegisterStatistics(final Date from) { List<JobRegisterStatistics> result = new LinkedList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s WHERE statistics_time >= '%s' order by id ASC", TABLE_JOB_REGISTER_STATISTICS, formatter.format(from)); try ( Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery() ) { while (resultSet.next()) { JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime())); result.add(jobRegisterStatistics); } } catch (final SQLException ex) { log.error("Fetch jobRegisterStatistics from DB error:", ex); } return result; }
StatisticRdbRepository { public List<JobRegisterStatistics> findJobRegisterStatistics(final Date from) { List<JobRegisterStatistics> result = new LinkedList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s WHERE statistics_time >= '%s' order by id ASC", TABLE_JOB_REGISTER_STATISTICS, formatter.format(from)); try ( Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery() ) { while (resultSet.next()) { JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime())); result.add(jobRegisterStatistics); } } catch (final SQLException ex) { log.error("Fetch jobRegisterStatistics from DB error:", ex); } return result; } }
StatisticRdbRepository { public List<JobRegisterStatistics> findJobRegisterStatistics(final Date from) { List<JobRegisterStatistics> result = new LinkedList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s WHERE statistics_time >= '%s' order by id ASC", TABLE_JOB_REGISTER_STATISTICS, formatter.format(from)); try ( Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery() ) { while (resultSet.next()) { JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime())); result.add(jobRegisterStatistics); } } catch (final SQLException ex) { log.error("Fetch jobRegisterStatistics from DB error:", ex); } return result; } StatisticRdbRepository(final DataSource dataSource); }
StatisticRdbRepository { public List<JobRegisterStatistics> findJobRegisterStatistics(final Date from) { List<JobRegisterStatistics> result = new LinkedList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s WHERE statistics_time >= '%s' order by id ASC", TABLE_JOB_REGISTER_STATISTICS, formatter.format(from)); try ( Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery() ) { while (resultSet.next()) { JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime())); result.add(jobRegisterStatistics); } } catch (final SQLException ex) { log.error("Fetch jobRegisterStatistics from DB error:", ex); } return result; } StatisticRdbRepository(final DataSource dataSource); boolean add(final TaskResultStatistics taskResultStatistics); boolean add(final TaskRunningStatistics taskRunningStatistics); boolean add(final JobRunningStatistics jobRunningStatistics); boolean add(final JobRegisterStatistics jobRegisterStatistics); List<TaskResultStatistics> findTaskResultStatistics(final Date from, final StatisticInterval statisticInterval); TaskResultStatistics getSummedTaskResultStatistics(final Date from, final StatisticInterval statisticInterval); Optional<TaskResultStatistics> findLatestTaskResultStatistics(final StatisticInterval statisticInterval); List<TaskRunningStatistics> findTaskRunningStatistics(final Date from); List<JobRunningStatistics> findJobRunningStatistics(final Date from); Optional<TaskRunningStatistics> findLatestTaskRunningStatistics(); Optional<JobRunningStatistics> findLatestJobRunningStatistics(); List<JobRegisterStatistics> findJobRegisterStatistics(final Date from); Optional<JobRegisterStatistics> findLatestJobRegisterStatistics(); }
StatisticRdbRepository { public List<JobRegisterStatistics> findJobRegisterStatistics(final Date from) { List<JobRegisterStatistics> result = new LinkedList<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sql = String.format("SELECT id, registered_count, statistics_time, creation_time FROM %s WHERE statistics_time >= '%s' order by id ASC", TABLE_JOB_REGISTER_STATISTICS, formatter.format(from)); try ( Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(sql); ResultSet resultSet = preparedStatement.executeQuery() ) { while (resultSet.next()) { JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(resultSet.getLong(1), resultSet.getInt(2), new Date(resultSet.getTimestamp(3).getTime()), new Date(resultSet.getTimestamp(4).getTime())); result.add(jobRegisterStatistics); } } catch (final SQLException ex) { log.error("Fetch jobRegisterStatistics from DB error:", ex); } return result; } StatisticRdbRepository(final DataSource dataSource); boolean add(final TaskResultStatistics taskResultStatistics); boolean add(final TaskRunningStatistics taskRunningStatistics); boolean add(final JobRunningStatistics jobRunningStatistics); boolean add(final JobRegisterStatistics jobRegisterStatistics); List<TaskResultStatistics> findTaskResultStatistics(final Date from, final StatisticInterval statisticInterval); TaskResultStatistics getSummedTaskResultStatistics(final Date from, final StatisticInterval statisticInterval); Optional<TaskResultStatistics> findLatestTaskResultStatistics(final StatisticInterval statisticInterval); List<TaskRunningStatistics> findTaskRunningStatistics(final Date from); List<JobRunningStatistics> findJobRunningStatistics(final Date from); Optional<TaskRunningStatistics> findLatestTaskRunningStatistics(); Optional<JobRunningStatistics> findLatestJobRunningStatistics(); List<JobRegisterStatistics> findJobRegisterStatistics(final Date from); Optional<JobRegisterStatistics> findLatestJobRegisterStatistics();  }