deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-434 fixed RepositoryComponent
Date Fri, 01 Nov 2013 21:18:13 GMT
Updated Branches:
  refs/heads/master 4a3da4053 -> f724794a4


DELTASPIKE-434 fixed RepositoryComponent


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

Branch: refs/heads/master
Commit: f724794a4d7e918c009f2d3282c4dd3282467c03
Parents: 4a3da40
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Nov 1 22:15:00 2013 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Nov 1 22:15:37 2013 +0100

----------------------------------------------------------------------
 .../data/impl/RepositoryExtension.java          |  4 ++--
 .../data/impl/meta/RepositoryComponent.java     | 25 ++++++++++++++++++--
 .../data/impl/meta/RepositoryComponents.java    |  5 ++--
 .../data/impl/builder/part/QueryRootTest.java   |  4 ++--
 4 files changed, 29 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f724794a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
index 8ba0dca..ef098fd 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
@@ -63,7 +63,7 @@ public class RepositoryExtension implements Extension
         PersistenceUnits.instance().init();
     }
 
-    <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event, BeanManager
beanManager)
+    <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event)
     {
         if (isRepository(event.getAnnotatedType()))
         {
@@ -72,7 +72,7 @@ public class RepositoryExtension implements Extension
             {
                 log.log(Level.FINER, "getHandlerClass: Repository annotation detected on
{0}",
                         event.getAnnotatedType());
-                RepositoryComponentsFactory.instance().add(repoClass, beanManager);
+                RepositoryComponentsFactory.instance().add(repoClass);
             }
             catch (RepositoryDefinitionException e)
             {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f724794a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
index 5acee4e..2943555 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponent.java
@@ -34,6 +34,7 @@ import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.persistence.FlushModeType;
 
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
 import org.apache.deltaspike.data.api.EntityManagerConfig;
 import org.apache.deltaspike.data.api.EntityManagerResolver;
 import org.apache.deltaspike.data.api.Repository;
@@ -53,15 +54,16 @@ public class RepositoryComponent
 
     private static final Logger log = Logger.getLogger(RepositoryComponent.class.getName());
 
+    private volatile Boolean entityManagerResolverIsNormalScope;
+
     private final Class<?> repoClass;
     private final RepositoryEntity entityClass;
     private final Class<? extends EntityManagerResolver> entityManagerResolver;
-    private final boolean entityManagerResolverIsNormalScope;
     private final FlushModeType entityManagerFlushMode;
 
     private final Map<Method, RepositoryMethod> methods = new HashMap<Method, RepositoryMethod>();
 
-    public RepositoryComponent(Class<?> repoClass, RepositoryEntity entityClass, BeanManager
beanManager)
+    public RepositoryComponent(Class<?> repoClass, RepositoryEntity entityClass)
     {
         if (entityClass == null)
         {
@@ -71,6 +73,23 @@ public class RepositoryComponent
         this.entityClass = entityClass;
         this.entityManagerResolver = extractEntityManagerResolver(repoClass);
         this.entityManagerFlushMode = extractEntityManagerFlushMode(repoClass);
+    }
+
+    //don't trigger this lookup during ProcessAnnotatedType
+    private void lazyInit()
+    {
+        if (entityManagerResolverIsNormalScope == null)
+        {
+            init(BeanManagerProvider.getInstance().getBeanManager());
+        }
+    }
+
+    private synchronized void init(BeanManager beanManager)
+    {
+        if (entityManagerResolverIsNormalScope != null)
+        {
+            return;
+        }
 
         if (entityManagerResolver != null && beanManager != null)
         {
@@ -88,6 +107,7 @@ public class RepositoryComponent
 
     public boolean isEntityManagerResolverIsNormalScope()
     {
+        lazyInit();
         return entityManagerResolverIsNormalScope;
     }
 
@@ -104,6 +124,7 @@ public class RepositoryComponent
      */
     public RepositoryMethod lookupMethod(Method method)
     {
+        lazyInit();
         return methods.get(method);
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f724794a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
index 1bc12db..1686e31 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/RepositoryComponents.java
@@ -23,7 +23,6 @@ import org.apache.deltaspike.data.impl.meta.extractor.AnnotationMetadataExtracto
 import org.apache.deltaspike.data.impl.meta.extractor.MetadataExtractor;
 import org.apache.deltaspike.data.impl.meta.extractor.TypeMetadataExtractor;
 
-import javax.enterprise.inject.spi.BeanManager;
 import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.util.Arrays;
@@ -52,10 +51,10 @@ public class RepositoryComponents implements Serializable
      * @param repoClass  The repo class.
      * @return {@code true} if Repository class has been added, {@code false} otherwise.
      */
-    public void add(Class<?> repoClass, BeanManager bm)
+    public void add(Class<?> repoClass)
     {
         RepositoryEntity entityClass = extractEntityMetaData(repoClass);
-        RepositoryComponent repo = new RepositoryComponent(repoClass, entityClass, bm);
+        RepositoryComponent repo = new RepositoryComponent(repoClass, entityClass);
         repos.put(repoClass, repo);
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f724794a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
index 1c70466..4279e62 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
@@ -30,8 +30,8 @@ import org.junit.Test;
 
 public class QueryRootTest
 {
-    private final RepositoryComponent repo = new RepositoryComponent(SimpleRepository.class,
new RepositoryEntity(Simple.class, Long.class), null);
-    private final RepositoryComponent repoFetchBy = new RepositoryComponent(SimpleFetchRepository.class,
new RepositoryEntity(Simple.class, Long.class), null);
+    private final RepositoryComponent repo = new RepositoryComponent(SimpleRepository.class,
new RepositoryEntity(Simple.class, Long.class));
+    private final RepositoryComponent repoFetchBy = new RepositoryComponent(SimpleFetchRepository.class,
new RepositoryEntity(Simple.class, Long.class));
 
     @Test
     public void should_create_simple_query()


Mime
View raw message