@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); } }
@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); } }
/** * Register handlers with the current Unit of Work that save or delete the given {@code aggregate} when * the Unit of Work is committed. * * @param aggregate The Aggregate to save or delete when the Unit of Work is committed */ protected void prepareForCommit(A aggregate) { if (UnitOfWork.Phase.STARTED.isBefore(CurrentUnitOfWork.get().phase())) { doCommit(aggregate); } else { CurrentUnitOfWork.get().onPrepareCommit(u -> { // If the aggregate isn't "managed" anymore, it means its state was invalidated by a rollback doCommit(aggregate); }); } }
/** * Register handlers with the current Unit of Work that save or delete the given {@code aggregate} when * the Unit of Work is committed. * * @param aggregate The Aggregate to save or delete when the Unit of Work is committed */ protected void prepareForCommit(A aggregate) { if (UnitOfWork.Phase.STARTED.isBefore(CurrentUnitOfWork.get().phase())) { doCommit(aggregate); } else { CurrentUnitOfWork.get().onPrepareCommit(u -> { // if the aggregate isn't "managed" anymore, it means its state was invalidated by a rollback doCommit(aggregate); }); } }
@Override protected void addHandler(Phase phase, Consumer<UnitOfWork<T>> handler) { Assert.state(!phase.isBefore(phase()), () -> "Cannot register a listener for phase: " + phase + " because the Unit of Work is already in a later phase: " + phase()); processingContext.addHandler(phase, handler); }
@Override protected void addHandler(Phase phase, Consumer<UnitOfWork<T>> handler) { Assert.state(!phase.isBefore(phase()), () -> "Cannot register a listener for phase: " + phase + " because the Unit of Work is already in a later phase: " + phase()); processingContext.addHandler(phase, handler); }
/** * Register handlers with the current Unit of Work that save or delete the given {@code aggregate} when * the Unit of Work is committed. * * @param aggregate The Aggregate to save or delete when the Unit of Work is committed */ protected void prepareForCommit(A aggregate) { if (UnitOfWork.Phase.STARTED.isBefore(CurrentUnitOfWork.get().phase())) { doCommit(aggregate); } else { CurrentUnitOfWork.get().onPrepareCommit(u -> { // If the aggregate isn't "managed" anymore, it means its state was invalidated by a rollback doCommit(aggregate); }); } }
@Override protected void addHandler(Phase phase, Consumer<UnitOfWork<T>> handler) { Assert.state(!phase.isBefore(phase()), () -> "Cannot register a listener for phase: " + phase + " because the Unit of Work is already in a later phase: " + phase()); processingContext.addHandler(phase, handler); }