You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/09/15 08:03:12 UTC

[07/50] [abbrv] isis git commit: ISIS-1194: moved PersistenceSession#lazilyLoaded to AdapterManager.

ISIS-1194: moved PersistenceSession#lazilyLoaded to AdapterManager.

Also:
- renamed some of the methods in PersistenceSession to reflect what they actually do (vs when they are called).
- inlined postDeleteProcessing into its caller (IsisLifecycleListener2) since is a no-op


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/f401ee6f
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/f401ee6f
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/f401ee6f

Branch: refs/heads/master
Commit: f401ee6f7a58d1d7fceea5731dee476f09e69790
Parents: bf10d6f
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Sep 11 18:42:58 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Sep 14 07:35:55 2015 +0100

----------------------------------------------------------------------
 .../adaptermanager/AdapterManagerDefault.java   | 12 +++++-
 .../persistence/IsisLifecycleListener2.java     | 20 ++++-----
 .../system/persistence/PersistenceSession.java  | 44 ++++++--------------
 .../PersistenceQueryProcessorAbstract.java      |  2 +-
 4 files changed, 34 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/f401ee6f/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/adaptermanager/AdapterManagerDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/adaptermanager/AdapterManagerDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/adaptermanager/AdapterManagerDefault.java
index 89c00bc..085260b 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/adaptermanager/AdapterManagerDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/adaptermanager/AdapterManagerDefault.java
@@ -19,6 +19,7 @@
 
 package org.apache.isis.core.runtime.persistence.adaptermanager;
 
+import org.datanucleus.enhancement.Persistable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -200,7 +201,7 @@ public class AdapterManagerDefault implements AdapterManager,
         }
         
         // pojo may have been lazily loaded by object store, but we haven't yet seen it
-        final ObjectAdapter lazilyLoadedAdapter = persistenceSession.lazilyLoaded(pojo);
+        final ObjectAdapter lazilyLoadedAdapter = lazilyLoaded(pojo);
         if(lazilyLoadedAdapter != null) {
             return lazilyLoadedAdapter;
         }
@@ -217,6 +218,15 @@ public class AdapterManagerDefault implements AdapterManager,
         return null;
     }
 
+    private ObjectAdapter lazilyLoaded(Object pojo) {
+        if(!(pojo instanceof Persistable)) {
+            return null;
+        }
+        final Persistable persistenceCapable = (Persistable) pojo;
+        return persistenceSession.mapRecreatedPersistent(persistenceCapable);
+    }
+
+
 
     /**
      * {@inheritDoc}

http://git-wip-us.apache.org/repos/asf/isis/blob/f401ee6f/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IsisLifecycleListener2.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IsisLifecycleListener2.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IsisLifecycleListener2.java
index 09cb735..54c38c8 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IsisLifecycleListener2.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IsisLifecycleListener2.java
@@ -75,7 +75,7 @@ public class IsisLifecycleListener2
             @Override
             protected void doRun() {
                 final Persistable pojo = Utils.persistenceCapableFor(event);
-                persistenceSession.postLoadProcessingFor(pojo);
+                persistenceSession.initializeMapAndCheckConcurrency(pojo);
             }});
     }
 
@@ -85,7 +85,7 @@ public class IsisLifecycleListener2
             @Override
             protected void doRun() {
                 final Persistable pojo = Utils.persistenceCapableFor(event);
-                persistenceSession.preStoreProcessingFor(pojo);
+                persistenceSession.callIsisPersistingCallback(pojo);
 
             }});
     }
@@ -128,20 +128,20 @@ public class IsisLifecycleListener2
             @Override
             protected void doRun() {
                 final Persistable pojo = Utils.persistenceCapableFor(event);
-                persistenceSession.preDeleteProcessingFor(pojo);
+                persistenceSession.invokeIsisRemovingCallback(pojo);
             }
         });
     }
 
     @Override
     public void postDelete(InstanceLifecycleEvent event) {
-        withLogging(Phase.POST, event, new RunnableAbstract(event){
-            @Override
-            protected void doRun() {
-                final Persistable pojo = Utils.persistenceCapableFor(event);
-                persistenceSession.postDeleteProcessingFor(pojo);
-            }
-        });
+
+        // previously we called the PersistenceSession to invoke the removed callback (if any).
+        // however, this is almost certainly incorrect, because DN will not allow us
+        // to "touch" the pojo once deleted.
+        //
+        // CallbackFacet.Util.callCallback(adapter, RemovedCallbackFacet.class);
+
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/isis/blob/f401ee6f/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
----------------------------------------------------------------------
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 d6e3c23..8af6887 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
@@ -753,15 +753,8 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
 
     //region > lazilyLoaded
 
-    public ObjectAdapter lazilyLoaded(Object pojo) {
-        if(!(pojo instanceof Persistable)) {
-            return null;
-        }
-        final Persistable persistenceCapable = (Persistable) pojo;
-        return lazilyLoaded(persistenceCapable);
-    }
 
-    private ObjectAdapter lazilyLoaded(final Persistable pojo) {
+    public ObjectAdapter mapRecreatedPersistent(final Persistable pojo) {
         if (getJdoObjectId(pojo) == null) {
             return null;
         }
@@ -824,7 +817,7 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
         // possibly redundant because also called in the post-load event
         // listener, but (with JPA impl) found it was required if we were ever to
         // get an eager left-outer-join as the result of a refresh (sounds possible).
-        postLoadProcessingFor((Persistable) domainObject);
+        initializeMapAndCheckConcurrency((Persistable) domainObject);
     }
     //endregion
 
@@ -1237,21 +1230,7 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
 
     //region > FrameworkSynchronizer delegate methods
 
-    public void postDeleteProcessingFor(final Persistable pojo) {
-        ObjectAdapter adapter = getAdapterFor(pojo);
-        if (adapter == null) {
-            return;
-        }
-
-        // previously we called the removed callback (if any).
-        // however, this is almost certainly incorrect, because DN will not allow us
-        // to "touch" the pojo once deleted.
-        //
-        // CallbackFacet.Util.callCallback(adapter, RemovedCallbackFacet.class);
-    }
-
-
-    public void preDeleteProcessingFor(final Persistable pojo) {
+    public void invokeIsisRemovingCallback(final Persistable pojo) {
         ObjectAdapter adapter = adapterFor(pojo);
 
         final IsisTransaction transaction = getCurrentTransaction();
@@ -1261,7 +1240,7 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
     }
 
 
-    public void postLoadProcessingFor(final Persistable pojo) {
+    public void initializeMapAndCheckConcurrency(final Persistable pojo) {
         final Persistable pc = pojo;
 
         // need to do eagerly, because (if a viewModel then) a
@@ -1287,7 +1266,7 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
             final Version thisVersion = originalVersion;
             final Version otherVersion = datastoreVersion;
 
-            if (thisVersion != null &&
+            if (    thisVersion != null &&
                     otherVersion != null &&
                     thisVersion.different(otherVersion)) {
 
@@ -1328,7 +1307,7 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
      * The implementation therefore uses Isis' {@link org.apache.isis.core.metamodel.adapter.oid.Oid#isTransient() oid}
      * to determine which callback to fire.
      */
-    public void preStoreProcessingFor(final Persistable pojo) {
+    public void callIsisPersistingCallback(final Persistable pojo) {
         final ObjectAdapter adapter = getAdapterFor(pojo);
         if (adapter == null) {
             // not expected.
@@ -1390,10 +1369,6 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
         adapter.setVersion(versionIfAny);
     }
 
-    private Version getVersionIfAny(final Persistable pojo) {
-        return Utils.getVersionIfAny(pojo, authenticationSession);
-    }
-
 
     public void preDirtyProcessingFor(final Persistable pojo) {
         ObjectAdapter adapter = getAdapterFor(pojo);
@@ -1405,7 +1380,7 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
             // it seems reasonable in this case to simply map into Isis here ("just-in-time"); presumably
             // DN would not be calling this callback if the pojo was not persistent.
 
-            adapter = lazilyLoaded(pojo);
+            adapter = mapRecreatedPersistent(pojo);
             if (adapter == null) {
                 throw new RuntimeException(
                         "DN could not find objectId for pojo (unexpected) and so could not map into Isis; pojo=["
@@ -1441,6 +1416,11 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
         }
     }
 
+    private Version getVersionIfAny(final Persistable pojo) {
+        return Utils.getVersionIfAny(pojo, authenticationSession);
+    }
+
+
     //endregion
 
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/f401ee6f/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java
index 16b0c60..434acc5 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/queries/PersistenceQueryProcessorAbstract.java
@@ -59,7 +59,7 @@ public abstract class PersistenceQueryProcessorAbstract<T extends PersistenceQue
             ObjectAdapter adapter;
             if(pojo instanceof Persistable) {
                 // an entity
-                persistenceSession.postLoadProcessingFor((Persistable) pojo);
+                persistenceSession.initializeMapAndCheckConcurrency((Persistable) pojo);
                 adapter = persistenceSession.getAdapterFor(pojo);
             } else {
                 // a value type