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

ahuber pushed a commit to branch ISIS-1976-rethink-object-adapters
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to 
refs/heads/ISIS-1976-rethink-object-adapters by this push:
     new a416a1a  ISIS-1976: introduce 'isRecognized' to PS API (Draft)
a416a1a is described below

commit a416a1a37ba7ae62b7377bebc34d2879bb972fdd
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Mon Sep 10 19:27:13 2018 +0200

    ISIS-1976: introduce 'isRecognized' to PS API (Draft)
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
 .../system/persistence/PersistenceSession4.java       | 11 +++++++++++
 .../system/persistence/PersistenceSession5.java       | 19 ++++++++++++-------
 .../system/persistence/PersistenceSession.java        |  4 ++++
 .../persistence/adaptermanager/OidProviders.java      |  4 ++--
 4 files changed, 29 insertions(+), 9 deletions(-)

diff --git 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
 
b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
index 6869eab..b9b6ca9 100644
--- 
a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
+++ 
b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
@@ -1032,6 +1032,17 @@ implements 
IsisLifecycleListener.PersistenceSessionLifecycleManagement {
         }
         return false;
     }
+    
+    @Override
+    public boolean isRecognized(Object pojo) {
+        if (pojo!=null && pojo instanceof Persistable) {
+            final Object jdoOid = pm().getObjectId(pojo);
+            if(jdoOid!=null) {
+                return true;
+            }
+        }
+        return false;
+    }
 
     @Override
     public MementoRecreateObjectSupport mementoSupport() {
diff --git 
a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
 
b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
index d0f879c..4b8c6ab 100644
--- 
a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
+++ 
b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
@@ -51,7 +51,6 @@ import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
 import org.apache.isis.applib.services.iactn.Interaction;
-import org.apache.isis.commons.internal.exceptions._Exceptions;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.commons.exceptions.IsisException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -855,12 +854,7 @@ implements 
IsisLifecycleListener.PersistenceSessionLifecycleManagement {
 
     @Override
     public String identifierFor(final Object pojo) {
-        final Object jdoOid = getPersistenceManager().getObjectId(pojo);
-        if(jdoOid==null) {
-            _Exceptions.throwUnexpectedCodeReach();
-            return UUID.randomUUID().toString(); //FIXME[ISIS-1976] should be 
guarded against somewhere else
-        }
-        
+        final Object jdoOid = pm().getObjectId(pojo);
         requireNonNull(jdoOid, 
                 ()->String.format("Pojo of type '%s' is not recognized by 
JDO.", 
                         pojo.getClass().getName()));
@@ -1034,6 +1028,17 @@ implements 
IsisLifecycleListener.PersistenceSessionLifecycleManagement {
         }
         return false;
     }
+    
+    @Override
+    public boolean isRecognized(Object pojo) {
+        if (pojo!=null && pojo instanceof Persistable) {
+            final Object jdoOid = pm().getObjectId(pojo);
+            if(jdoOid!=null) {
+                return true;
+            }
+        }
+        return false;
+    }
 
     @Override
     public MementoRecreateObjectSupport mementoSupport() {
diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
index f26e3c3..c87c797 100644
--- 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
@@ -85,6 +85,9 @@ extends
     boolean isRepresentingPersistent(Object pojo);
     /**@since 2.0.0-M2*/
     boolean isDestroyed(Object pojo);
+    /** whether pojo is recognized by the persistence layer, that is, it has 
an ObjectId
+     * @since 2.0.0-M2*/
+    boolean isRecognized(Object pojo);
     /**@since 2.0.0-M2*/
     Object fetchPersistentPojo(RootOid rootOid);
     /**@since 2.0.0-M2*/
@@ -172,5 +175,6 @@ extends
     // -- OTHERS
     
     void execute(List<PersistenceCommand> persistenceCommandList);
+    
 
 }
diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java
 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java
index 833bf1d..58eef68 100644
--- 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/OidProviders.java
@@ -61,8 +61,8 @@ public class OidProviders {
         @Override
         public RootOid oidFor(Object pojo, ObjectSpecification spec) {
             final PersistenceSession persistenceSession = 
IsisContext.getPersistenceSession().get();
-            final boolean isPersistent = !persistenceSession.isTransient(pojo);
-            if(isPersistent) {
+            final boolean isRecognized = persistenceSession.isRecognized(pojo);
+            if(isRecognized) {
                 final String identifier = 
persistenceSession.identifierFor(pojo);
                 return new RootOid(spec.getSpecId(), identifier, 
Oid.State.PERSISTENT);
             } else {

Reply via email to