openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1414398 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa: conf/Compatibility.java meta/MetaDataRepository.java
Date Tue, 27 Nov 2012 20:51:45 GMT
Author: jgrassel
Date: Tue Nov 27 20:51:44 2012
New Revision: 1414398

URL: http://svn.apache.org/viewvc?rev=1414398&view=rev
Log:
OPENJPA-2288: MetaDataRepository should be able to filter classes from other app ClassLoaders
in JEE Env

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java?rev=1414398&r1=1414397&r2=1414398&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
Tue Nov 27 20:51:44 2012
@@ -75,6 +75,7 @@ public class Compatibility {
     private boolean _metaFactoriesAreStrict = false; 
     private boolean _resetFlushFlagForCascadePersist = true;//OPENJPA-2051
     private boolean _singletonLifecycleEventManager = false;
+    private boolean _filterPCRegistryClasses = false; // OPENJPA-2288
     
     /**
      * Whether to require exact identity value types when creating object
@@ -713,4 +714,18 @@ public class Compatibility {
     public void setSingletonLifecycleEventManager(boolean singleton) {
         _singletonLifecycleEventManager = singleton;
     }
+    
+    /**
+     * Whether the metadata processor should filter classes dispatched by the PCRegistry
listener system.
+     **/
+    public boolean  getFilterPCRegistryClasses() {
+        return _filterPCRegistryClasses; 
+    }
+     
+    /**
+     * Whether the metadata processor should filter classes dispatched by the PCRegistry
listener system.
+     **/
+    public void setFilterPCRegistryClasses(boolean bool) {
+        _filterPCRegistryClasses = bool;
+    }
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=1414398&r1=1414397&r2=1414398&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Tue Nov 27 20:51:44 2012
@@ -162,6 +162,9 @@ public class MetaDataRepository implemen
     // Entities.
     private boolean _logEnhancementLevel = true;
 
+    // A boolean used to decide whether to filter Class<?> objects submitted by the
PCRegistry listener system
+    private boolean _filterRegisteredClasses = false;
+    
     /**
      * Default constructor. Configure via {@link Configurable}.
      */
@@ -1635,10 +1638,41 @@ public class MetaDataRepository implemen
         Collection<String> pcNames = getPersistentTypeNames(false, envLoader);
         Collection<Class<?>> failed = null;
         for (int i = 0; i < reg.length; i++) {
-            // don't process types that aren't listed by the user; may belong
-            // to a different persistence unit
-            if (pcNames != null && !pcNames.isEmpty() && !pcNames.contains(reg[i].getName()))
+            // Don't process types that aren't listed by the user; it may belong to a different
persistence unit.
+            if (pcNames != null && !pcNames.isEmpty() && !pcNames.contains(reg[i].getName()))
{
                 continue;
+            }
+            
+            // If the compatibility option "filterPCRegistryClasses" is enabled, then verify
that the type is
+            // accessible to the envLoader/Thread Context ClassLoader
+            if (_filterRegisteredClasses) {
+                Log log = (_conf == null) ? null : _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+                ClassLoader loadCL = (envLoader != null) ?
+                        envLoader :
+                        AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction());
+                        
+                try {
+                    Class<?> classFromAppClassLoader = Class.forName(reg[i].getName(),
true, loadCL);
+                    
+                    if (!reg[i].equals(classFromAppClassLoader)) {
+                        // This is a class that belongs to a ClassLoader not associated with
the Application,
+                        // so it should be processed.
+                        if (log != null && log.isTraceEnabled()) {
+                            log.trace(
+                                "Metadata Repository will ignore Class " + reg[i].getName()
+ 
+                                ", since it originated from a ClassLoader not associated
with the application.");
+                        }
+                        continue;
+                    }
+                } catch (ClassNotFoundException cnfe) {
+                    // Catch exception and log its occurrence, and permit MDR processing
to continue to preserve
+                    // original behavior.
+                    if (log != null && log.isTraceEnabled()) {
+                        log.trace("The Class " + reg[i].getName() + " was identified as a
persistent class " +
+                            "by configuration, but the Class could not be found.");
+                    }
+                }
+            }
 
             checkEnhancementLevel(reg[i]);
             try {
@@ -1878,6 +1912,7 @@ public class MetaDataRepository implemen
     public void setConfiguration(Configuration conf) {
         _conf = (OpenJPAConfiguration) conf;
         _log = _conf.getLog(OpenJPAConfiguration.LOG_METADATA);
+        _filterRegisteredClasses = _conf.getCompatibilityInstance().getFilterPCRegistryClasses();
     }
 
     public void startConfiguration() {



Mime
View raw message