private void commitAsRoot() { try { try { changePhase(Phase.PREPARE_COMMIT, Phase.COMMIT); } catch (Exception e) { setRollbackCause(e); changePhase(Phase.ROLLBACK); throw e; } if (phase() == Phase.COMMIT) { changePhase(Phase.AFTER_COMMIT); } } finally { changePhase(Phase.CLEANUP, Phase.CLOSED); } }
private void commitAsNested() { try { changePhase(Phase.PREPARE_COMMIT, Phase.COMMIT); delegateAfterCommitToParent(this); parentUnitOfWork.onRollback(u -> changePhase(Phase.ROLLBACK)); } catch (Exception e) { setRollbackCause(e); changePhase(Phase.ROLLBACK); throw e; } }
private void delegateAfterCommitToParent(UnitOfWork<?> uow) { Optional<UnitOfWork<?>> parent = uow.parent(); if (parent.isPresent()) { parent.get().afterCommit(this::delegateAfterCommitToParent); } else { changePhase(Phase.AFTER_COMMIT); } }
@Override public void start() { if (logger.isDebugEnabled()) { logger.debug("Starting Unit Of Work"); } Assert.state(Phase.NOT_STARTED.equals(phase()), () -> "UnitOfWork is already started"); rolledBack = false; onRollback(u -> rolledBack = true); CurrentUnitOfWork.ifStarted(parent -> { // we're nesting. this.parentUnitOfWork = parent; root().onCleanup(r -> changePhase(Phase.CLEANUP, Phase.CLOSED)); }); changePhase(Phase.STARTED); CurrentUnitOfWork.set(this); }
@Override public void rollback(Throwable cause) { if (logger.isDebugEnabled()) { logger.debug("Rolling back Unit Of Work.", cause); } Assert.state(isActive() && phase().isBefore(Phase.ROLLBACK), () -> String.format("The UnitOfWork is in an incompatible phase: %s", phase())); Assert.state(isCurrent(), () -> "The UnitOfWork is not the current Unit of Work"); try { setRollbackCause(cause); changePhase(Phase.ROLLBACK); if (isRoot()) { changePhase(Phase.CLEANUP, Phase.CLOSED); } } finally { CurrentUnitOfWork.clear(this); } }
private void commitAsRoot() { try { try { changePhase(Phase.PREPARE_COMMIT, Phase.COMMIT); } catch (Exception e) { setRollbackCause(e); changePhase(Phase.ROLLBACK); throw e; } if (phase() == Phase.COMMIT) { changePhase(Phase.AFTER_COMMIT); } } finally { changePhase(Phase.CLEANUP, Phase.CLOSED); } }
private void commitAsRoot() { try { try { changePhase(Phase.PREPARE_COMMIT, Phase.COMMIT); } catch (Exception e) { setRollbackCause(e); changePhase(Phase.ROLLBACK); throw e; } if (phase() == Phase.COMMIT) { changePhase(Phase.AFTER_COMMIT); } } finally { changePhase(Phase.CLEANUP, Phase.CLOSED); } }
private void commitAsNested() { try { changePhase(Phase.PREPARE_COMMIT, Phase.COMMIT); delegateAfterCommitToParent(this); parentUnitOfWork.onRollback(u -> changePhase(Phase.ROLLBACK)); } catch (Exception e) { setRollbackCause(e); changePhase(Phase.ROLLBACK); throw e; } }
private void commitAsNested() { try { changePhase(Phase.PREPARE_COMMIT, Phase.COMMIT); delegateAfterCommitToParent(this); parentUnitOfWork.onRollback(u -> changePhase(Phase.ROLLBACK)); } catch (Exception e) { setRollbackCause(e); changePhase(Phase.ROLLBACK); throw e; } }
private void delegateAfterCommitToParent(UnitOfWork<?> uow) { Optional<UnitOfWork<?>> parent = uow.parent(); if (parent.isPresent()) { parent.get().afterCommit(this::delegateAfterCommitToParent); } else { changePhase(Phase.AFTER_COMMIT); } }
private void delegateAfterCommitToParent(UnitOfWork<?> uow) { Optional<UnitOfWork<?>> parent = uow.parent(); if (parent.isPresent()) { parent.get().afterCommit(this::delegateAfterCommitToParent); } else { changePhase(Phase.AFTER_COMMIT); } }
@Override public void start() { if (logger.isDebugEnabled()) { logger.debug("Starting Unit Of Work"); } Assert.state(Phase.NOT_STARTED.equals(phase()), () -> "UnitOfWork is already started"); rolledBack = false; onRollback(u -> rolledBack = true); CurrentUnitOfWork.ifStarted(parent -> { // we're nesting. this.parentUnitOfWork = parent; root().onCleanup(r -> changePhase(Phase.CLEANUP, Phase.CLOSED)); }); changePhase(Phase.STARTED); CurrentUnitOfWork.set(this); }
@Override public void start() { if (logger.isDebugEnabled()) { logger.debug("Starting Unit Of Work"); } Assert.state(Phase.NOT_STARTED.equals(phase()), () -> "UnitOfWork is already started"); rolledBack = false; onRollback(u -> rolledBack = true); CurrentUnitOfWork.ifStarted(parent -> { // we're nesting. this.parentUnitOfWork = parent; root().onCleanup(r -> changePhase(Phase.CLEANUP, Phase.CLOSED)); }); changePhase(Phase.STARTED); CurrentUnitOfWork.set(this); }
@Override public void rollback(Throwable cause) { if (logger.isDebugEnabled()) { logger.debug("Rolling back Unit Of Work.", cause); } Assert.state(isActive() && phase().isBefore(Phase.ROLLBACK), () -> String.format("The UnitOfWork is in an incompatible phase: %s", phase())); Assert.state(isCurrent(), () -> "The UnitOfWork is not the current Unit of Work"); try { setRollbackCause(cause); changePhase(Phase.ROLLBACK); if (isRoot()) { changePhase(Phase.CLEANUP, Phase.CLOSED); } } finally { CurrentUnitOfWork.clear(this); } }
@Override public void rollback(Throwable cause) { if (logger.isDebugEnabled()) { logger.debug("Rolling back Unit Of Work.", cause); } Assert.state(isActive() && phase().isBefore(Phase.ROLLBACK), () -> String.format("The UnitOfWork is in an incompatible phase: %s", phase())); Assert.state(isCurrent(), () -> "The UnitOfWork is not the current Unit of Work"); try { setRollbackCause(cause); changePhase(Phase.ROLLBACK); if (isRoot()) { changePhase(Phase.CLEANUP, Phase.CLOSED); } } finally { CurrentUnitOfWork.clear(this); } }