/** * Check that returns {@code true} if this Unit of Work has not got a parent. * * @return {@code true} if this Unit of Work has no parent */ default boolean isRoot() { return !parent().isPresent(); }
/** * Returns the root of this Unit of Work. If this Unit of Work has no parent (see {@link #parent()}) it returns * itself, otherwise it returns the root of its parent. * * @return the root of this Unit of Work */ default UnitOfWork<?> root() { //noinspection unchecked // cast is used to remove inspection error in IDE return parent().map(UnitOfWork::root).orElse((UnitOfWork) this); }
private void delegateAfterCommitToParent(UnitOfWork<?> uow) { Optional<UnitOfWork<?>> parent = uow.parent(); if (parent.isPresent()) { parent.get().afterCommit(this::delegateAfterCommitToParent); } else { changePhase(Phase.AFTER_COMMIT); } }
/** * Returns a list of all the events staged for publication in this Unit of Work. Changing this list will * not affect the publication of events. * * @return a list of all the events staged for publication */ protected List<EventMessage<?>> queuedMessages() { if (!CurrentUnitOfWork.isStarted()) { return Collections.emptyList(); } List<EventMessage<?>> messages = new ArrayList<>(); for (UnitOfWork<?> uow = CurrentUnitOfWork.get(); uow != null; uow = uow.parent().orElse(null)) { messages.addAll(0, uow.getOrDefaultResource(eventsKey, Collections.emptyList())); } return messages; }
if (u.parent().isPresent() && !u.parent().get().phase().isAfter(PREPARE_COMMIT)) { eventsQueue(u.parent().get()).addAll(eventQueue); } else { int processedItems = eventQueue.size(); if (u.parent().isPresent() && !u.root().phase().isAfter(COMMIT)) { u.root().onCommit(w -> doWithEvents(this::commit, eventQueue)); } else { if (u.parent().isPresent() && !u.root().phase().isAfter(AFTER_COMMIT)) { u.root().afterCommit(w -> doWithEvents(this::afterCommit, eventQueue)); } else {
/** * Check that returns {@code true} if this Unit of Work has not got a parent. * * @return {@code true} if this Unit of Work has no parent */ default boolean isRoot() { return !parent().isPresent(); }
/** * Check that returns {@code true} if this Unit of Work has not got a parent. * * @return {@code true} if this Unit of Work has no parent */ default boolean isRoot() { return !parent().isPresent(); }
/** * Returns the root of this Unit of Work. If this Unit of Work has no parent (see {@link #parent()}) it returns * itself, otherwise it returns the root of its parent. * * @return the root of this Unit of Work */ default UnitOfWork<?> root() { //noinspection unchecked // cast is used to remove inspection error in IDE return parent().map(UnitOfWork::root).orElse((UnitOfWork) this); }
/** * Returns the root of this Unit of Work. If this Unit of Work has no parent (see {@link #parent()}) it returns * itself, otherwise it returns the root of its parent. * * @return the root of this Unit of Work */ default UnitOfWork<?> root() { //noinspection unchecked // cast is used to remove inspection error in IDE return parent().map(UnitOfWork::root).orElse((UnitOfWork) this); }
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); } }
/** * Returns a list of all the events staged for publication in this Unit of Work. Changing this list will * not affect the publication of events. * * @return a list of all the events staged for publication */ protected List<EventMessage<?>> queuedMessages() { if (!CurrentUnitOfWork.isStarted()) { return Collections.emptyList(); } List<EventMessage<?>> messages = new ArrayList<>(); for (UnitOfWork<?> uow = CurrentUnitOfWork.get(); uow != null; uow = uow.parent().orElse(null)) { messages.addAll(0, uow.getOrDefaultResource(eventsKey, Collections.emptyList())); } return messages; }
/** * Returns a list of all the events staged for publication in this Unit of Work. Changing this list will * not affect the publication of events. * * @return a list of all the events staged for publication */ protected List<EventMessage<?>> queuedMessages() { if (!CurrentUnitOfWork.isStarted()) { return Collections.emptyList(); } List<EventMessage<?>> messages = new ArrayList<>(); for (UnitOfWork<?> uow = CurrentUnitOfWork.get(); uow != null; uow = uow.parent().orElse(null)) { messages.addAll(0, uow.getOrDefaultResource(eventsKey, Collections.emptyList())); } return messages; }
if (u.parent().isPresent() && !u.parent().get().phase().isAfter(PREPARE_COMMIT)) { eventsQueue(u.parent().get()).addAll(eventQueue); } else { int processedItems = eventQueue.size(); if (u.parent().isPresent() && !u.root().phase().isAfter(COMMIT)) { u.root().onCommit(w -> doWithEvents(this::commit, eventQueue)); } else { if (u.parent().isPresent() && !u.root().phase().isAfter(AFTER_COMMIT)) { u.root().afterCommit(w -> doWithEvents(this::afterCommit, eventQueue)); } else {
if (u.parent().isPresent() && !u.parent().get().phase().isAfter(PREPARE_COMMIT)) { eventsQueue(u.parent().get()).addAll(eventQueue); } else { int processedItems = eventQueue.size(); if (u.parent().isPresent() && !u.root().phase().isAfter(COMMIT)) { u.root().onCommit(w -> doWithEvents(this::commit, eventQueue)); } else { if (u.parent().isPresent() && !u.root().phase().isAfter(AFTER_COMMIT)) { u.root().afterCommit(w -> doWithEvents(this::afterCommit, eventQueue)); } else {