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 requiresTransaction per method
Date Wed, 07 Jun 2017 21:36:46 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 762d3a53b -> a551978c2


DELTASPIKE-1270 [perf] cache requiresTransaction per method

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

Branch: refs/heads/master
Commit: a551978c2510be4397fae94a9c97056c5be2d5f9
Parents: 762d3a5
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Wed Jun 7 23:36:38 2017 +0200
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Wed Jun 7 23:36:38 2017 +0200

----------------------------------------------------------------------
 .../impl/meta/RepositoryMethodMetadata.java     | 12 ++++++++
 .../RepositoryMethodMetadataInitializer.java    | 27 +++++++++++++++++
 .../data/impl/tx/TransactionalQueryRunner.java  | 31 +-------------------
 3 files changed, 40 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a551978c/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 84d528c..8f00568 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
@@ -45,6 +45,8 @@ public class RepositoryMethodMetadata
     private boolean returnsStream;
     
     private SingleResultType singleResultType;
+    
+    private boolean requiresTransaction;
 
     public RepositoryMethodMetadata()
     {
@@ -175,4 +177,14 @@ public class RepositoryMethodMetadata
     {
         this.singleResultType = singleResultType;
     }
+
+    public boolean isRequiresTransaction()
+    {
+        return requiresTransaction;
+    }
+
+    public void setRequiresTransaction(boolean requiresTransaction)
+    {
+        this.requiresTransaction = requiresTransaction;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a551978c/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 74f1dc0..5d94b39 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
@@ -29,6 +29,8 @@ import javax.enterprise.context.ApplicationScoped;
 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.ClassUtils;
 
 import org.apache.deltaspike.core.util.OptionalUtil;
 import org.apache.deltaspike.core.util.StreamUtil;
@@ -41,6 +43,7 @@ import org.apache.deltaspike.data.api.mapping.QueryInOutMapper;
 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;
 
 @ApplicationScoped
 public class RepositoryMethodMetadataInitializer
@@ -79,6 +82,7 @@ public class RepositoryMethodMetadataInitializer
         initQueryInOutMapperIsNormalScope(repositoryMetadata, repositoryMethodMetadata, beanManager);
 
         initSingleResultType(repositoryMethodMetadata);
+        initRequiresTransaction(repositoryMethodMetadata);
 
         
         return repositoryMethodMetadata;
@@ -193,4 +197,27 @@ public class RepositoryMethodMetadataInitializer
         }
     }
     
+    private void initRequiresTransaction(RepositoryMethodMetadata repositoryMethodMetadata)
+    {
+        boolean requiresTransaction = false;
+        
+        if (ClassUtils.containsMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod()))
+        {
+            Method executed = ClassUtils.extractMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod());
+            if (executed.isAnnotationPresent(RequiresTransaction.class))
+            {
+                requiresTransaction = true;
+            }
+        }
+
+        Query query = repositoryMethodMetadata.getQuery();
+        Modifying modifying = repositoryMethodMetadata.getModifying();
+        
+        if ((query != null && !query.lock().equals(LockModeType.NONE)) || modifying
!= null)
+        {
+            requiresTransaction = true;
+        }
+        
+        repositoryMethodMetadata.setRequiresTransaction(requiresTransaction);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a551978c/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
index fe89dbe..f91418c 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunner.java
@@ -18,20 +18,13 @@
  */
 package org.apache.deltaspike.data.impl.tx;
 
-import java.lang.reflect.Method;
 import javax.enterprise.context.ApplicationScoped;
 
 import javax.inject.Inject;
-import javax.persistence.LockModeType;
-import org.apache.deltaspike.core.util.ClassUtils;
-import org.apache.deltaspike.data.api.Modifying;
-import org.apache.deltaspike.data.api.Query;
 
 import org.apache.deltaspike.data.impl.builder.QueryBuilder;
 import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext;
-import org.apache.deltaspike.data.impl.handler.EntityRepositoryHandler;
 import org.apache.deltaspike.data.impl.handler.QueryRunner;
-import org.apache.deltaspike.data.impl.meta.RequiresTransaction;
 import org.apache.deltaspike.jpa.spi.entitymanager.ActiveEntityManagerHolder;
 import org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy;
 
@@ -49,7 +42,7 @@ public class TransactionalQueryRunner implements QueryRunner
     public Object executeQuery(final QueryBuilder builder, final CdiQueryInvocationContext
context)
         throws Throwable
     {
-        if (needsTransaction(context))
+        if (context.getRepositoryMethodMetadata().isRequiresTransaction())
         {
             try
             {
@@ -82,26 +75,4 @@ public class TransactionalQueryRunner implements QueryRunner
         });
     }
 
-    private boolean needsTransaction(CdiQueryInvocationContext context)
-    {
-        if (ClassUtils.containsMethod(EntityRepositoryHandler.class, context.getMethod()))
-        {
-            Method executed = ClassUtils.extractMethod(EntityRepositoryHandler.class, context.getMethod());
-            if (executed.isAnnotationPresent(RequiresTransaction.class))
-            {
-                return true;
-            }
-        }
-
-        Query query = context.getRepositoryMethodMetadata().getQuery();
-        Modifying modifying = context.getRepositoryMethodMetadata().getModifying();
-        
-        if ((query != null && !query.lock().equals(LockModeType.NONE)) || modifying
!= null)
-        {
-            return true;
-        }
-        
-        return false;
-    }
-
 }


Mime
View raw message