@Test public void shouldBeAbleToReentrantLock() { JDBI_RULE.DBI.withHandle(handle -> { final StateMachineDao repository = handle.attach(StateMachineDao.class); assertTrue(repository.lock("999", 10)); assertTrue(repository.lock("999", 10)); assertTrue(repository.lock("999", 10)); return null; }); }
public boolean lock(String smId, long timeout) { return getHandle().inTransaction((conn, status) -> { final Query<Map<String, Object>> query = conn.createQuery("SELECT GET_LOCK(:lock, :timeout);"); query.bind("lock", PURE_FSM_LOCK_PREFIX + smId); query.bind("timeout", timeout); final Long result = (Long) query.first().values().stream().findFirst().get(); return LOCK_SUCCEEDED.equals(result); }); }
StateMachineDao implements GetHandle { public boolean lock(String smId, long timeout) { return getHandle().inTransaction((conn, status) -> { final Query<Map<String, Object>> query = conn.createQuery("SELECT GET_LOCK(:lock, :timeout);"); query.bind("lock", PURE_FSM_LOCK_PREFIX + smId); query.bind("timeout", timeout); final Long result = (Long) query.first().values().stream().findFirst().get(); return LOCK_SUCCEEDED.equals(result); }); } }
StateMachineDao implements GetHandle { public boolean lock(String smId, long timeout) { return getHandle().inTransaction((conn, status) -> { final Query<Map<String, Object>> query = conn.createQuery("SELECT GET_LOCK(:lock, :timeout);"); query.bind("lock", PURE_FSM_LOCK_PREFIX + smId); query.bind("timeout", timeout); final Long result = (Long) query.first().values().stream().findFirst().get(); return LOCK_SUCCEEDED.equals(result); }); }  }
StateMachineDao implements GetHandle { public boolean lock(String smId, long timeout) { return getHandle().inTransaction((conn, status) -> { final Query<Map<String, Object>> query = conn.createQuery("SELECT GET_LOCK(:lock, :timeout);"); query.bind("lock", PURE_FSM_LOCK_PREFIX + smId); query.bind("timeout", timeout); final Long result = (Long) query.first().values().stream().findFirst().get(); return LOCK_SUCCEEDED.equals(result); }); }  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 lock(String smId, long timeout) { return getHandle().inTransaction((conn, status) -> { final Query<Map<String, Object>> query = conn.createQuery("SELECT GET_LOCK(:lock, :timeout);"); query.bind("lock", PURE_FSM_LOCK_PREFIX + smId); query.bind("timeout", timeout); final Long result = (Long) query.first().values().stream().findFirst().get(); return LOCK_SUCCEEDED.equals(result); }); }  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);  }