mirror of https://github.com/apache/openjpa.git
[OPENJPA-2834] ensure getProperties does not fail with xmlstore
This commit is contained in:
parent
4a546f759c
commit
9fa619f94e
|
@ -2023,6 +2023,9 @@ public class OpenJPAConfigurationImpl
|
|||
|
||||
@Override
|
||||
public FinderCache getFinderCacheInstance() {
|
||||
if (finderCachePlugin == null) { // xmlstore case
|
||||
return null;
|
||||
}
|
||||
if (finderCachePlugin.get() == null) {
|
||||
finderCachePlugin.instantiate(FinderCache.class, this);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@ public class PCClassFileTransformer
|
|||
private final ClassLoader _tmpLoader;
|
||||
private final Log _log;
|
||||
private final Set _names;
|
||||
private boolean _transforming = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -104,6 +103,13 @@ public class PCClassFileTransformer
|
|||
_log.info(_loc.get("runtime-enhance-pcclasses"));
|
||||
}
|
||||
|
||||
public static PCClassFileTransformer newInstance(final MetaDataRepository repos, final Options parseProperties,
|
||||
final ClassLoader tmpLoader) {
|
||||
return parseProperties != null && parseProperties.getBooleanProperty("Reentrant") ?
|
||||
new PCClassFileTransformer.Reentrant(repos, parseProperties, tmpLoader) :
|
||||
new PCClassFileTransformer(repos, parseProperties, tmpLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader loader, String className, Class redef, ProtectionDomain domain, byte[] bytes)
|
||||
throws IllegalClassFormatException {
|
||||
|
@ -115,14 +121,6 @@ public class PCClassFileTransformer
|
|||
if (className == null) {
|
||||
return null;
|
||||
}
|
||||
// prevent re-entrant calls, which can occur if the enhancing
|
||||
// loader is used to also load OpenJPA libraries; this is to prevent
|
||||
// recursive enhancement attempts for internal openjpa libraries
|
||||
if (_transforming)
|
||||
return null;
|
||||
|
||||
_transforming = true;
|
||||
|
||||
return transform0(className, redef, bytes);
|
||||
}
|
||||
|
||||
|
@ -131,7 +129,7 @@ public class PCClassFileTransformer
|
|||
* ClassCircularityError when executing method using pure-JIT JVMs
|
||||
* such as JRockit.
|
||||
*/
|
||||
private byte[] transform0(String className, Class redef, byte[] bytes)
|
||||
protected byte[] transform0(String className, Class redef, byte[] bytes)
|
||||
throws IllegalClassFormatException {
|
||||
|
||||
byte[] returnBytes = null;
|
||||
|
@ -169,7 +167,6 @@ public class PCClassFileTransformer
|
|||
throw (IllegalClassFormatException) t;
|
||||
throw new GeneralException(t);
|
||||
} finally {
|
||||
_transforming = false;
|
||||
if (returnBytes != null && _log.isTraceEnabled())
|
||||
_log.trace(_loc.get("runtime-enhance-complete", className,
|
||||
bytes.length, returnBytes.length));
|
||||
|
@ -228,4 +225,30 @@ public class PCClassFileTransformer
|
|||
private static boolean isEnhanced(byte[] b) {
|
||||
return AsmAdaptor.isEnhanced(b);
|
||||
}
|
||||
|
||||
public static class Reentrant extends PCClassFileTransformer {
|
||||
private final ThreadLocal<Boolean> transforming = new ThreadLocal<>();
|
||||
|
||||
public Reentrant(final MetaDataRepository repos, final Options opts, final ClassLoader loader) {
|
||||
super(repos, opts, loader);
|
||||
}
|
||||
|
||||
public Reentrant(final MetaDataRepository repos, final PCEnhancer.Flags flags,
|
||||
final ClassLoader tmpLoader, final boolean devscan) {
|
||||
super(repos, flags, tmpLoader, devscan);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] transform0(String className, Class redef, byte[] bytes) throws IllegalClassFormatException {
|
||||
if (transforming.get() != null) {
|
||||
return bytes;
|
||||
}
|
||||
transforming.set(true);
|
||||
try {
|
||||
return super.transform0(className, redef, bytes);
|
||||
} finally {
|
||||
transforming.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ public class PCEnhancerAgent {
|
|||
conf.setReadOnly(Configuration.INIT_STATE_FREEZING);
|
||||
conf.instantiateAll(); // avoid threading issues
|
||||
|
||||
PCClassFileTransformer transformer = new PCClassFileTransformer
|
||||
PCClassFileTransformer transformer = PCClassFileTransformer.newInstance
|
||||
(conf.newMetaDataRepositoryInstance(), clonedOptions,
|
||||
tmpLoader);
|
||||
inst.addTransformer(transformer);
|
||||
|
|
|
@ -791,7 +791,10 @@ public class BrokerImpl implements Broker, FindCallbacks, Cloneable, Serializabl
|
|||
public Map<String, Object> getProperties() {
|
||||
Map<String, Object> props = _conf.toProperties(true);
|
||||
for (String s : _supportedPropertyNames) {
|
||||
props.put("openjpa." + s, Reflection.getValue(this, s, true));
|
||||
final Object value = Reflection.getValue(this, s, !"CacheFinderQuery".equals(s));
|
||||
if (value != null) {
|
||||
props.put("openjpa." + s, value);
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
|
|
@ -342,7 +342,7 @@ public class PersistenceProviderImpl
|
|||
|
||||
MetaDataRepository repos = conf.getMetaDataRepositoryInstance();
|
||||
repos.setResolve(MetaDataModes.MODE_MAPPING, false);
|
||||
_trans = new PCClassFileTransformer(repos,
|
||||
_trans = PCClassFileTransformer.newInstance(repos,
|
||||
Configurations.parseProperties(props), tmpLoader);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue