@Test public void shouldOnlyAllowOneHandleToObtainLockAtOneTime() throws InterruptedException { final Handle handleOne = JDBI_RULE.DBI.open(); final Handle handleTwo = JDBI_RULE.DBI.open(); final Handle handleThree = JDBI_RULE.DBI.open(); assertTrue(attemptLock(handleOne, "4445")); assertFalse(attemptLock(handleTwo, "4445")); assertFalse(attemptLock(handleTwo, "4445")); assertFalse(attemptLock(handleThree, "4445")); assertFalse(attemptLock(handleThree, "4445")); unlock(handleOne, "4445"); assertTrue(attemptLock(handleTwo, "4445")); assertFalse(attemptLock(handleThree, "4445")); assertFalse(attemptLock(handleThree, "4445")); unlock(handleTwo, "4445"); assertTrue(attemptLock(handleThree, "4445")); assertFalse(attemptLock(handleOne, "4445")); assertFalse(attemptLock(handleOne, "4445")); }
public boolean unlock(String smId) { return getHandle().inTransaction((conn, status) -> { final Update statement = conn.createStatement("DO RELEASE_LOCK(:lock);"); statement.bind("lock", PURE_FSM_LOCK_PREFIX + smId); statement.execute(); return true; }); }
StateMachineDao implements GetHandle { public boolean unlock(String smId) { return getHandle().inTransaction((conn, status) -> { final Update statement = conn.createStatement("DO RELEASE_LOCK(:lock);"); statement.bind("lock", PURE_FSM_LOCK_PREFIX + smId); statement.execute(); return true; }); } }
StateMachineDao implements GetHandle { public boolean unlock(String smId) { return getHandle().inTransaction((conn, status) -> { final Update statement = conn.createStatement("DO RELEASE_LOCK(:lock);"); statement.bind("lock", PURE_FSM_LOCK_PREFIX + smId); statement.execute(); return true; }); }  }
StateMachineDao implements GetHandle { public boolean unlock(String smId) { return getHandle().inTransaction((conn, status) -> { final Update statement = conn.createStatement("DO RELEASE_LOCK(:lock);"); statement.bind("lock", PURE_FSM_LOCK_PREFIX + smId); statement.execute(); return true; }); }  Set<String> getAllIds(); String getNextId(); void insertStateMachineData(String smId, Transition transition); void updateStateMachineData(String smId, Transition transition); boolean removeStateMachineData(String smId); boolean lock(String smId, long timeout); boolean unlock(String smId); Transition getStateMachineData(String smId); }
StateMachineDao implements GetHandle { public boolean unlock(String smId) { return getHandle().inTransaction((conn, status) -> { final Update statement = conn.createStatement("DO RELEASE_LOCK(:lock);"); statement.bind("lock", PURE_FSM_LOCK_PREFIX + smId); statement.execute(); return true; }); }  Set<String> getAllIds(); String getNextId(); void insertStateMachineData(String smId, Transition transition); void updateStateMachineData(String smId, Transition transition); boolean removeStateMachineData(String smId); boolean lock(String smId, long timeout); boolean unlock(String smId); Transition getStateMachineData(String smId);  }