You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/05/28 14:29:00 UTC

[isis] branch master updated: ISIS-2706: if entity state is undecidable between DETACHED or REMOVED, return DETACHED

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new effaaf6  ISIS-2706: if entity state is undecidable between DETACHED or REMOVED, return DETACHED
effaaf6 is described below

commit effaaf651370d2fda3fb49baf570e3f8c4393259
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri May 28 16:28:31 2021 +0200

    ISIS-2706: if entity state is undecidable between DETACHED or REMOVED,
    return DETACHED
---
 .../metamodel/JpaEntityFacetFactory.java           |  9 +++-----
 .../JpaGeneratedLongIdEntityLifecycleTest.java     |  2 +-
 ...JpaNonGeneratedStringIdEntityLifecycleTest.java | 24 ++++++++++------------
 3 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java b/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java
index 3579421..7c2730a 100644
--- a/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java
+++ b/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java
@@ -296,14 +296,11 @@ public class JpaEntityFacetFactory extends FacetFactoryAbstract {
 
             val primaryKey = getPersistenceUnitUtil(entityManager).getIdentifier(pojo);
             if(primaryKey == null) {
-                return EntityState.PERSISTABLE_DETACHED;
+                return EntityState.PERSISTABLE_DETACHED; // an optimization, not strictly required
             }
 
-            //XXX this find operation is potentially expensive,
-            // compared to JDO, which does not require this extra step
-            return entityManager.find(entityClass, primaryKey)==null
-                    ? EntityState.PERSISTABLE_DESTROYED
-                    : EntityState.PERSISTABLE_DETACHED;
+            //XXX whether DETACHED or REMOVED is currently undecidable (JPA)
+            return EntityState.PERSISTABLE_DETACHED;
         }
 
         @Override
diff --git a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaGeneratedLongIdEntityLifecycleTest.java b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaGeneratedLongIdEntityLifecycleTest.java
index e5af29d..0c66f5e 100644
--- a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaGeneratedLongIdEntityLifecycleTest.java
+++ b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaGeneratedLongIdEntityLifecycleTest.java
@@ -132,7 +132,7 @@ class JpaGeneratedLongIdEntityLifecycleTest {
 
         repository.remove(entity.getPojo());
 
-     // expected post-condition (after removal)
+        // expected post-condition (after removal)
         assertEquals(
                 EntityState.PERSISTABLE_DESTROYED,
                 ManagedObjects.EntityUtil.getEntityState(entity));
diff --git a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaNonGeneratedStringIdEntityLifecycleTest.java b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaNonGeneratedStringIdEntityLifecycleTest.java
index 2984452..65ff4d1 100644
--- a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaNonGeneratedStringIdEntityLifecycleTest.java
+++ b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/isis/testdomain/persistence/jpa/entitylifecycle/JpaNonGeneratedStringIdEntityLifecycleTest.java
@@ -25,7 +25,6 @@ import javax.inject.Inject;
 
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.MethodOrderer;
 import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.Test;
@@ -76,14 +75,12 @@ class JpaNonGeneratedStringIdEntityLifecycleTest {
         entityRef = null;
     }
 
-    @Disabled("TODO: ISIS-2706")
     @Test @Order(0) @Commit
     void cleanup_justInCase() {
         // cleanup just in case
         repository.removeAll(JpaEntityNonGeneratedStringId.class);
     }
 
-    @Disabled("TODO: ISIS-2706")
     @Test @Order(1) @Commit
     void detached_shouldBeProperlyDetected() {
 
@@ -98,7 +95,6 @@ class JpaNonGeneratedStringIdEntityLifecycleTest {
         entityRef.set(entity);
     }
 
-    @Disabled("TODO: ISIS-2706")
     @Test @Order(2) @Commit
     void attached_shouldBeProperlyDetected() {
 
@@ -113,7 +109,6 @@ class JpaNonGeneratedStringIdEntityLifecycleTest {
 
     }
 
-    @Disabled("TODO: ISIS-2706")
     @Test @Order(3) @Commit
     void removed_shouldBeProperlyDetected() {
 
@@ -137,26 +132,29 @@ class JpaNonGeneratedStringIdEntityLifecycleTest {
 
         repository.remove(entity.getPojo());
 
-     // expected post-condition (after removal)
-        assertEquals(
-                EntityState.PERSISTABLE_DESTROYED,
-                ManagedObjects.EntityUtil.getEntityState(entity));
+        // expected post-condition (after removal)
+        assertDetachedOrDeleted(entity);
 
         entityRef.set(entity);
     }
 
-    @Disabled("TODO: ISIS-2706")
     @Test @Order(4) @Commit
     void postCondition_shouldBe_anEmptyRepository() {
 
         val entity = entityRef.get();
 
-        assertEquals(
-                EntityState.PERSISTABLE_DESTROYED,
-                ManagedObjects.EntityUtil.getEntityState(entity));
+        assertDetachedOrDeleted(entity);
         assertEquals(0, repository.allInstances(JpaEntityNonGeneratedStringId.class).size());
 
     }
 
+    // -- HELPER
+
+    public static void assertDetachedOrDeleted(final ManagedObject entity) {
+        assertEquals(
+                EntityState.PERSISTABLE_DETACHED, // if undecidable we currently return PERSISTABLE_DETACHED;
+                ManagedObjects.EntityUtil.getEntityState(entity));
+    }
+
 
 }