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-1270 [perf] cache Transactional per method
Date Thu, 08 Jun 2017 15:27:45 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master dbd437ea0 -> 4965c1767


DELTASPIKE-1270 [perf] cache Transactional per method

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

Branch: refs/heads/master
Commit: 4965c176758672e32579d2af00bc0c458b828a9e
Parents: dbd437e
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Thu Jun 8 17:27:33 2017 +0200
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Thu Jun 8 17:27:33 2017 +0200

----------------------------------------------------------------------
 .../impl/handler/CdiQueryInvocationContext.java |  2 +-
 .../data/impl/handler/QueryHandler.java         | 29 +++++++++-----------
 .../impl/meta/RepositoryMetadataHandler.java    |  6 ++--
 .../meta/RepositoryMetadataInitializer.java     |  8 +++---
 .../impl/meta/RepositoryMethodMetadata.java     | 13 +++++++++
 .../RepositoryMethodMetadataInitializer.java    |  8 ++++++
 6 files changed, 42 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4965c176/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 529bbb1..f8fa9ba 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
@@ -78,7 +78,7 @@ public class CdiQueryInvocationContext implements QueryInvocationContext
         this.cleanup = new LinkedList<Destroyable>();
     }
 
-    public void initMapper()
+    public void init()
     {
         if (hasQueryInOutMapper())
         {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4965c176/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
index 4698541..ce1a7e0 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/QueryHandler.java
@@ -85,19 +85,21 @@ public class QueryHandler implements Serializable, InvocationHandler
     @Override
     public Object invoke(final Object proxy, final Method method, final Object[] args) throws
Throwable
     {
-        Transactional transactionalAnnotation =
-            AnnotationUtils.extractAnnotationFromMethodOrClass(
-                this.beanManager, method, proxy.getClass(), Transactional.class);
+        List<Class<?>> candidates = ProxyUtils.getProxyAndBaseTypes(proxy.getClass());
+        final RepositoryMetadata repositoryMetadata =
+                metadataHandler.lookupMetadata(candidates);
+        final RepositoryMethodMetadata repositoryMethodMetadata =
+                metadataHandler.lookupMethodMetadata(repositoryMetadata, method);
 
-        if (transactionalAnnotation != null)
+        if (repositoryMethodMetadata.getTransactional() != null)
         {
-            if (transactionalAnnotation.qualifier().length > 1)
+            if (repositoryMethodMetadata.getTransactional().qualifier().length > 1)
             {
                 throw new IllegalStateException(proxy.getClass().getName() + " uses @" +
Transactional.class.getName() +
                     " with multiple qualifiers. That isn't supported with @" + Repository.class.getName());
             }
 
-            Class<? extends Annotation> qualifier = transactionalAnnotation.qualifier()[0];
+            Class<? extends Annotation> qualifier = repositoryMethodMetadata.getTransactional().qualifier()[0];
             if (!Any.class.equals(qualifier))
             {
                 EntityManager entityManager = BeanProvider.getContextualReference(
@@ -113,7 +115,7 @@ public class QueryHandler implements Serializable, InvocationHandler
                     {
                         try
                         {
-                            return process(proxy, method, args);
+                            return process(proxy, method, args, repositoryMetadata, repositoryMethodMetadata);
                         }
                         catch (Throwable t)
                         {
@@ -124,22 +126,17 @@ public class QueryHandler implements Serializable, InvocationHandler
         }
         else
         {
-            return process(proxy, method, args);
+            return process(proxy, method, args, repositoryMetadata, repositoryMethodMetadata);
         }
     }
 
-    public Object process(Object proxy, Method method, Object[] args) throws Throwable
+    protected Object process(Object proxy, Method method, Object[] args,
+            RepositoryMetadata repositoryMetadata, RepositoryMethodMetadata repositoryMethodMetadata)
throws Throwable
     {
         CdiQueryInvocationContext queryContext = null;
         EntityManagerRef entityManagerRef = null;
         try
         {
-            List<Class<?>> candidates = ProxyUtils.getProxyAndBaseTypes(proxy.getClass());
-            RepositoryMetadata repositoryMetadata =
-                    metadataHandler.lookupComponent(candidates);
-            RepositoryMethodMetadata repositoryMethodMetadata =
-                    metadataHandler.lookupMethod(repositoryMetadata, method);
-
             entityManagerRef = entityManagerRefLookup.lookupReference(repositoryMetadata);
             queryContext = createContext(proxy, method, args, entityManagerRef.getEntityManager(),
                     repositoryMetadata, repositoryMethodMetadata);
@@ -178,7 +175,7 @@ public class QueryHandler implements Serializable, InvocationHandler
         CdiQueryInvocationContext queryContext = new CdiQueryInvocationContext(proxy, method,
args,
                 repositoryMetadata, repositoryMethodMetadata, entityManager);
         context.set(queryContext);
-        queryContext.initMapper();
+        queryContext.init();
         return queryContext;
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4965c176/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
index 3fd2a76..2c03aa8 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataHandler.java
@@ -60,7 +60,7 @@ public class RepositoryMetadataHandler
      * @param candidateClasses List of candidates to check.
      * @return A {@link RepositoryMetadataInitializer}.
      */
-    public RepositoryMetadata lookupComponent(List<Class<?>> candidateClasses)
+    public RepositoryMetadata lookupMetadata(List<Class<?>> candidateClasses)
     {
         for (Class<?> repoClass : candidateClasses)
         {
@@ -78,7 +78,7 @@ public class RepositoryMetadataHandler
      * @param repositoryClass The repository class to lookup the method for
      * @return A {@link RepositoryMetadata}.
      */
-    public RepositoryMetadata lookupComponent(Class<?> repositoryClass)
+    public RepositoryMetadata lookupMetadata(Class<?> repositoryClass)
     {
         if (repositoriesMetadata.containsKey(repositoryClass))
         {
@@ -94,7 +94,7 @@ public class RepositoryMetadataHandler
      * @param method The method object to get Repository meta data for.
      * @return A {@link RepositoryMethodMetadata}.
      */
-    public RepositoryMethodMetadata lookupMethod(RepositoryMetadata repositoryMetadata, Method
method)
+    public RepositoryMethodMetadata lookupMethodMetadata(RepositoryMetadata repositoryMetadata,
Method method)
     {
         return repositoryMetadata.getMethodsMetadata().get(method);
     }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4965c176/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
index c2755b5..2ddcc6d 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryMetadataInitializer.java
@@ -83,12 +83,12 @@ public class RepositoryMetadataInitializer
 
         for (Class<?> implemented : allImplemented)
         {
-            Method[] repoClassMethods = implemented.getDeclaredMethods();
-            for (Method repoClassMethod : repoClassMethods)
+            Method[] repositoryMethods = implemented.getDeclaredMethods();
+            for (Method repositoryMethod : repositoryMethods)
             {
                 RepositoryMethodMetadata methodMetadata =
-                        methodMetadataInitializer.init(repositoryMetadata, repoClassMethod,
beanManager);
-                repositoryMetadata.getMethodsMetadata().put(repoClassMethod, methodMetadata);
+                        methodMetadataInitializer.init(repositoryMetadata, repositoryMethod,
beanManager);
+                repositoryMetadata.getMethodsMetadata().put(repositoryMethod, methodMetadata);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4965c176/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 8f00568..cf12f42 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
@@ -25,6 +25,7 @@ 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;
+import org.apache.deltaspike.jpa.api.transaction.Transactional;
 
 public class RepositoryMethodMetadata
 {
@@ -47,6 +48,8 @@ public class RepositoryMethodMetadata
     private SingleResultType singleResultType;
     
     private boolean requiresTransaction;
+    
+    private Transactional transactional;
 
     public RepositoryMethodMetadata()
     {
@@ -187,4 +190,14 @@ public class RepositoryMethodMetadata
     {
         this.requiresTransaction = requiresTransaction;
     }
+
+    public Transactional getTransactional()
+    {
+        return transactional;
+    }
+
+    public void setTransactional(Transactional transactional)
+    {
+        this.transactional = transactional;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4965c176/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 969be6d..da0ef0e 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
@@ -30,6 +30,7 @@ import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
 import javax.persistence.LockModeType;
+import org.apache.deltaspike.core.util.AnnotationUtils;
 import org.apache.deltaspike.core.util.ClassUtils;
 
 import org.apache.deltaspike.core.util.OptionalUtil;
@@ -44,6 +45,7 @@ import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
 import org.apache.deltaspike.data.impl.builder.part.QueryRoot;
 import org.apache.deltaspike.data.impl.builder.result.QueryProcessorFactory;
 import org.apache.deltaspike.data.impl.handler.EntityRepositoryHandler;
+import org.apache.deltaspike.jpa.api.transaction.Transactional;
 
 @ApplicationScoped
 public class RepositoryMethodMetadataInitializer
@@ -51,6 +53,9 @@ public class RepositoryMethodMetadataInitializer
     @Inject
     private QueryProcessorFactory queryProcessorFactory;
     
+    @Inject
+    private BeanManager beanManager;
+    
     public RepositoryMethodMetadata init(RepositoryMetadata repositoryMetadata, Method method,
BeanManager beanManager)
     {
         RepositoryMethodMetadata repositoryMethodMetadata = new RepositoryMethodMetadata();
@@ -66,6 +71,9 @@ public class RepositoryMethodMetadataInitializer
                 ? method.getAnnotation(Query.class) : null);
         repositoryMethodMetadata.setModifying(method.isAnnotationPresent(Modifying.class)
                 ? method.getAnnotation(Modifying.class) : null);
+        
+        repositoryMethodMetadata.setTransactional(AnnotationUtils.extractAnnotationFromMethodOrClass(
+                beanManager, method, repositoryMetadata.getRepositoryClass(), Transactional.class));
 
         repositoryMethodMetadata.setMethodPrefix(new RepositoryMethodPrefix(
                     repositoryMetadata.getRepositoryClass().getAnnotation(Repository.class).methodPrefix(),


Mime
View raw message