You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/04/27 15:50:31 UTC

tomee git commit: TOMEE-1562 more direct scanning for configuration deployer, no need to rely on internal booleans

Repository: tomee
Updated Branches:
  refs/heads/master 0eec790bc -> b60431be6


TOMEE-1562 more direct scanning for configuration deployer, no need to rely on internal booleans


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

Branch: refs/heads/master
Commit: b60431be6d709d144f4a1fcc6af44b1d2c6a2c5f
Parents: 0eec790
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Mon Apr 27 15:49:59 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Mon Apr 27 15:49:59 2015 +0200

----------------------------------------------------------------------
 .../openejb/config/AnnotationDeployer.java      | 58 +++++++++++---------
 .../openejb/config/ConfigurationDeployer.java   | 58 +++++++++++---------
 2 files changed, 62 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/b60431be/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
index 1419953..00adadc 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
@@ -1874,39 +1874,43 @@ public class AnnotationDeployer implements DynamicDeployer {
                 for (final org.apache.openejb.jee.jpa.unit.PersistenceUnit pu : pm.getPersistence().getPersistenceUnit()) {
                     if ((pu.isExcludeUnlistedClasses() == null || !pu.isExcludeUnlistedClasses())
                         && "true".equalsIgnoreCase(pu.getProperties().getProperty(OPENEJB_JPA_AUTO_SCAN))) {
-                        final String packageName = pu.getProperties().getProperty(OPENEJB_JPA_AUTO_SCAN_PACKAGE);
-                        String[] packageNames = null;
-                        if (packageName != null) {
-                            packageNames = packageName.split(",");
-                        }
+                        doAutoJpa(finder, pu);
+                    }
+                }
+            }
+        }
+    }
 
-                        // no need of meta currently since JPA providers doesn't support it
-                        final List<Class<?>> classes = new ArrayList<Class<?>>();
-                        classes.addAll(finder.findAnnotatedClasses(Entity.class));
-                        classes.addAll(finder.findAnnotatedClasses(Embeddable.class));
-                        classes.addAll(finder.findAnnotatedClasses(MappedSuperclass.class));
-                        final List<String> existingClasses = pu.getClazz();
-                        for (final Class<?> clazz : classes) {
-                            final String name = clazz.getName();
-                            if (existingClasses.contains(name)) {
-                                continue;
-                            }
+    public static void doAutoJpa(final IAnnotationFinder finder, final org.apache.openejb.jee.jpa.unit.PersistenceUnit pu) {
+        final String packageName = pu.getProperties().getProperty(OPENEJB_JPA_AUTO_SCAN_PACKAGE);
+        String[] packageNames = null;
+        if (packageName != null) {
+            packageNames = packageName.split(",");
+        }
 
-                            if (packageNames == null) {
-                                pu.getClazz().add(name);
-                            } else {
-                                for (final String pack : packageNames) {
-                                    if (name.startsWith(pack)) {
-                                        pu.getClazz().add(name);
-                                    }
-                                }
-                            }
-                        }
-                        pu.setScanned(true);
+        // no need of meta currently since JPA providers doesn't support it
+        final List<Class<?>> classes = new ArrayList<Class<?>>();
+        classes.addAll(finder.findAnnotatedClasses(Entity.class));
+        classes.addAll(finder.findAnnotatedClasses(Embeddable.class));
+        classes.addAll(finder.findAnnotatedClasses(MappedSuperclass.class));
+        final List<String> existingClasses = pu.getClazz();
+        for (final Class<?> clazz : classes) {
+            final String name = clazz.getName();
+            if (existingClasses.contains(name)) {
+                continue;
+            }
+
+            if (packageNames == null) {
+                pu.getClazz().add(name);
+            } else {
+                for (final String pack : packageNames) {
+                    if (name.startsWith(pack)) {
+                        pu.getClazz().add(name);
                     }
                 }
             }
         }
+        pu.setScanned(true);
     }
 
     public static class ProcessAnnotatedBeans implements DynamicDeployer {

http://git-wip-us.apache.org/repos/asf/tomee/blob/b60431be/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationDeployer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationDeployer.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationDeployer.java
index 75f9d26..80eab0c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationDeployer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationDeployer.java
@@ -25,6 +25,7 @@ import org.apache.openejb.jee.jpa.unit.TransactionType;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.PropertyPlaceHolderHelper;
+import org.apache.xbean.finder.IAnnotationFinder;
 
 import java.util.ArrayList;
 import javax.persistence.Entity;
@@ -37,45 +38,46 @@ public class ConfigurationDeployer implements DynamicDeployer {
                 continue;
             }
 
-            boolean scan = false;
+            EjbModule m = null;
             for (final Class<?> configClass : module.getFinder().findAnnotatedClasses(PersistenceUnitDefinition.class)) {
-                configureJpa(appModule, configClass.getAnnotation(PersistenceUnitDefinition.class));
-                scan = true;
+                m = m == null ? findModule(appModule, module) : m;
+                configureJpa(appModule, configClass.getAnnotation(PersistenceUnitDefinition.class), m.getFinder());
             }
             for (final Class<?> configClass : module.getFinder().findAnnotatedClasses(PersistenceUnitDefinitions.class)) {
                 for (final PersistenceUnitDefinition persistenceUnitDefinition : configClass.getAnnotation(PersistenceUnitDefinitions.class).value()) {
-                    configureJpa(appModule, persistenceUnitDefinition);
-                    scan = true;
+                    m = m == null ? findModule(appModule, module) : m;
+                    configureJpa(appModule, persistenceUnitDefinition, m.getFinder());
                 }
             }
-            if (scan) {
-                EjbModule m = module;
-                if (m.getFinder().findAnnotatedClasses(Entity.class).isEmpty()) {
-                    // switch to another module
-                    for (final EjbModule other : appModule.getEjbModules()) {
-                        if (other == module || other.getFinder() == null) {
-                            continue;
-                        }
-                        m = other;
-                        boolean done = false;
-                        for (final WebModule web : appModule.getWebModules()) {
-                            if (web.getModuleId().equals(other.getModuleId())) { // the biggest module is found, use it
-                                done = true;
-                                break;
-                            }
-                        }
-                        if (done) {
-                            break;
-                        }
+        }
+        return appModule;
+    }
+
+    private EjbModule findModule(final AppModule appModule, final EjbModule module) {
+        EjbModule m = module;
+        if (m.getFinder().findAnnotatedClasses(Entity.class).isEmpty()) {
+            // switch to another module
+            for (final EjbModule other : appModule.getEjbModules()) {
+                if (other == module || other.getFinder() == null) {
+                    continue;
+                }
+                m = other;
+                boolean done = false;
+                for (final WebModule web : appModule.getWebModules()) {
+                    if (web.getModuleId().equals(other.getModuleId())) { // the biggest module is found, use it
+                        done = true;
+                        break;
                     }
                 }
-                AnnotationDeployer.autoJpa(m); // we pass after annotation deployer so need to fill it ourself
+                if (done) {
+                    break;
+                }
             }
         }
-        return appModule;
+        return m;
     }
 
-    private void configureJpa(final AppModule appModule, final PersistenceUnitDefinition annotation) {
+    private void configureJpa(final AppModule appModule, final PersistenceUnitDefinition annotation, final IAnnotationFinder finder) {
         if (annotation == null) {
             return;
         }
@@ -122,6 +124,8 @@ public class ConfigurationDeployer implements DynamicDeployer {
         unit.setValidationMode(annotation.validationMode());
         unit.setSharedCacheMode(annotation.cacheMode());
 
+        AnnotationDeployer.doAutoJpa(finder, unit); // we pass after annotation deployer so need to fill it ourself
+
         final Persistence persistence = new Persistence();
         persistence.addPersistenceUnit(unit);
         appModule.addPersistenceModule(new PersistenceModule(appModule, "@Configuration#" + unitName, persistence));