MessageDao { @Transactional @SelectDataSource(storage = Storage.SCHEDULER) public List<ScheduledMessage> retrieveOldest(int offset, int rowCount) { return currentSession() .createCriteria(ScheduledMessage.class) .addOrder(Order.asc("scheduledTime")) .add(Restrictions.lt("scheduledTime", System.currentTimeMillis())) .setFirstResult(offset) .setMaxResults(rowCount) .list(); } @Inject  MessageDao(@Named("schedulerSessionFactoriesContext") SessionFactoryContext sessionFactoryContext); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) void save(ScheduledMessage scheduledMessage); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) int bulkInsertOrUpdate(List<ScheduledMessage> messages); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) Long redriverCount(); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) List<ScheduledMessage> retrieveOldest(int offset, int rowCount); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) int deleteInBatch(List<SmIdAndTaskIdPair> messageIdsToDelete); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) void delete(SmIdAndTaskIdPair smIdAndTaskIdPair);  }
@Test public void testRetrieveOldest() throws Exception { messageDao.save(new ScheduledMessage(1l, "sample-state-machine-uuid", 2l)); messageDao.save(new ScheduledMessage(2l, "sample-state-machine-uuid", 3l)); messageDao.save(new ScheduledMessage(3l, "sample-state-machine-uuid", 4l)); assertThat(messageDao.retrieveOldest(0, 1)).containsExactly(new ScheduledMessage(1l, "sample-state-machine-uuid", 2l)); assertThat(messageDao.retrieveOldest(1, 3)).hasSize(2); assertThat(messageDao.retrieveOldest(1, 3)).containsSequence(new ScheduledMessage(2l, "sample-state-machine-uuid", 3l), new ScheduledMessage(3l, "sample-state-machine-uuid", 4l)); }