-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAUSEWAY-3859: Java record refactoring (part 51)
- Loading branch information
1 parent
ac86f6c
commit 78e5c48
Showing
6 changed files
with
110 additions
and
198 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...model/src/main/java/org/apache/causeway/core/metamodel/object/BookmarkedObjectHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.causeway.core.metamodel.object; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
import org.jspecify.annotations.NonNull; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
import org.apache.causeway.applib.services.bookmark.Bookmark; | ||
import org.apache.causeway.core.metamodel.context.MetaModelContext; | ||
import org.apache.causeway.core.metamodel.objectmanager.ObjectManager; | ||
|
||
/** | ||
* Transiently holds a detachable {@link ManagedObject}, | ||
* that is lazily created based on the given immutable {@link Bookmark}. | ||
*/ | ||
public final class BookmarkedObjectHolder implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final Bookmark bookmark; | ||
private transient ManagedObject managedObject; | ||
|
||
public BookmarkedObjectHolder(final @NonNull Bookmark bookmark, final @Nullable ManagedObject managedObject) { | ||
this.bookmark = bookmark; | ||
this.managedObject = managedObject; | ||
} | ||
|
||
public Bookmark bookmark() { | ||
return bookmark; | ||
} | ||
|
||
public ManagedObject managedObject() { | ||
return managedObject!=null | ||
? managedObject | ||
: (this.managedObject = objectManager().loadObjectElseFail(bookmark)); | ||
} | ||
|
||
public void detach() { | ||
this.managedObject = null; | ||
} | ||
|
||
// -- CONTRACT | ||
|
||
@Override | ||
public final int hashCode() { | ||
return bookmark.hashCode(); | ||
} | ||
|
||
@Override | ||
public final boolean equals(final Object obj) { | ||
return obj instanceof BookmarkedObjectHolder other | ||
? Objects.equals(this.bookmark, other.bookmark) | ||
: false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ManagedObjectHolder[%s]".formatted(bookmark); | ||
} | ||
|
||
// -- HELPER | ||
|
||
private ObjectManager objectManager() { | ||
return MetaModelContext.instanceElseFail().getObjectManager(); | ||
} | ||
|
||
} |
165 changes: 0 additions & 165 deletions
165
...odel/src/main/java/org/apache/causeway/viewer/wicket/model/models/ManagedObjectModel.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters