@Test(groups = INTEGRATION) public void testGetsEventsForListenerThatWereCreatedAfterTheLastCheckOfTheListener() throws SQLException { List<MysqlEvent> newEvents = repo.getNewEventsForListener(listener, connection); assertTrue(newEvents.isEmpty()); insertEvent(new MysqlEvent(1, TEST_TABLE_NAME, INSERT_TYPE, "{}", "{}", new Date()), connection); newEvents = repo.getNewEventsForListener(listener, connection); assertEquals(newEvents.size(), 1); }
public List<MysqlEvent> getNewEventsForListener(Listener listener, Connection connection) throws DataAccessException { verifyListenerExists(listener, connection); try ( PreparedStatement stmt = connection.prepareStatement(GET_EVENTS_FOR_LISTENER_QUERY) ) { Date lastCheckDate = listener.getLastCheck(); listenerRepo.refreshLastCheck(listener, connection); stmt.setObject(1, listener.getLastEventId()); stmt.setObject(2, lastCheckDate); stmt.setObject(3, listener.getId()); ResultSet rs = stmt.executeQuery(); List<MysqlEvent> result = Lists.newArrayList(); long maxEventId = 0l; while (rs.next()) { maxEventId = Math.max(rs.getLong(EVENT_ID_COL), maxEventId); result.add(extractEvent(rs)); } if (maxEventId > listener.getLastEventId()) { listener.setLastEventId(maxEventId); listenerRepo.update(listener, connection); } return result; } catch (SQLException e) { throw new DataAccessException("Could not get new events for listener with id:" + listener.getId(), e); } }
MysqlEventRepo { public List<MysqlEvent> getNewEventsForListener(Listener listener, Connection connection) throws DataAccessException { verifyListenerExists(listener, connection); try ( PreparedStatement stmt = connection.prepareStatement(GET_EVENTS_FOR_LISTENER_QUERY) ) { Date lastCheckDate = listener.getLastCheck(); listenerRepo.refreshLastCheck(listener, connection); stmt.setObject(1, listener.getLastEventId()); stmt.setObject(2, lastCheckDate); stmt.setObject(3, listener.getId()); ResultSet rs = stmt.executeQuery(); List<MysqlEvent> result = Lists.newArrayList(); long maxEventId = 0l; while (rs.next()) { maxEventId = Math.max(rs.getLong(EVENT_ID_COL), maxEventId); result.add(extractEvent(rs)); } if (maxEventId > listener.getLastEventId()) { listener.setLastEventId(maxEventId); listenerRepo.update(listener, connection); } return result; } catch (SQLException e) { throw new DataAccessException("Could not get new events for listener with id:" + listener.getId(), e); } } }
MysqlEventRepo { public List<MysqlEvent> getNewEventsForListener(Listener listener, Connection connection) throws DataAccessException { verifyListenerExists(listener, connection); try ( PreparedStatement stmt = connection.prepareStatement(GET_EVENTS_FOR_LISTENER_QUERY) ) { Date lastCheckDate = listener.getLastCheck(); listenerRepo.refreshLastCheck(listener, connection); stmt.setObject(1, listener.getLastEventId()); stmt.setObject(2, lastCheckDate); stmt.setObject(3, listener.getId()); ResultSet rs = stmt.executeQuery(); List<MysqlEvent> result = Lists.newArrayList(); long maxEventId = 0l; while (rs.next()) { maxEventId = Math.max(rs.getLong(EVENT_ID_COL), maxEventId); result.add(extractEvent(rs)); } if (maxEventId > listener.getLastEventId()) { listener.setLastEventId(maxEventId); listenerRepo.update(listener, connection); } return result; } catch (SQLException e) { throw new DataAccessException("Could not get new events for listener with id:" + listener.getId(), e); } } MysqlEventRepo(); }
MysqlEventRepo { public List<MysqlEvent> getNewEventsForListener(Listener listener, Connection connection) throws DataAccessException { verifyListenerExists(listener, connection); try ( PreparedStatement stmt = connection.prepareStatement(GET_EVENTS_FOR_LISTENER_QUERY) ) { Date lastCheckDate = listener.getLastCheck(); listenerRepo.refreshLastCheck(listener, connection); stmt.setObject(1, listener.getLastEventId()); stmt.setObject(2, lastCheckDate); stmt.setObject(3, listener.getId()); ResultSet rs = stmt.executeQuery(); List<MysqlEvent> result = Lists.newArrayList(); long maxEventId = 0l; while (rs.next()) { maxEventId = Math.max(rs.getLong(EVENT_ID_COL), maxEventId); result.add(extractEvent(rs)); } if (maxEventId > listener.getLastEventId()) { listener.setLastEventId(maxEventId); listenerRepo.update(listener, connection); } return result; } catch (SQLException e) { throw new DataAccessException("Could not get new events for listener with id:" + listener.getId(), e); } } MysqlEventRepo(); List<MysqlEvent> getNewEventsForListener(Listener listener, Connection connection); }
MysqlEventRepo { public List<MysqlEvent> getNewEventsForListener(Listener listener, Connection connection) throws DataAccessException { verifyListenerExists(listener, connection); try ( PreparedStatement stmt = connection.prepareStatement(GET_EVENTS_FOR_LISTENER_QUERY) ) { Date lastCheckDate = listener.getLastCheck(); listenerRepo.refreshLastCheck(listener, connection); stmt.setObject(1, listener.getLastEventId()); stmt.setObject(2, lastCheckDate); stmt.setObject(3, listener.getId()); ResultSet rs = stmt.executeQuery(); List<MysqlEvent> result = Lists.newArrayList(); long maxEventId = 0l; while (rs.next()) { maxEventId = Math.max(rs.getLong(EVENT_ID_COL), maxEventId); result.add(extractEvent(rs)); } if (maxEventId > listener.getLastEventId()) { listener.setLastEventId(maxEventId); listenerRepo.update(listener, connection); } return result; } catch (SQLException e) { throw new DataAccessException("Could not get new events for listener with id:" + listener.getId(), e); } } MysqlEventRepo(); List<MysqlEvent> getNewEventsForListener(Listener listener, Connection connection);  }