/** * Starts a new DefaultUnitOfWork instance, registering it a CurrentUnitOfWork. This methods returns the started * UnitOfWork instance. * <p> * Note that this Unit Of Work type is not meant to be shared among different Threads. A single DefaultUnitOfWork * instance should be used exclusively by the Thread that created it. * * @param message the message that will be processed in the context of the unit of work * @return the started UnitOfWork instance */ public static <T extends Message<?>> DefaultUnitOfWork<T> startAndGet(T message) { DefaultUnitOfWork<T> uow = new DefaultUnitOfWork<>(message); uow.start(); return uow; }
@Override public <R> ResultMessage<R> executeWithResult(Callable<R> task, RollbackConfiguration rollbackConfiguration) { if (phase() == Phase.NOT_STARTED) { start();
/** * Starts a new DefaultUnitOfWork instance, registering it a CurrentUnitOfWork. This methods returns the started * UnitOfWork instance. * <p> * Note that this Unit Of Work type is not meant to be shared among different Threads. A single DefaultUnitOfWork * instance should be used exclusively by the Thread that created it. * * @param message the message that will be processed in the context of the unit of work * @return the started UnitOfWork instance */ public static <T extends Message<?>> DefaultUnitOfWork<T> startAndGet(T message) { DefaultUnitOfWork<T> uow = new DefaultUnitOfWork<>(message); uow.start(); return uow; }
/** * Starts a new DefaultUnitOfWork instance, registering it a CurrentUnitOfWork. This methods returns the started * UnitOfWork instance. * <p> * Note that this Unit Of Work type is not meant to be shared among different Threads. A single DefaultUnitOfWork * instance should be used exclusively by the Thread that created it. * * @param message the message that will be processed in the context of the unit of work * @return the started UnitOfWork instance */ public static <T extends Message<?>> DefaultUnitOfWork<T> startAndGet(T message) { DefaultUnitOfWork<T> uow = new DefaultUnitOfWork<>(message); uow.start(); return uow; }
@Override public <R> R executeWithResult(Callable<R> task, RollbackConfiguration rollbackConfiguration) throws Exception { if (phase() == Phase.NOT_STARTED) { start(); } Assert.state(phase() == Phase.STARTED, () -> String.format("The UnitOfWork has an incompatible phase: %s", phase())); R result; try { result = task.call(); } catch (Error | Exception e) { if (rollbackConfiguration.rollBackOn(e)) { rollback(e); } else { setExecutionResult(new ExecutionResult(e)); commit(); } throw e; } setExecutionResult(new ExecutionResult(result)); commit(); return result; }
@Override public <R> ResultMessage<R> executeWithResult(Callable<R> task, RollbackConfiguration rollbackConfiguration) { if (phase() == Phase.NOT_STARTED) { start();