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:41 UTC

[42/50] [abbrv] isis git commit: ISIS-1194: minor refactors to findInstances ...

ISIS-1194: minor refactors to findInstances ...

... with respect to error handling of creating a corresponding PersistenceQuery for an applib Query, and looking up corresponding PersistenceQueryProcessor to actually execute.


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

Branch: refs/heads/ISIS-1194
Commit: fc05d143b7255b59958ee088085baf33528045e3
Parents: dfdd569
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Sep 10 10:21:26 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Sep 10 10:21:26 2015 +0100

----------------------------------------------------------------------
 .../system/persistence/PersistenceSession.java  | 43 +++++++++++++-------
 1 file changed, 29 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/fc05d143/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 74d9774..3512cf1 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
@@ -416,10 +416,11 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
      *             if the criteria is not support by this persistor
      */
     public <T> ObjectAdapter findInstances(final Query<T> query, final QueryCardinality cardinality) {
-        final PersistenceQuery persistenceQuery = createPersistenceQueryFor(query, cardinality);
-        if (persistenceQuery == null) {
-            throw new IllegalArgumentException("Unknown query type: " + query.getDescription());
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("findInstances using (applib) Query: " + query);
         }
+
+        final PersistenceQuery persistenceQuery = createPersistenceQueryFor(query, cardinality);
         return findInstances(persistenceQuery);
     }
 
@@ -436,18 +437,12 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
      * @throws org.apache.isis.core.runtime.persistence.UnsupportedFindException
      *             if the criteria is not support by this persistor
      */
-    public ObjectAdapter findInstances(final PersistenceQuery persistenceQuery) {
+    private ObjectAdapter findInstances(final PersistenceQuery persistenceQuery) {
         if (LOG.isDebugEnabled()) {
-            LOG.debug("getInstances matching " + persistenceQuery);
+            LOG.debug("findInstances using (core runtime) PersistenceQuery: " + persistenceQuery);
         }
 
-        final PersistenceQueryProcessor<? extends PersistenceQuery> processor =
-                PersistenceSession.this.persistenceQueryProcessorByClass
-                        .get(persistenceQuery.getClass());
-        if (processor == null) {
-            throw new UnsupportedFindException(MessageFormat.format(
-                    "Unsupported criteria type: {0}", persistenceQuery.getClass().getName()));
-        }
+        final PersistenceQueryProcessor<? extends PersistenceQuery> processor = lookupProcessorFor(persistenceQuery);
 
         final List<ObjectAdapter> instances = getTransactionManager().executeWithinTransaction(
                 new TransactionalClosureWithReturn<List<ObjectAdapter>>() {
@@ -461,12 +456,32 @@ public class PersistenceSession implements TransactionalResource, SessionScopedC
         return getAdapterManager().adapterFor(results);
     }
 
+    private PersistenceQueryProcessor<? extends PersistenceQuery> lookupProcessorFor(final PersistenceQuery persistenceQuery) {
+        final Class<? extends PersistenceQuery> persistenceQueryClass = persistenceQuery.getClass();
+        final PersistenceQueryProcessor<? extends PersistenceQuery> processor =
+                persistenceQueryProcessorByClass.get(persistenceQueryClass);
+        if (processor == null) {
+            throw new UnsupportedFindException(MessageFormat.format(
+                    "Unsupported PersistenceQuery class: {0}", persistenceQueryClass.getName()));
+        }
+        return processor;
+    }
+
     /**
      * Converts the {@link Query applib representation of a query} into the
      * {@link PersistenceQuery NOF-internal representation}.
      */
-    protected final PersistenceQuery createPersistenceQueryFor(final Query<?> query, final QueryCardinality cardinality) {
-        return persistenceQueryFactory.createPersistenceQueryFor(query, cardinality);
+    protected final PersistenceQuery createPersistenceQueryFor(
+            final Query<?> query,
+            final QueryCardinality cardinality) {
+
+        final PersistenceQuery persistenceQuery =
+                persistenceQueryFactory.createPersistenceQueryFor(query, cardinality);
+        if (persistenceQuery == null) {
+            throw new IllegalArgumentException("Unknown Query type: " + query.getDescription());
+        }
+
+        return persistenceQuery;
     }
 
     //endregion