This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch 3202_executor_not_persisting_jpa in repository https://gitbox.apache.org/repos/asf/isis.git
commit 3c42a3178f8b29d7a0f136eec800aa116bea2429 Author: Andi Huber <ahu...@apache.org> AuthorDate: Sun Sep 4 08:33:05 2022 +0200 ISIS-3202: factors bookmark invalidation into separate interface --- .../isis/core/metamodel/object/Bookmarkable.java | 26 +++++++++------- .../isis/core/metamodel/object/ManagedObject.java | 3 +- ...ed.java => _ManagedObjectEntityBookmarked.java} | 9 ++---- .../object/_ManagedObjectEntityHybrid.java | 35 ++++++++++------------ .../metamodel/object/_ManagedObjectService.java | 5 ---- .../core/metamodel/object/_ManagedObjectValue.java | 5 ---- .../metamodel/object/_ManagedObjectViewmodel.java | 7 +++-- .../actionresponse/ActionResultResponseType.java | 3 +- .../widgets/linkandlabel/ActionLink.java | 5 +++- .../wicket/ui/panels/FormExecutorDefault.java | 1 + 10 files changed, 46 insertions(+), 53 deletions(-) diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/Bookmarkable.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/Bookmarkable.java index 69ce59eb42..55ecfe9f99 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/Bookmarkable.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/Bookmarkable.java @@ -21,6 +21,7 @@ package org.apache.isis.core.metamodel.object; import java.util.Optional; import org.apache.isis.applib.services.bookmark.Bookmark; +import org.apache.isis.commons.internal.base._Casts; import org.apache.isis.core.metamodel.object.ManagedObject.Specialization.BookmarkPolicy; import org.apache.isis.core.metamodel.objectmanager.ObjectManager; @@ -40,15 +41,10 @@ public interface Bookmarkable { boolean isBookmarkMemoized(); - /** - * Similar to {@link #getBookmark()}, but invalidates any memoized {@link Bookmark} - * such that the {@link Bookmark} returned is recreated, reflecting the object's current state. - * @implNote - * As this is not required, in fact not recommended for entities, - * (but might be necessary for viewmodels, when their state has changed), - * we silently ignore bookmark invalidation attempts for entities. - */ - Optional<Bookmark> getBookmarkRefreshed(); + default void invalidateBookmark() { + _Casts.castTo(BookmarkRefreshable.class, this) + .ifPresent(Bookmarkable.BookmarkRefreshable::invalidateBookmark); + } /** * Implements {@link Bookmarkable} reflecting @@ -57,8 +53,18 @@ public interface Bookmarkable { static interface NoBookmark extends Bookmarkable { @Override default boolean isBookmarkSupported() { return false; } @Override default Optional<Bookmark> getBookmark() { return Optional.empty(); } - @Override default Optional<Bookmark> getBookmarkRefreshed() { return Optional.empty(); } @Override default boolean isBookmarkMemoized() { return false; } } + static interface BookmarkRefreshable extends Bookmarkable { + /** + * Invalidates any memoized {@link Bookmark} for (lazy) recreation, + * reflecting the object's current state. + * @apiNote only makes sense in the context of mutable viewmodels + */ + @Override + void invalidateBookmark(); + + } + } diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java index 74c031850a..cb7f36fd0e 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/ManagedObject.java @@ -460,7 +460,7 @@ extends final @NonNull Object pojo, final @NonNull Optional<Bookmark> bookmarkIfKnown) { return new _ManagedObjectEntityHybrid( - new _ManagedObjectEntityAttached(spec, pojo, bookmarkIfKnown)); + new _ManagedObjectEntityBookmarked(spec, pojo, bookmarkIfKnown)); } //FIXME java-doc static ManagedObject entityDetached( @@ -632,4 +632,5 @@ extends return ManagedObject.identified(spec, pojo, bookmark); } + } diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityAttached.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityBookmarked.java similarity index 95% rename from core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityAttached.java rename to core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityBookmarked.java index 72e8633e1d..386fa2173b 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityAttached.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityBookmarked.java @@ -40,14 +40,14 @@ import lombok.extern.log4j.Log4j2; * @see ManagedObject.Specialization#ENTITY */ @Log4j2 -final class _ManagedObjectEntityAttached +final class _ManagedObjectEntityBookmarked extends _ManagedObjectSpecified implements _Refetchable { private /*final*/ @Nullable Object pojo; private final @NonNull Bookmark bookmark; - _ManagedObjectEntityAttached( + _ManagedObjectEntityBookmarked( final ObjectSpecification spec, final Object pojo, final @NonNull Optional<Bookmark> bookmarkIfKnown) { @@ -62,11 +62,6 @@ implements _Refetchable { return Optional.of(bookmark); } - @Override - public Optional<Bookmark> getBookmarkRefreshed() { - return getBookmark(); // no-op for entities - } - @Override public boolean isBookmarkMemoized() { return true; diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityHybrid.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityHybrid.java index d0356438de..82765eb98d 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityHybrid.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectEntityHybrid.java @@ -42,25 +42,25 @@ extends _ManagedObjectSpecified implements _Refetchable { /** - * dynamically mutates from one to the other based on pojos persistent state; - * however the pojo reference must be kept identical + * dynamically mutates from one to the other based on pojo's persistent state; + * however, the pojo reference must be kept identical */ - private @NonNull Either<_ManagedObjectEntityDetached, _ManagedObjectEntityAttached> - eitherDetachedOrAttached; + private @NonNull Either<_ManagedObjectEntityDetached, _ManagedObjectEntityBookmarked> + eitherDetachedOrBookmarked; private EntityState entityState; _ManagedObjectEntityHybrid( final @NonNull _ManagedObjectEntityDetached detached) { super(ManagedObject.Specialization.ENTITY, detached.getSpecification()); - this.eitherDetachedOrAttached = Either.left(detached); + this.eitherDetachedOrBookmarked = Either.left(detached); this.entityState = EntityState.PERSISTABLE_DETACHED; } _ManagedObjectEntityHybrid( - final @NonNull _ManagedObjectEntityAttached attached) { + final @NonNull _ManagedObjectEntityBookmarked attached) { super(ManagedObject.Specialization.ENTITY, attached.getSpecification()); - this.eitherDetachedOrAttached = Either.right(attached); + this.eitherDetachedOrBookmarked = Either.right(attached); this.entityState = EntityState.PERSISTABLE_ATTACHED; this.bookmarkRef.set(attached.getBookmark().orElseThrow()); } @@ -73,11 +73,6 @@ implements _Refetchable { return Optional.ofNullable(bookmarkRef.get()); } - @Override - public Optional<Bookmark> getBookmarkRefreshed() { - return getBookmark(); // identity op - } - @Override public boolean isBookmarkMemoized() { return bookmarkRef.get()!=null; @@ -86,7 +81,7 @@ implements _Refetchable { @Override public @NonNull EntityState getEntityState() { - val entityState = eitherDetachedOrAttached + val entityState = eitherDetachedOrBookmarked .fold(ManagedObject::getEntityState, ManagedObject::getEntityState); if(this.entityState!=entityState) { @@ -105,7 +100,7 @@ implements _Refetchable { @Override public Object getPojo() { - val pojo = eitherDetachedOrAttached + val pojo = eitherDetachedOrBookmarked .fold(ManagedObject::getPojo, ManagedObject::getPojo); triggerReassessment(); @@ -115,7 +110,7 @@ implements _Refetchable { @Override public Object peekAtPojo() { - return eitherDetachedOrAttached + return eitherDetachedOrBookmarked .fold(_Refetchable::peekAtPojo, _Refetchable::peekAtPojo); } @@ -136,11 +131,11 @@ implements _Refetchable { private final AtomicReference<Bookmark> bookmarkRef = new AtomicReference<Bookmark>(); private boolean isVariantAttached() { - return eitherDetachedOrAttached.isRight(); + return eitherDetachedOrBookmarked.isRight(); } private boolean isVariantDetached() { - return eitherDetachedOrAttached.isLeft(); + return eitherDetachedOrBookmarked.isLeft(); } @Synchronized @@ -161,15 +156,15 @@ implements _Refetchable { val bookmark = isBookmarkMemoized() ? Optional.ofNullable(bookmarkRef.get()) : getSpecification().entityFacetElseFail().bookmarkFor(pojo); - val attached = new _ManagedObjectEntityAttached(getSpecification(), pojo, bookmark); - eitherDetachedOrAttached = Either.right(attached); + val attached = new _ManagedObjectEntityBookmarked(getSpecification(), pojo, bookmark); + eitherDetachedOrBookmarked = Either.right(attached); // set in any case bookmarkRef.set(attached.getBookmark().orElseThrow()); } // morph into detached private void detach(final Object pojo) { - eitherDetachedOrAttached = Either.left( + eitherDetachedOrBookmarked = Either.left( new _ManagedObjectEntityDetached(getSpecification(), pojo)); } diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectService.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectService.java index e9049f583a..982b9e0437 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectService.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectService.java @@ -61,11 +61,6 @@ extends _ManagedObjectSpecified { return bookmarkLazy.get(); } - @Override - public Optional<Bookmark> getBookmarkRefreshed() { - return getBookmark(); // no-op for services - } - @Override public boolean isBookmarkMemoized() { return bookmarkLazy.isMemoized(); diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectValue.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectValue.java index 6d2cc94cb4..6d8bf7520d 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectValue.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectValue.java @@ -58,11 +58,6 @@ extends _ManagedObjectSpecified { return bookmarkLazy.get(); } - @Override - public Optional<Bookmark> getBookmarkRefreshed() { - return getBookmark(); // no-op for values - } - @Override public boolean isBookmarkMemoized() { return bookmarkLazy.isMemoized(); diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectViewmodel.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectViewmodel.java index 441163221e..555d6332db 100644 --- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectViewmodel.java +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/object/_ManagedObjectViewmodel.java @@ -43,7 +43,9 @@ import lombok.val; */ final class _ManagedObjectViewmodel extends _ManagedObjectSpecified -implements _RefreshableViewmodel { +implements + Bookmarkable.BookmarkRefreshable, + _RefreshableViewmodel { @Getter(onMethod_ = {@Override}) @Nullable private /*final*/ Object pojo; @@ -74,9 +76,8 @@ implements _RefreshableViewmodel { } @Override - public final Optional<Bookmark> getBookmarkRefreshed() { + public void invalidateBookmark() { bookmarkLazy.clear(); - return getBookmark(); } private void replaceBookmark(final UnaryOperator<Bookmark> replacer) { diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java index 5c4084cca8..6f4de9587d 100644 --- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java +++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java @@ -233,7 +233,8 @@ public enum ActionResultResponseType { } public static ActionResultResponse toEntityPage(final ManagedObject entityOrViewmodel) { - return ActionResultResponse.toPage(EntityPage.class, entityOrViewmodel.getBookmarkRefreshed().orElseThrow()); + entityOrViewmodel.invalidateBookmark(); + return ActionResultResponse.toPage(EntityPage.class, entityOrViewmodel.getBookmark().orElseThrow()); } // -- HELPER diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java index 3dd662b1d6..3899309c78 100644 --- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java +++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java @@ -199,7 +199,10 @@ extends IndicatingAjaxLink<ManagedObject> { // the EventBus' exception handler will automatically veto. This results in a growl message rather than // an error page, but is probably 'good enough'). val targetAdapter = actionModel.getParentObject(); - val bookmark = targetAdapter.getBookmarkRefreshed().orElseThrow(); + + targetAdapter.invalidateBookmark(); + + val bookmark = targetAdapter.getBookmark().orElseThrow(); getCommonContext().getTransactionService().flushTransaction(); // "redirect-after-post" diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java index bb3c128a58..a04a5d577d 100644 --- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java +++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java @@ -173,6 +173,7 @@ implements FormExecutor { }); // redirect using associated strategy + // XXX note: on property edit, triggers SQL update (on JPA) resultResponse .getHandlingStrategy() .handleResults(getCommonContext(), resultResponse);