deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-1062 @Transactional and @TransactionScoped support for @Repository including qualifiers
Date Fri, 08 Jan 2016 02:57:12 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 530dc72c8 -> d14eb560c


DELTASPIKE-1062 @Transactional and @TransactionScoped support for @Repository including qualifiers


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

Branch: refs/heads/master
Commit: d14eb560c47e4a875df452c9df088cf38af7ab92
Parents: 530dc72
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Jan 8 03:49:21 2016 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Jan 8 03:54:33 2016 +0100

----------------------------------------------------------------------
 .../data/impl/handler/EntityManagerLookup.java  |  9 ++++
 .../data/impl/handler/QueryHandler.java         | 46 +++++++++++++++-----
 2 files changed, 43 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d14eb560/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerLookup.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerLookup.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerLookup.java
index 3a78393..5970544 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerLookup.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityManagerLookup.java
@@ -28,6 +28,7 @@ import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.api.provider.DependentProvider;
 import org.apache.deltaspike.data.api.EntityManagerResolver;
 import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
+import org.apache.deltaspike.jpa.spi.entitymanager.ActiveEntityManagerHolder;
 
 public class EntityManagerLookup
 {
@@ -36,6 +37,9 @@ public class EntityManagerLookup
     @Any
     private Instance<EntityManager> entityManager;
 
+    @Inject
+    private ActiveEntityManagerHolder activeEntityManagerHolder;
+
     private DependentProvider<? extends EntityManagerResolver> dependentResolverProvider;
 
     public EntityManager lookupFor(final RepositoryComponent repository)
@@ -57,6 +61,11 @@ public class EntityManagerLookup
         }
         else
         {
+            if (activeEntityManagerHolder.isSet())
+            {
+                return activeEntityManagerHolder.get();
+            }
+
             result = entityManager.select(new DefaultLiteral()).get();
         }
         if (repository.hasEntityManagerFlushMode())

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d14eb560/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 86b018e..5858f16 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
@@ -18,22 +18,13 @@
  */
 package org.apache.deltaspike.data.impl.handler;
 
-import java.io.Serializable;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-import javax.persistence.PersistenceException;
-
 import org.apache.deltaspike.core.api.lifecycle.Initialized;
-import org.apache.deltaspike.core.util.interceptor.AbstractInvocationContext;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.util.AnnotationUtils;
 import org.apache.deltaspike.core.util.ExceptionUtils;
 import org.apache.deltaspike.core.util.ProxyUtils;
+import org.apache.deltaspike.core.util.interceptor.AbstractInvocationContext;
+import org.apache.deltaspike.core.util.metadata.AnnotationInstanceProvider;
 import org.apache.deltaspike.data.api.QueryInvocationException;
 import org.apache.deltaspike.data.api.Repository;
 import org.apache.deltaspike.data.impl.builder.QueryBuilder;
@@ -42,8 +33,22 @@ import org.apache.deltaspike.data.impl.meta.RepositoryComponent;
 import org.apache.deltaspike.data.impl.meta.RepositoryComponents;
 import org.apache.deltaspike.data.impl.meta.RepositoryMethod;
 import org.apache.deltaspike.jpa.api.transaction.Transactional;
+import org.apache.deltaspike.jpa.spi.entitymanager.ActiveEntityManagerHolder;
 import org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy;
 
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 /**
  * Entry point for query processing.
  */
@@ -77,6 +82,9 @@ public class QueryHandler implements Serializable, InvocationHandler
     @Inject
     private TransactionStrategy transactionStrategy;
 
+    @Inject
+    private ActiveEntityManagerHolder activeEntityManagerHolder;
+
     @Override
     public Object invoke(final Object proxy, final Method method, final Object[] args) throws
Throwable
     {
@@ -86,6 +94,20 @@ public class QueryHandler implements Serializable, InvocationHandler
 
         if (transactionalAnnotation != null)
         {
+            if (transactionalAnnotation.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];
+            if (!Any.class.equals(qualifier))
+            {
+                EntityManager entityManager = BeanProvider.getContextualReference(
+                    EntityManager.class, false, AnnotationInstanceProvider.of(qualifier));
+                activeEntityManagerHolder.set(entityManager);
+            }
+
             return transactionStrategy.execute(
                 new AbstractInvocationContext<Object>(proxy, method, args, null)
                 {


Mime
View raw message