MessageDao { @Transactional @SelectDataSource(storage = Storage.SCHEDULER) public int deleteInBatch(List<SmIdAndTaskIdPair> messageIdsToDelete) { StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("delete from ScheduledMessage where (stateMachineId,taskId) in ("); messageIdsToDelete.forEach(smIdAndTaskIdPair -> { queryBuilder.append("(\'") .append(smIdAndTaskIdPair.getSmId()) .append("\',\'").append(smIdAndTaskIdPair.getTaskId()) .append("\'),"); }); queryBuilder.setCharAt(queryBuilder.length() - 1, ')'); final Query deleteQuery = currentSession().createQuery(queryBuilder.toString()); return deleteQuery.executeUpdate(); } @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 testDeleteInBatch() 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)); messageDao.deleteInBatch(Arrays.asList(new SmIdAndTaskIdPair("sample-state-machine-uuid", 1l), new SmIdAndTaskIdPair("sample-state-machine-uuid", 2l))); assertThat(messageDao.retrieveOldest(0, 10)).containsExactly(new ScheduledMessage(3l, "sample-state-machine-uuid", 4l)); }