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/10 14:07:15 UTC

[16/50] [abbrv] isis git commit: ISIS-1194: inlining and simplifying PersistenceSession# loadObject

ISIS-1194: inlining and simplifying PersistenceSession# loadObject


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

Branch: refs/heads/ISIS-1194
Commit: 9fed5270eb6f1316203b8bcdd637f4bf21a7fd8b
Parents: fba0c14
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Sep 10 09:00:49 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Sep 10 09:00:49 2015 +0100

----------------------------------------------------------------------
 .../system/persistence/PersistenceSession.java  | 79 ++++++++------------
 1 file changed, 32 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/9fed5270/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 2876b2c..6c8f874 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
@@ -546,47 +546,15 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
     }
     //endregion
 
-    //region > loadObject, reload
-    /**
-     * Loads the object identified by the specified {@link RootOid} from the
-     * persisted set of objects.
-     */
-    public ObjectAdapter loadObject(final RootOid oid) {
-        
-        // REVIEW: 
-        // this method does not account for the oid possibly being a view model
-        // alternatively, can call getAdapterManager().adapterFor(oid); this code
-        // delegates to the PojoRecreator which *does* take view models into account
-        //
-        // it's possible, therefore, that existing callers to this method (the Scimpi viewer)
-        // could be refactored to use getAdapterManager().adapterFor(...)
-        ensureThatArg(oid, is(notNullValue()));
-
-        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(oid);
-        if (adapter != null) {
-            return adapter;
-        }
-
-        return loadMappedObjectFromObjectStore(oid);
-    }
-
-    private ObjectAdapter loadMappedObjectFromObjectStore(final RootOid oid) {
-        final ObjectAdapter adapter = getTransactionManager().executeWithinTransaction(
-                new TransactionalClosureWithReturn<ObjectAdapter>() {
-                    @Override
-                    public ObjectAdapter execute() {
-                        return loadInstanceAndAdapt(oid);
-                    }
-                });
-        return adapter;
-    }
-
-    //endregion
+    //region > loadObject
 
-    //region > loadInstanceAndAdapt
     /**
-     * Retrieves the object identified by the specified {@link RootOid} from the object
-     * store, {@link AdapterManager#mapRecreatedPojo(org.apache.isis.core.metamodel.adapter.oid.Oid, Object) mapped by the adapter manager}.
+     * Loads the object identified by the specified {@link RootOid}.
+     *
+     * <p>
+     * That is, it retrieves the object identified by the specified {@link RootOid} from the object
+     * store, {@link AdapterManager#mapRecreatedPojo(org.apache.isis.core.metamodel.adapter.oid.Oid, Object) mapped by
+     * the adapter manager}.
      *
      * <p>The cache should be checked first and, if the object is cached,
      * the cached version should be returned. It is important that if this
@@ -623,16 +591,34 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
      * @throws org.apache.isis.core.runtime.persistence.ObjectNotFoundException
      *             when no object corresponding to the oid can be found
      */
-    public ObjectAdapter loadInstanceAndAdapt(final RootOid oid) {
-        ensureOpened();
-        ensureInTransaction();
+    public ObjectAdapter loadObject(final RootOid oid) {
+        
+        // REVIEW: 
+        // this method does not account for the oid possibly being a view model
+        // alternatively, can call getAdapterManager().adapterFor(oid); this code
+        // delegates to the PojoRecreator which *does* take view models into account
+        //
+        // it's possible, therefore, that existing callers to this method (the Scimpi viewer)
+        // could be refactored to use getAdapterManager().adapterFor(...)
+        ensureThatArg(oid, is(notNullValue()));
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("getObject; oid=" + oid);
+        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(oid);
+        if (adapter != null) {
+            return adapter;
         }
 
-        final Object pojo = loadPojo(oid);
-        return getAdapterManager().mapRecreatedPojo(oid, pojo);
+        return getTransactionManager().executeWithinTransaction(
+                new TransactionalClosureWithReturn<ObjectAdapter>() {
+                    @Override
+                    public ObjectAdapter execute() {
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("getObject; oid=" + oid);
+                        }
+
+                        final Object pojo = loadPojo(oid);
+                        return getAdapterManager().mapRecreatedPojo(oid, pojo);
+                    }
+                });
     }
 
 
@@ -640,7 +626,6 @@ public class PersistenceSession implements SessionScopedComponent, DebuggableWit
 
     //region > loadPojo
 
-
     public Object loadPojo(final RootOid rootOid) {
 
         Object result = null;