JdbcTriggerImpl implements TriggerLoader { @Override public synchronized void addTrigger(final Trigger t) throws TriggerLoaderException { logger.info("Inserting trigger " + t.toString() + " into db."); final SQLTransaction<Long> insertAndGetLastID = transOperator -> { transOperator.update(ADD_TRIGGER, DateTime.now().getMillis()); transOperator.getConnection().commit(); return transOperator.getLastInsertId(); }; try { final long id = this.dbOperator.transaction(insertAndGetLastID); t.setTriggerId((int) id); updateTrigger(t); logger.info("uploaded trigger " + t.getDescription()); } catch (final SQLException ex) { logger.error("Adding Trigger " + t.getTriggerId() + " failed."); throw new TriggerLoaderException("trigger id is not properly created.", ex); } } @Inject  JdbcTriggerImpl(final DatabaseOperator databaseOperator); @Override List<Trigger> getUpdatedTriggers(final long lastUpdateTime); @Override List<Trigger> loadTriggers(); @Override void removeTrigger(final Trigger t); @Override synchronized void addTrigger(final Trigger t); @Override void updateTrigger(final Trigger t); @Override Trigger loadTrigger(final int triggerId);  }
@Test public void testAddTrigger() throws Exception { final Trigger t1 = createTrigger("testProj1", "testFlow1", "source1"); final Trigger t2 = createTrigger("testProj2", "testFlow2", "source2"); this.loader.addTrigger(t1); List<Trigger> ts = this.loader.loadTriggers(); assertTrue(ts.size() == 1); final Trigger t3 = ts.get(0); assertTrue(t3.getSource().equals("source1")); this.loader.addTrigger(t2); ts = this.loader.loadTriggers(); assertTrue(ts.size() == 2); for (final Trigger t : ts) { if (t.getTriggerId() == t2.getTriggerId()) { t.getSource().equals(t2.getSource()); } } }