deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-1269 [perf] Cache singleResultType per method
Date Wed, 07 Jun 2017 15:17:58 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master d9b1acb2b -> 762d3a53b


DELTASPIKE-1269 [perf] Cache singleResultType per method

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

Branch: refs/heads/master
Commit: 762d3a53b4d029e5bdff5e7b3824e3686af19bfe
Parents: d9b1acb
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Wed Jun 7 17:17:50 2017 +0200
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Wed Jun 7 17:17:50 2017 +0200

----------------------------------------------------------------------
 .../builder/result/QueryProcessorFactory.java   |  2 +-
 .../impl/handler/CdiQueryInvocationContext.java | 61 +++++++-------------
 .../impl/meta/RepositoryMethodMetadata.java     | 13 +++++
 .../RepositoryMethodMetadataInitializer.java    | 21 +++++++
 4 files changed, 55 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/762d3a53/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
index 4139cae..a9be795 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/result/QueryProcessorFactory.java
@@ -102,7 +102,7 @@ public class QueryProcessorFactory
         @Override
         public Object executeQuery(Query query, CdiQueryInvocationContext context)
         {
-            SingleResultType style = context.getSingleResultStyle();
+            SingleResultType style = context.getRepositoryMethodMetadata().getSingleResultType();
             Object result = null;
             switch (style)
             {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/762d3a53/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
index 5586daf..529bbb1 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/CdiQueryInvocationContext.java
@@ -31,7 +31,6 @@ import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.api.provider.DependentProvider;
 
 import org.apache.deltaspike.data.api.EntityGraph;
-import org.apache.deltaspike.data.api.SingleResultType;
 import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
 import org.apache.deltaspike.data.impl.graph.EntityGraphHelper;
 import org.apache.deltaspike.data.impl.meta.EntityMetadata;
@@ -159,26 +158,32 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
     {
         Parameters params = getParams();
         Method method = getMethod();
+        
         if (params.hasSizeRestriction())
         {
             query.setMaxResults(params.getSizeRestriciton());
         }
+        
         if (params.hasFirstResult())
         {
             query.setFirstResult(params.getFirstResult());
         }
-        if (hasLockMode(method))
+        
+        LockModeType lockMode = extractLockMode();
+        if (lockMode != null)
         {
-            query.setLockMode(extractLockMode(method));
+            query.setLockMode(lockMode);
         }
-        if (hasQueryHints(method))
+        
+        QueryHint[] hints = extractQueryHints();
+        if (hints != null)
         {
-            QueryHint[] hints = extractQueryHints(method);
             for (QueryHint hint : hints)
             {
                 query.setHint(hint.name(), hint.value());
             }
         }
+
         applyEntityGraph(query, method);
         query = applyJpaQueryPostProcessors(query);
         return query;
@@ -298,59 +303,33 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
         return result;
     }
 
-    public SingleResultType getSingleResultStyle()
-    {
-        SingleResultType baseSingleResultType = repositoryMethodMetadata.getQuery() != null
-                ? repositoryMethodMetadata.getQuery().singleResult()
-                : repositoryMethodMetadata.getMethodPrefix().getSingleResultStyle();
-        
-        if (repositoryMethodMetadata.isReturnsOptional() && baseSingleResultType
== SingleResultType.JPA)
-        {
-            return SingleResultType.OPTIONAL;
-        }
-        else
-        {
-            return baseSingleResultType;
-        }
-    }
-
     public Object getProxy()
     {
         return proxy;
     }
 
-    private boolean hasLockMode(Method method)
-    {
-        return extractLockMode(method) != null;
-    }
-
-    private LockModeType extractLockMode(Method method)
+    private LockModeType extractLockMode()
     {
-        Class<org.apache.deltaspike.data.api.Query> query = org.apache.deltaspike.data.api.Query.class;
-        if (method.isAnnotationPresent(query) &&
-                method.getAnnotation(query).lock() != LockModeType.NONE)
+        org.apache.deltaspike.data.api.Query query = getRepositoryMethodMetadata().getQuery();
+        if (query != null && query.lock() != LockModeType.NONE)
         {
-            return method.getAnnotation(query).lock();
+            return query.lock();
         }
+
         return null;
     }
 
-    private QueryHint[] extractQueryHints(Method method)
+    private QueryHint[] extractQueryHints()
     {
-        Class<org.apache.deltaspike.data.api.Query> query = org.apache.deltaspike.data.api.Query.class;
-        if (method.isAnnotationPresent(query) &&
-                method.getAnnotation(query).hints().length > 0)
+        org.apache.deltaspike.data.api.Query query = getRepositoryMethodMetadata().getQuery();
       
+        if (query != null && query.hints().length > 0)
         {
-            return method.getAnnotation(query).hints();
+            return query.hints();
         }
+
         return null;
     }
 
-    private boolean hasQueryHints(Method method)
-    {
-        return extractQueryHints(method) != null;
-    }
-    
     private void applyEntityGraph(Query query, Method method)
     {
         EntityGraph entityGraphAnn = method.getAnnotation(EntityGraph.class);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/762d3a53/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
index 3c4e6af..84d528c 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadata.java
@@ -21,6 +21,7 @@ package org.apache.deltaspike.data.impl.meta;
 import java.lang.reflect.Method;
 import org.apache.deltaspike.data.api.Modifying;
 import org.apache.deltaspike.data.api.Query;
+import org.apache.deltaspike.data.api.SingleResultType;
 import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
 import org.apache.deltaspike.data.impl.builder.part.QueryRoot;
 import org.apache.deltaspike.data.impl.builder.result.QueryProcessor;
@@ -42,6 +43,8 @@ public class RepositoryMethodMetadata
     
     private boolean returnsOptional;
     private boolean returnsStream;
+    
+    private SingleResultType singleResultType;
 
     public RepositoryMethodMetadata()
     {
@@ -162,4 +165,14 @@ public class RepositoryMethodMetadata
     {
         this.returnsStream = returnsStream;
     }
+
+    public SingleResultType getSingleResultType()
+    {
+        return singleResultType;
+    }
+
+    public void setSingleResultType(SingleResultType singleResultType)
+    {
+        this.singleResultType = singleResultType;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/762d3a53/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
index e21fcdc..74f1dc0 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMethodMetadataInitializer.java
@@ -35,6 +35,7 @@ import org.apache.deltaspike.core.util.StreamUtil;
 import org.apache.deltaspike.data.api.Modifying;
 import org.apache.deltaspike.data.api.Query;
 import org.apache.deltaspike.data.api.Repository;
+import org.apache.deltaspike.data.api.SingleResultType;
 import org.apache.deltaspike.data.api.mapping.MappingConfig;
 import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
 import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
@@ -77,6 +78,9 @@ public class RepositoryMethodMetadataInitializer
         initQueryRoot(repositoryMetadata, repositoryMethodMetadata);
         initQueryInOutMapperIsNormalScope(repositoryMetadata, repositoryMethodMetadata, beanManager);
 
+        initSingleResultType(repositoryMethodMetadata);
+
+        
         return repositoryMethodMetadata;
     }
 
@@ -172,4 +176,21 @@ public class RepositoryMethodMetadataInitializer
         
         return null;
     }
+    
+    private void initSingleResultType(RepositoryMethodMetadata repositoryMethodMetadata)
+    {
+        SingleResultType singleResultType = repositoryMethodMetadata.getQuery() != null
+                ? repositoryMethodMetadata.getQuery().singleResult()
+                : repositoryMethodMetadata.getMethodPrefix().getSingleResultStyle();
+        
+        if (repositoryMethodMetadata.isReturnsOptional() && singleResultType == SingleResultType.JPA)
+        {
+            repositoryMethodMetadata.setSingleResultType(SingleResultType.OPTIONAL);
+        }
+        else
+        {
+            repositoryMethodMetadata.setSingleResultType(singleResultType);
+        }
+    }
+    
 }


Mime
View raw message