EventSchedulerDao { @Transactional @SelectDataSource(storage = Storage.SCHEDULER) public List<ScheduledEvent> retrieveOldest(int rowCount) { return currentSession() .createCriteria(ScheduledEvent.class) .addOrder(Order.asc("scheduledTime")) .setMaxResults(rowCount) .list(); } @Inject  EventSchedulerDao(@Named("schedulerSessionFactoriesContext") SessionFactoryContext sessionFactoryContext); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) void save(ScheduledEvent scheduledEvent); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) void delete(String correlationId, String eventName); @Transactional @SelectDataSource(storage = Storage.SCHEDULER) List<ScheduledEvent> retrieveOldest(int rowCount);  }
@Test public void testRetrieveOldest() throws Exception { Long triggerTime = System.currentTimeMillis()/1000; eventSchedulerDao.save(new ScheduledEvent("smCorId1", "event_name1", triggerTime, "data")); eventSchedulerDao.save(new ScheduledEvent("smCorId2", "event_name1", triggerTime+1, "data")); eventSchedulerDao.save(new ScheduledEvent("smCorId2", "event_name2", triggerTime+2, "data")); assertThat(eventSchedulerDao.retrieveOldest(1)).containsExactly(new ScheduledEvent("smCorId1", "event_name1", triggerTime, "data")); assertThat(eventSchedulerDao.retrieveOldest(3)).hasSize(3); assertThat(eventSchedulerDao.retrieveOldest(3)).containsSequence( new ScheduledEvent("smCorId1", "event_name1", triggerTime, "data"), new ScheduledEvent("smCorId2", "event_name1", triggerTime+1, "data"), new ScheduledEvent("smCorId2", "event_name2", triggerTime+2, "data")); }