/** * Initiates the rollback of this Unit of Work, invoking all registered rollback ({@link #onRollback(Consumer) and * clean-up handlers {@link #onCleanup(Consumer)}} respectively. Finally, the Unit of Work is unregistered from the * {@link CurrentUnitOfWork}. * <p/> * If the rollback is a result of an exception, consider using {@link #rollback(Throwable)} instead. * * @throws IllegalStateException if the Unit of Work is not in a compatible phase. */ default void rollback() { rollback(null); }
@After public void tearDown() { scheduledThreadPool.shutdownNow(); while (CurrentUnitOfWork.isStarted()) { CurrentUnitOfWork.get().rollback(); } }
/** * Attach a transaction to this Unit of Work, using the given {@code transactionManager}. The transaction will be * managed in the lifecycle of this Unit of Work. Failure to start a transaction will cause this Unit of Work * to be rolled back. * * @param transactionManager The Transaction Manager to create, commit and/or rollback the transaction */ default void attachTransaction(TransactionManager transactionManager) { try { Transaction transaction = transactionManager.startTransaction(); onCommit(u -> transaction.commit()); onRollback(u -> transaction.rollback()); } catch (Throwable t) { rollback(t); throw t; } }
private void detectIllegalStateChanges(MatchAllFieldFilter fieldFilter, Aggregate<T> workingAggregate) { logger.debug("Starting separate Unit of Work for the purpose of checking illegal state changes in Aggregate"); if (aggregateIdentifier != null && workingAggregate != null && reportIllegalStateChange) { UnitOfWork<?> uow = DefaultUnitOfWork.startAndGet(null); try { Aggregate<T> aggregate2 = repository.delegate.load(aggregateIdentifier); if (workingAggregate.isDeleted()) { throw new AxonAssertionError("The working aggregate was considered deleted, " + "but the Repository still contains a non-deleted copy of " + "the aggregate. Make sure the aggregate explicitly marks " + "itself as deleted in an EventHandler."); } assertValidWorkingAggregateState(aggregate2, fieldFilter, workingAggregate); } catch (AggregateNotFoundException notFound) { if (!workingAggregate.isDeleted()) { throw new AxonAssertionError("The working aggregate was not considered deleted, " //NOSONAR + "but the Repository cannot recover the state of the " + "aggregate, as it is considered deleted there."); } } catch (Exception e) { throw new FixtureExecutionException("An Exception occurred while reconstructing the Aggregate from " + "given and published events. This may be an indication " + "that the aggregate cannot be recreated from its events.", e); } finally { // rollback to prevent changes bing pushed to event store uow.rollback(); } } }
@After public void tearDown() { eventProcessor.shutDown(); while (CurrentUnitOfWork.isStarted()) { CurrentUnitOfWork.get().rollback(); } }
/** * Initiates the rollback of this Unit of Work, invoking all registered rollback ({@link #onRollback(Consumer) and * clean-up handlers {@link #onCleanup(Consumer)}} respectively. Finally, the Unit of Work is unregistered from the * {@link CurrentUnitOfWork}. * <p/> * If the rollback is a result of an exception, consider using {@link #rollback(Throwable)} instead. * * @throws IllegalStateException if the Unit of Work is not in a compatible phase. */ default void rollback() { rollback(null); }
/** * Initiates the rollback of this Unit of Work, invoking all registered rollback ({@link #onRollback(Consumer) and * clean-up handlers {@link #onCleanup(Consumer)}} respectively. Finally, the Unit of Work is unregistered from the * {@link CurrentUnitOfWork}. * <p/> * If the rollback is a result of an exception, consider using {@link #rollback(Throwable)} instead. * * @throws IllegalStateException if the Unit of Work is not in a compatible phase. */ default void rollback() { rollback(null); }
/** * Attach a transaction to this Unit of Work, using the given {@code transactionManager}. The transaction will be * managed in the lifecycle of this Unit of Work. Failure to start a transaction will cause this Unit of Work * to be rolled back. * * @param transactionManager The Transaction Manager to create, commit and/or rollback the transaction */ default void attachTransaction(TransactionManager transactionManager) { try { Transaction transaction = transactionManager.startTransaction(); onCommit(u -> transaction.commit()); onRollback(u -> transaction.rollback()); } catch (Throwable t) { rollback(t); throw t; } }
/** * Attach a transaction to this Unit of Work, using the given {@code transactionManager}. The transaction will be * managed in the lifecycle of this Unit of Work. Failure to start a transaction will cause this Unit of Work * to be rolled back. * * @param transactionManager The Transaction Manager to create, commit and/or rollback the transaction */ default void attachTransaction(TransactionManager transactionManager) { try { Transaction transaction = transactionManager.startTransaction(); onCommit(u -> transaction.commit()); onRollback(u -> transaction.rollback()); } catch (Throwable t) { rollback(t); throw t; } }