Skip to content

Commit

Permalink
CAUSEWAY-2297: removes _Recreatable
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-huber committed Nov 12, 2024
1 parent 6e49606 commit 8cd193c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,34 @@
import org.apache.causeway.applib.id.HasLogicalType;
import org.apache.causeway.applib.id.LogicalType;
import org.apache.causeway.applib.services.bookmark.BookmarkHolder;
import org.apache.causeway.applib.services.bookmark.Oid;
import org.apache.causeway.commons.internal.base._Bytes;
import org.apache.causeway.commons.internal.base._Strings;
import org.apache.causeway.commons.internal.collections._Lists;
import org.apache.causeway.commons.internal.resources._Serializables;
import org.apache.causeway.core.metamodel.facets.object.value.ValueFacet;
import org.apache.causeway.core.metamodel.object.ManagedObject;

/**
* @since 2.0
*/
public interface ObjectMemento extends BookmarkHolder, HasLogicalType, Serializable {
public sealed interface ObjectMemento
extends BookmarkHolder, HasLogicalType, Serializable
permits ObjectMementoForEmpty, ObjectMementoForScalar, ObjectMementoCollection {

enum RecreateStrategy {
/**
* The {@link ManagedObject} that this is the memento for, directly has
* an {@link ValueFacet} (it is almost certainly a value), and so is
* stored directly.
*/
VALUE,
/**
* The {@link ManagedObject} that this is for, is already known by its
* (persistent) {@link Oid}.
*/
LOOKUP;
}

/** arbitrary/random string */
static final String NULL_ID = "VGN6r6zKTiLhUsA0WkdQ17LvMU1IYdb0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
@ToString
@RequiredArgsConstructor
public class ObjectMementoForEmpty implements ObjectMemento {
public final class ObjectMementoForEmpty implements ObjectMemento {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static ObjectMementoForScalar createPersistent(

@Getter(onMethod_ = {@Override}) final LogicalType logicalType;

_Recreatable.RecreateStrategy recreateStrategy;
ObjectMemento.RecreateStrategy recreateStrategy;

@Getter(onMethod_ = {@Override}) private final String title;
@Getter final Bookmark bookmark;
Expand All @@ -86,8 +86,8 @@ private ObjectMementoForScalar(
this.title = "?memento?"; // TODO can we do better?

this.recreateStrategy = spec.isValue()
? _Recreatable.RecreateStrategy.VALUE
: _Recreatable.RecreateStrategy.LOOKUP;
? RecreateStrategy.VALUE
: RecreateStrategy.LOOKUP;
}

private ObjectMementoForScalar(final @NonNull ManagedObject adapter) {
Expand All @@ -109,13 +109,13 @@ private ObjectMementoForScalar(final @NonNull ManagedObject adapter) {
? bookmark.withHintId(hintId)
: bookmark;

recreateStrategy = _Recreatable.RecreateStrategy.LOOKUP;
recreateStrategy = RecreateStrategy.LOOKUP;
return;
}

if (spec.isValue()) {
bookmark = ManagedObjects.bookmarkElseFail(adapter);
recreateStrategy = _Recreatable.RecreateStrategy.VALUE;
recreateStrategy = RecreateStrategy.VALUE;
return;
}

Expand All @@ -141,20 +141,20 @@ public ManagedObject reconstructObject(final MetaModelContext mmc) {
return spec.getMetaModelContext().lookupServiceAdapterById(getLogicalTypeName());
}

return recreateStrategy.recreateObject(this, mmc);
return mmc.getObjectManager().loadObjectElseFail(bookmark);
}

@Override
public int hashCode() {
return recreateStrategy.hashCode(this);
return bookmark.hashCode();
}

@Override
public boolean equals(final Object other) {
if (!(other instanceof ObjectMementoForScalar)) {
return false;
}
return recreateStrategy.equals(this, (ObjectMementoForScalar) other);
public boolean equals(final Object o) {
return (o instanceof ObjectMementoForScalar other)
? this.recreateStrategy == other.recreateStrategy
&& this.bookmark.equals(other.bookmark)
: false;
}

}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 8cd193c

Please sign in to comment.