OPENJPA-674 javaagent enhancer (PCEnhancerAgent) ignores persistence units after the first in persistence.xml

committing PCEnhancerAgent.patch provided by Dinkar Rao

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@683075 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Catalina Wei 2008-08-06 01:28:26 +00:00
parent a6216d10db
commit e97d6d1598
1 changed files with 35 additions and 24 deletions

View File

@ -20,6 +20,8 @@ package org.apache.openjpa.enhance;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.security.AccessController; import java.security.AccessController;
import java.util.Iterator;
import java.util.List;
import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.conf.OpenJPAConfigurationImpl; import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
@ -90,30 +92,39 @@ public class PCEnhancerAgent {
private static void registerClassLoadEnhancer(Instrumentation inst, private static void registerClassLoadEnhancer(Instrumentation inst,
Options opts) { Options opts) {
OpenJPAConfiguration conf = new OpenJPAConfigurationImpl(); List<String> anchors = Configurations.
Configurations.populateConfiguration(conf, opts); getFullyQualifiedAnchorsInPropertiesLocation(opts);
// don't allow connections for (String a : anchors) {
conf.setConnectionUserName(null); Options clonedOptions = (Options) opts.clone();
conf.setConnectionPassword(null); clonedOptions.setProperty("properties", a);
conf.setConnectionURL(null); OpenJPAConfiguration conf = new OpenJPAConfigurationImpl();
conf.setConnectionDriverName(null); Configurations.populateConfiguration(conf, clonedOptions);
conf.setConnectionFactoryName(null); // don't allow connections
// set single class resolver conf.setConnectionUserName(null);
final ClassLoader tmpLoader = (ClassLoader) AccessController conf.setConnectionPassword(null);
.doPrivileged(J2DoPrivHelper conf.setConnectionURL(null);
.newTemporaryClassLoaderAction((ClassLoader) AccessController conf.setConnectionDriverName(null);
.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()) conf.setConnectionFactoryName(null);
)); // set single class resolver
conf.setClassResolver(new ClassResolver() { final ClassLoader tmpLoader = (ClassLoader) AccessController
public ClassLoader getClassLoader(Class context, ClassLoader env) { .doPrivileged(J2DoPrivHelper
return tmpLoader; .newTemporaryClassLoaderAction((ClassLoader) AccessController
} .doPrivileged(J2DoPrivHelper.getContextClassLoaderAction())
}); ));
conf.setReadOnly(Configuration.INIT_STATE_FREEZING); conf.setClassResolver(new ClassResolver() {
conf.instantiateAll(); // avoid threading issues public ClassLoader getClassLoader(Class context,
ClassLoader env) {
return tmpLoader;
}
});
conf.setReadOnly(Configuration.INIT_STATE_FREEZING);
conf.instantiateAll(); // avoid threading issues
PCClassFileTransformer transformer = new PCClassFileTransformer PCClassFileTransformer transformer = new PCClassFileTransformer
(conf.newMetaDataRepositoryInstance(), opts, tmpLoader); (conf.newMetaDataRepositoryInstance(), clonedOptions,
inst.addTransformer(transformer); tmpLoader);
inst.addTransformer(transformer);
conf.close();
}
} }
} }