You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2023/06/29 11:29:06 UTC
[causeway] branch 3500-entity.state.cleanup updated: CAUSEWAY-3500: removes unsafe hasOid
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 3500-entity.state.cleanup
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/3500-entity.state.cleanup by this push:
new 33c8843030 CAUSEWAY-3500: removes unsafe hasOid
33c8843030 is described below
commit 33c88430300229889b5fe7f4044fb2de7d511ba3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Jun 29 13:29:02 2023 +0200
CAUSEWAY-3500: removes unsafe hasOid
---
.../applib/services/repository/EntityState.java | 15 ++++------
.../object/_ManagedObjectEntityBookmarked.java | 10 ++-----
.../executor/MemberExecutorServiceDefault.java | 2 +-
.../metamodel/facets/entity/JdoEntityFacet.java | 7 +++--
.../applib/fixturescripts/FixtureScripts.java | 33 ++++++----------------
5 files changed, 22 insertions(+), 45 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/services/repository/EntityState.java b/api/applib/src/main/java/org/apache/causeway/applib/services/repository/EntityState.java
index 8d8caa8de3..d64d016a5f 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/services/repository/EntityState.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/services/repository/EntityState.java
@@ -136,21 +136,16 @@ public enum EntityState {
|| isDetached();
}
- //FIXME[CAUSEWAY-3500] hollow has OID
- public boolean hasOid() {
- return isAttached() || isDetached();
- }
-
- //FIXME[CAUSEWAY-3500] no of the below can be flushed!
+ //FIXME[CAUSEWAY-3500] 3 different types of flush checks, which is it though
public boolean isFlushable() {
- return isJdoHollow()
- || isTransientOrRemoved()
- || isDetached();
+ return isDetached()
+ || (isTransientOrRemoved()
+ && !isJdoDeleted());
}
//FIXME[CAUSEWAY-3500] 3 different types of flush checks, which is it though
public boolean canFlush() {
- return !unsafe.hasOid();
+ return (!isAttached() && !isDetached());
}
//FIXME[CAUSEWAY-3500] 3 different types of flush checks, which is it though
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/object/_ManagedObjectEntityBookmarked.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/object/_ManagedObjectEntityBookmarked.java
index 1def118757..a4fbae263d 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/object/_ManagedObjectEntityBookmarked.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/object/_ManagedObjectEntityBookmarked.java
@@ -130,7 +130,7 @@ implements _Refetchable {
val refetchedPojo = refetchedIfSuccess.get();
- if(!entityFacet.getEntityState(refetchedPojo).unsafe.hasOid()) {
+ if(!entityFacet.getEntityState(refetchedPojo).hasOid()) {
throw new ObjectNotFoundException(""+bookmark);
//throw _Exceptions.illegalState("entity not attached after refetch attempt %s", bookmark);
}
@@ -148,13 +148,9 @@ implements _Refetchable {
private Bookmark createBookmark() {
val entityFacet = entityFacet();
- // fail early when detached entities are detected
+ // fail early when non bookmarkable entities are detected
// should have been re-fetched at start of this request-cycle
- if(
-// && EntityUtil.getPersistenceStandard(managedObject)
-// .map(PersistenceStandard::isJdo)
-// .orElse(false)
- !entityFacet.getEntityState(pojo).unsafe.hasOid()) {
+ if(!entityFacet.getEntityState(pojo).hasOid()) {
_Debug.onCondition(XrayUi.isXrayEnabled(), ()->{
_Debug.log("detached entity detected %s", pojo);
diff --git a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/executor/MemberExecutorServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/executor/MemberExecutorServiceDefault.java
index fb8b03e77e..ab82dcfcb2 100644
--- a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/executor/MemberExecutorServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/executor/MemberExecutorServiceDefault.java
@@ -315,7 +315,7 @@ implements MemberExecutorService {
}
val entityState2 = resultAdapter.getEntityState();
- if(entityState2.unsafe.hasOid()) {
+ if(entityState2.hasOid()) {
val bookmark = ManagedObjects.bookmarkElseFail(resultAdapter);
command.updater().setResult(Try.success(bookmark));
return;
diff --git a/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java b/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java
index 9392e32bed..a17efa611a 100644
--- a/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java
+++ b/persistence/jdo/datanucleus/src/main/java/org/apache/causeway/persistence/jdo/datanucleus/metamodel/facets/entity/JdoEntityFacet.java
@@ -341,8 +341,11 @@ implements EntityFacet {
// guard against misuse
_Assert.assertNullableObjectIsInstanceOf(pojo, entityClass);
- if(pojo==null
- || DnEntityStateProvider.entityState(pojo).unsafe.hasOid()) {
+ val entityState = DnEntityStateProvider.entityState(pojo);
+
+ if(!entityState.isPersistable()
+ || entityState.isAttached()
+ || entityState.isJdoDeleted()) {
return; // nothing to do
}
diff --git a/testing/fixtures/applib/src/main/java/org/apache/causeway/testing/fixtures/applib/fixturescripts/FixtureScripts.java b/testing/fixtures/applib/src/main/java/org/apache/causeway/testing/fixtures/applib/fixturescripts/FixtureScripts.java
index ec6186bb7e..a9953923eb 100644
--- a/testing/fixtures/applib/src/main/java/org/apache/causeway/testing/fixtures/applib/fixturescripts/FixtureScripts.java
+++ b/testing/fixtures/applib/src/main/java/org/apache/causeway/testing/fixtures/applib/fixturescripts/FixtureScripts.java
@@ -31,7 +31,6 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.xml.bind.annotation.XmlRootElement;
-import org.apache.causeway.applib.ViewModel;
import org.apache.causeway.applib.annotation.Action;
import org.apache.causeway.applib.annotation.ActionLayout;
import org.apache.causeway.applib.annotation.Domain;
@@ -540,34 +539,18 @@ public class FixtureScripts {
return null;
}
- if (object instanceof ViewModel
- || repositoryService.getEntityState(object).unsafe.shouldFlush()) {
- // continue
- } else {
- switch(getNonPersistedObjectsStrategy()) {
- case PERSIST:
+ switch(getNonPersistedObjectsStrategy()) {
+ case PERSIST:
+ if (repositoryService.getEntityState(object).unsafe.shouldFlush()) {
transactionService.flushTransaction();
- break;
- case IGNORE:
- return null;
- default:
- throw _Exceptions.unmatchedCase(getNonPersistedObjectsStrategy());
}
+ break;
+ case IGNORE:
+ return null;
+ default:
+ throw _Exceptions.unmatchedCase(getNonPersistedObjectsStrategy());
}
-
-// switch(getNonPersistedObjectsStrategy()) {
-// case PERSIST:
-// if (repositoryService.getEntityState(object).unsafe.shouldFlush()) {
-// transactionService.flushTransaction();
-// }
-// break;
-// case IGNORE:
-// return null;
-// default:
-// throw _Exceptions.unmatchedCase(getNonPersistedObjectsStrategy());
-// }
-
final FixtureResult fixtureResult = serviceInjector.injectServicesInto(
new FixtureResult());
fixtureResult.setFixtureScriptClassName(firstTime ? script.getClass().getName() : null);