mirror of https://github.com/apache/openjpa.git
OPENJPA-2288: MetaDataRepository should be able to filter classes from other app ClassLoaders in JEE Env
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1414398 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e0d5b0505f
commit
89b44bbf6c
|
@ -75,6 +75,7 @@ public class Compatibility {
|
||||||
private boolean _metaFactoriesAreStrict = false;
|
private boolean _metaFactoriesAreStrict = false;
|
||||||
private boolean _resetFlushFlagForCascadePersist = true;//OPENJPA-2051
|
private boolean _resetFlushFlagForCascadePersist = true;//OPENJPA-2051
|
||||||
private boolean _singletonLifecycleEventManager = false;
|
private boolean _singletonLifecycleEventManager = false;
|
||||||
|
private boolean _filterPCRegistryClasses = false; // OPENJPA-2288
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to require exact identity value types when creating object
|
* Whether to require exact identity value types when creating object
|
||||||
|
@ -713,4 +714,18 @@ public class Compatibility {
|
||||||
public void setSingletonLifecycleEventManager(boolean singleton) {
|
public void setSingletonLifecycleEventManager(boolean singleton) {
|
||||||
_singletonLifecycleEventManager = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,6 +162,9 @@ public class MetaDataRepository implements PCRegistry.RegisterClassListener, Con
|
||||||
// Entities.
|
// Entities.
|
||||||
private boolean _logEnhancementLevel = true;
|
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}.
|
* Default constructor. Configure via {@link Configurable}.
|
||||||
*/
|
*/
|
||||||
|
@ -1635,10 +1638,41 @@ public class MetaDataRepository implements PCRegistry.RegisterClassListener, Con
|
||||||
Collection<String> pcNames = getPersistentTypeNames(false, envLoader);
|
Collection<String> pcNames = getPersistentTypeNames(false, envLoader);
|
||||||
Collection<Class<?>> failed = null;
|
Collection<Class<?>> failed = null;
|
||||||
for (int i = 0; i < reg.length; i++) {
|
for (int i = 0; i < reg.length; i++) {
|
||||||
// don't process types that aren't listed by the user; may belong
|
// Don't process types that aren't listed by the user; it may belong to a different persistence unit.
|
||||||
// to a different persistence unit
|
if (pcNames != null && !pcNames.isEmpty() && !pcNames.contains(reg[i].getName())) {
|
||||||
if (pcNames != null && !pcNames.isEmpty() && !pcNames.contains(reg[i].getName()))
|
|
||||||
continue;
|
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]);
|
checkEnhancementLevel(reg[i]);
|
||||||
try {
|
try {
|
||||||
|
@ -1878,6 +1912,7 @@ public class MetaDataRepository implements PCRegistry.RegisterClassListener, Con
|
||||||
public void setConfiguration(Configuration conf) {
|
public void setConfiguration(Configuration conf) {
|
||||||
_conf = (OpenJPAConfiguration) conf;
|
_conf = (OpenJPAConfiguration) conf;
|
||||||
_log = _conf.getLog(OpenJPAConfiguration.LOG_METADATA);
|
_log = _conf.getLog(OpenJPAConfiguration.LOG_METADATA);
|
||||||
|
_filterRegisteredClasses = _conf.getCompatibilityInstance().getFilterPCRegistryClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startConfiguration() {
|
public void startConfiguration() {
|
||||||
|
|
Loading…
Reference in New Issue