openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1197994 [4/10] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/...
Date Sat, 05 Nov 2011 17:17:33 GMT
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java Sat Nov  5 17:17:26 2011
@@ -43,15 +43,16 @@ import serp.bytecode.lowlevel.ConstantPo
 public class PCClassFileTransformer
     implements ClassFileTransformer {
 
-    private static final Localizer _loc = Localizer.forPackage(PCClassFileTransformer.class);
+    private static final Localizer _loc = Localizer.forPackage
+        (PCClassFileTransformer.class);
 
     private final MetaDataRepository _repos;
     private final PCEnhancer.Flags _flags;
     private final ClassLoader _tmpLoader;
     private final Log _log;
-    private final Set<String> _names;
+    private final Set _names;
     private boolean _transforming = false;
-    private static final String PERSISTENCE_CAPABLE = "org/apache/openjpa/enhance/PersistenceCapable";
+
     /**
      * Constructor.
      *
@@ -93,20 +94,17 @@ public class PCClassFileTransformer
         _repos = repos;
         _tmpLoader = tmpLoader;
 
-        _log = repos.getConfiguration().getLog(OpenJPAConfiguration.LOG_ENHANCE);
+        _log = repos.getConfiguration().
+            getLog(OpenJPAConfiguration.LOG_ENHANCE);
         _flags = flags;
-        repos.getConfiguration().addClassLoader(tmpLoader);
-        _names = repos.getPersistentTypeNames(devscan);
+
+        _names = repos.getPersistentTypeNames(devscan, tmpLoader);
         if (_names == null && _log.isInfoEnabled())
             _log.info(_loc.get("runtime-enhance-pcclasses"));
     }
 
-    /**
-     * The hook to transform byte code as they are loaded in Java Virtual Machine.
-     * 
-     */
     public byte[] transform(ClassLoader loader, String className,
-        Class<?> redef, ProtectionDomain domain, byte[] bytes)
+        Class redef, ProtectionDomain domain, byte[] bytes)
         throws IllegalClassFormatException {
         if (loader == _tmpLoader)
             return null;
@@ -131,27 +129,29 @@ public class PCClassFileTransformer
      * ClassCircularityError when executing method using pure-JIT JVMs
      * such as JRockit.
      */
-    private byte[] transform0(String className, Class<?> redef, byte[] bytes)
+    private byte[] transform0(String className, Class redef, byte[] bytes)
         throws IllegalClassFormatException {
         
+        byte[] returnBytes = null;
         try {
             Boolean enhance = needsEnhance(className, redef, bytes);
-            if (enhance != null && _log.isTraceEnabled()) {
-                _log.trace(_loc.get("needs-runtime-enhance", className,  enhance));
-            } 
-            if (enhance != Boolean.TRUE) {
+            if (enhance != null && _log.isTraceEnabled())
+                _log.trace(_loc.get("needs-runtime-enhance", className,
+                    enhance));
+            if (enhance != Boolean.TRUE)
                 return null;
-            }
 
             PCEnhancer enhancer = new PCEnhancer(_repos.getConfiguration(),
-                new Project().loadClass(new ByteArrayInputStream(bytes),  _tmpLoader), _repos);
+                new Project().loadClass(new ByteArrayInputStream(bytes),
+                    _tmpLoader), _repos);
             enhancer.setAddDefaultConstructor(_flags.addDefaultConstructor);
-            enhancer.setEnforcePropertyRestrictions(_flags.enforcePropertyRestrictions);
+            enhancer.setEnforcePropertyRestrictions
+                (_flags.enforcePropertyRestrictions);
 
-            if (enhancer.run() == PCEnhancer.ENHANCE_NONE) {
+            if (enhancer.run() == PCEnhancer.ENHANCE_NONE)
                 return null;
-            }
-            return enhancer.getPCBytecode().toByteArray();
+            returnBytes = enhancer.getPCBytecode().toByteArray();
+            return returnBytes;
         } catch (Throwable t) {
             _log.warn(_loc.get("cft-exception-thrown", className), t);
             if (t instanceof RuntimeException)
@@ -161,38 +161,40 @@ public class PCClassFileTransformer
             throw new GeneralException(t);
         } finally {
             _transforming = false;
+            if (returnBytes != null && _log.isTraceEnabled())
+                _log.trace(_loc.get("runtime-enhance-complete", className,
+                    bytes.length, returnBytes.length));
         }
     }
 
     /**
      * Return whether the given class needs enhancement.
      */
-    private Boolean needsEnhance(String clsName, Class<?> redef, byte[] bytes) {
+    private Boolean needsEnhance(String clsName, Class redef, byte[] bytes) {
         if (redef != null) {
-            Class<?>[] intfs = redef.getInterfaces();
-            for (int i = 0; i < intfs.length; i++) {
-                if (PersistenceCapable.class.getName().equals(intfs[i].getName())) {
-                    return !isEnhanced(bytes);
-                }
-            }
+            Class[] intfs = redef.getInterfaces();
+            for (int i = 0; i < intfs.length; i++)
+                if (PersistenceCapable.class.getName().
+                    equals(intfs[i].getName()))
+                    return Boolean.valueOf(!isEnhanced(bytes));
             return null;
         }
 
         if (_names != null) {
             if (_names.contains(clsName.replace('/', '.')))
-                return !isEnhanced(bytes);
+                return Boolean.valueOf(!isEnhanced(bytes));
             return null;
         }
 
-        if (clsName.startsWith("java/") || clsName.startsWith("javax/")) {
+        if (clsName.startsWith("java/") || clsName.startsWith("javax/"))
             return null;
-        }
         if (isEnhanced(bytes))
             return Boolean.FALSE;
 
         try {
-            Class<?> c = Class.forName(clsName.replace('/', '.'), false,  _tmpLoader);
-            if (_repos.getMetaData(c, false) != null)
+            Class c = Class.forName(clsName.replace('/', '.'), false,
+                _tmpLoader);
+            if (_repos.getMetaData(c, null, false) != null)
                 return Boolean.TRUE;
             return null;
         } catch (ClassNotFoundException cnfe) {
@@ -227,7 +229,7 @@ public class PCClassFileTransformer
             clsEntry = table.readUnsignedShort(idx);
             utfEntry = table.readUnsignedShort(table.get(clsEntry));
             name = table.readString(table.get(utfEntry));
-            if (PERSISTENCE_CAPABLE.equals(name))
+            if ("org/apache/openjpa/enhance/PersistenceCapable".equals(name))
                 return true;
         }
         return false;

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java Sat Nov  5 17:17:26 2011
@@ -249,14 +249,18 @@ public class PCEnhancer { 
      * @deprecated use {@link #PCEnhancer(OpenJPAConfiguration, BCClass,
         MetaDataRepository, ClassLoader)} instead. 
      */
+    public PCEnhancer(OpenJPAConfiguration conf, BCClass type,
+        MetaDataRepository repos) {
+        this(conf, type, repos, null);
+    }
 
     /**
      * Constructor. Supply configuration.
      *
-     * @param type the bytecode representation for the type to
+     * @param type the bytecode representation fo the type to
      * enhance; this can be created from any stream or file
      * @param repos a metadata repository to use for metadata access,
-     * or null to create a new repository; the repository
+     * or null to create a new reporitory; the repository
      * from the given configuration isn't used by default
      * because the configuration might be an
      * implementation-specific subclass whose metadata
@@ -264,7 +268,8 @@ public class PCEnhancer { 
      * @param loader the environment classloader to use for loading
      * classes and resources.
      */
-    public PCEnhancer(OpenJPAConfiguration conf, BCClass type, MetaDataRepository repos) {
+    public PCEnhancer(OpenJPAConfiguration conf, BCClass type,
+        MetaDataRepository repos, ClassLoader loader) {
         _managedType = type;
         _pc = type;
 
@@ -273,10 +278,9 @@ public class PCEnhancer { 
         if (repos == null) {
             _repos = conf.newMetaDataRepositoryInstance();
             _repos.setSourceMode(MetaDataRepository.MODE_META);
-        } else {
+        } else
             _repos = repos;
-        }
-        _meta = _repos.getMetaData(type.getType(), false);
+        _meta = _repos.getMetaData(type.getType(), loader, false);
     }
 
     /**
@@ -1128,7 +1132,7 @@ public class PCEnhancer { 
         if (_meta != null && _meta.getDescribedType().isInterface())
             return _meta;
 
-        return _repos.getMetaData(f.getDeclaringClass(), false);
+        return _repos.getMetaData(f.getDeclaringClass(), null, false);
     }
 
     /**
@@ -4682,18 +4686,22 @@ public class PCEnhancer { 
             PCEnhancer.class.getName() + "#bytecodeWriter");
 
         Configurations.populateConfiguration(conf, opts);
-        return run(conf, args, flags, null, writer);
+        return run(conf, args, flags, null, writer, null);
     }
 
     /**
      * Enhance the given classes.
      */
     public static boolean run(OpenJPAConfiguration conf, String[] args,
-        Flags flags, MetaDataRepository repos, BytecodeWriter writer)
+        Flags flags, MetaDataRepository repos, BytecodeWriter writer,
+        ClassLoader loader)
         throws IOException {
-        ClassLoader loader = conf.getClassLoader();
-//        if (flags.tmpClassLoader)
-//            loader = AccessController.doPrivileged(J2DoPrivHelper.newTemporaryClassLoaderAction(loader));
+        if (loader == null)
+            loader = conf.getClassResolverInstance().
+                getClassLoader(PCEnhancer.class, null);
+        if (flags.tmpClassLoader)
+            loader = AccessController.doPrivileged(J2DoPrivHelper
+                .newTemporaryClassLoaderAction(loader));
 
         if (repos == null) {
             repos = conf.newMetaDataRepositoryInstance();
@@ -4704,7 +4712,7 @@ public class PCEnhancer { 
         Collection classes;
         if (args == null || args.length == 0) {
             log.info(_loc.get("running-all-classes"));
-            classes = repos.getPersistentTypeNames(true);
+            classes = repos.getPersistentTypeNames(true, loader);
             if (classes == null) {
             	log.warn(_loc.get("no-class-to-enhance"));
             	return false;
@@ -4714,9 +4722,8 @@ public class PCEnhancer { 
                 getMetaDataFactory().newClassArgParser();
             cap.setClassLoader(loader);
             classes = new HashSet();
-            for (int i = 0; i < args.length; i++) {
+            for (int i = 0; i < args.length; i++)
                 classes.addAll(Arrays.asList(cap.parseTypes(args[i])));
-            }
         }
 
         Project project = new Project();
@@ -4732,7 +4739,7 @@ public class PCEnhancer { 
                 bc = project.loadClass((String) o, loader);
             else
                 bc = project.loadClass((Class) o);
-            enhancer = new PCEnhancer(conf, bc, repos);
+            enhancer = new PCEnhancer(conf, bc, repos, loader);
             if (writer != null)
                 enhancer.setBytecodeWriter(writer);
             enhancer.setDirectory(flags.directory);

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancerAgent.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancerAgent.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancerAgent.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancerAgent.java Sat Nov  5 17:17:26 2011
@@ -74,38 +74,38 @@ public class PCEnhancerAgent {
     private static boolean disableDynamicAgent = false;
 
     /**
-     * Affirms if the Agent has ran successfully. 
+     * @return True if the Agent has ran successfully. False otherwise.
      */
     public static synchronized boolean getLoadSuccessful() {
         return loadSuccessful;
     }
     /**
-     * disables dynamic agent. 
+     * @return True if the dynamic agent was disabled via configuration. 
      */
     public static void disableDynamicAgent(){
-        disableDynamicAgent = true;
+        disableDynamicAgent=true;
     }
     
     /**
-     * @param configuration
+     * @param log
      * @return True if the agent is loaded successfully
      */
-    public static synchronized boolean loadDynamicAgent(OpenJPAConfiguration conf) {
-        if (loadAttempted || disableDynamicAgent) {
-        	return false;
+    public static synchronized boolean loadDynamicAgent(Log log) {
+        if (loadAttempted == false && disableDynamicAgent == false) {
+            Instrumentation inst =
+                InstrumentationFactory.getInstrumentation(log);
+            if (inst != null) {
+                premain("", inst);
+                return true;
+            } 
+            // If we successfully get the Instrumentation, we will call premain
+            // where loadAttempted will be set to true. This case is the path 
+            // where we were unable to get Instrumentation so we need to set the
+            // loadAttempted flag to true. We do this so we will only run
+            // through this code one time.
+            loadAttempted = true;
         }
-        
-        Instrumentation inst = InstrumentationFactory.getInstrumentation(conf);
-        if (inst != null) {
-            premain("", inst);
-            return true;
-        } 
-        // If we successfully get the Instrumentation, we will call premain
-        // where loadAttempted will be set to true. This case is the path 
-        // where we were unable to get Instrumentation so we need to set the
-        // loadAttempted flag to true. We do this so we will only run
-        // through this code one time.
-        loadAttempted = true;
+
         return false;
     }
 
@@ -116,7 +116,7 @@ public class PCEnhancerAgent {
         // The agent will be disabled when running in an application
         // server.
         synchronized (PCEnhancerAgent.class) {
-            if (loadAttempted) {
+            if (loadAttempted == true) {
                 return;
             }
             // See the comment in loadDynamicAgent as to why we set this to true
@@ -128,11 +128,15 @@ public class PCEnhancerAgent {
 
         if (opts.containsKey("ClassLoadEnhancement") ||
             opts.containsKey("classLoadEnhancement")) {
-            if (opts.getBooleanProperty("ClassLoadEnhancement", "classLoadEnhancement", true))
+            if (opts.getBooleanProperty(
+                "ClassLoadEnhancement", "classLoadEnhancement", true))
                 registerClassLoadEnhancer(inst, opts);
-        } else if (opts.containsKey("RuntimeEnhancement") || opts.containsKey("runtimeEnhancement")) {
+        }
+        else if (opts.containsKey("RuntimeEnhancement") ||
+            opts.containsKey("runtimeEnhancement")) {
             // Deprecated property setting
-            if (opts.getBooleanProperty("RuntimeEnhancement", "runtimeEnhancement", true))
+            if (opts.getBooleanProperty(
+                "RuntimeEnhancement", "runtimeEnhancement", true))
                 registerClassLoadEnhancer(inst, opts);
         } else {
             // if neither is set, then we should be turning it on. We need this
@@ -141,7 +145,8 @@ public class PCEnhancerAgent {
             registerClassLoadEnhancer(inst, opts);
         }
 
-        if (opts.getBooleanProperty("RuntimeRedefinition", "runtimeRedefinition", true)) {
+        if (opts.getBooleanProperty(
+            "RuntimeRedefinition", "runtimeRedefinition", true)) {
             InstrumentationFactory.setInstrumentation(inst);
         } else {
             InstrumentationFactory.setDynamicallyInstallAgent(false);
@@ -149,8 +154,10 @@ public class PCEnhancerAgent {
         loadSuccessful = true;
     }
 
-    private static void registerClassLoadEnhancer(Instrumentation inst,  Options opts) {
-    	List<String> anchors = Configurations.getFullyQualifiedAnchorsInPropertiesLocation(opts);
+    private static void registerClassLoadEnhancer(Instrumentation inst,
+        Options opts) {
+    	List<String> anchors = Configurations.
+            getFullyQualifiedAnchorsInPropertiesLocation(opts);
     	for (String a : anchors) {
     		Options clonedOptions = (Options) opts.clone();
     		clonedOptions.setProperty("properties", a);
@@ -168,7 +175,12 @@ public class PCEnhancerAgent {
     		    .newTemporaryClassLoaderAction(AccessController
     		    .doPrivileged(J2DoPrivHelper.getContextClassLoaderAction())
     		    ));
-    		conf.addClassLoader(tmpLoader);
+    		conf.setClassResolver(new ClassResolver() {
+    		    public ClassLoader getClassLoader(Class context,
+                    ClassLoader env) {
+    		        return tmpLoader;
+    		    }
+    		});
     		conf.setReadOnly(Configuration.INIT_STATE_FREEZING);
     		conf.instantiateAll(); // avoid threading issues
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java Sat Nov  5 17:17:26 2011
@@ -64,7 +64,7 @@ public class ReflectingPersistenceCapabl
         Class type = o.getClass();
         pcSubclassInstance = PCRegistry.newInstance(type, null, false);
         meta = conf.getMetaDataRepositoryInstance()
-            .getMetaData(type, true);
+            .getMetaData(type, null, true);
     }
 
     public int pcGetEnhancementContractVersion() {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManager.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManager.java Sat Nov  5 17:17:26 2011
@@ -38,7 +38,7 @@ public interface InstrumentationManager 
      * @param conf the configuration to use for initialization
      * @param providers one or more providers as supplied via plugin list value
      */
-    public void initialize(OpenJPAConfiguration conf, PluginListValue<InstrumentationProvider> providers);
+    public void initialize(OpenJPAConfiguration conf, PluginListValue providers);
 
     /**
      * Manage a given provider.  This will plug the instruments managed by the 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManagerImpl.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManagerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/instrumentation/InstrumentationManagerImpl.java Sat Nov  5 17:17:26 2011
@@ -43,8 +43,9 @@ public class InstrumentationManagerImpl 
      * @param conf
      * @param providers
      */
-    public void initialize(OpenJPAConfiguration conf, PluginListValue<InstrumentationProvider> pluginVal) {
-        InstrumentationProvider[] providers = pluginVal.instantiate(conf);
+    public void initialize(OpenJPAConfiguration conf, PluginListValue pluginVal) {
+        InstrumentationProvider[] providers = 
+            (InstrumentationProvider[])pluginVal.instantiate(InstrumentationProvider.class, conf);
         _providers.addAll(Arrays.asList(providers));
     }
     

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java Sat Nov  5 17:17:26 2011
@@ -19,6 +19,7 @@
 package org.apache.openjpa.kernel;
 
 import java.io.ObjectStreamException;
+import java.security.AccessController;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -39,6 +40,7 @@ import javax.transaction.TransactionMana
 
 import org.apache.commons.collections.set.MapBackedSet;
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.kernel.AuditManager;
 import org.apache.openjpa.audit.Auditor;
 import org.apache.openjpa.conf.BrokerValue;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
@@ -103,7 +105,7 @@ public abstract class AbstractBrokerFact
     // cache the class names loaded from the persistent classes property so
     // that we can re-load them for each new broker
     private transient Collection<String> _pcClassNames = null;
-//    private transient Collection<ClassLoader> _pcClassLoaders = null;
+    private transient Collection<ClassLoader> _pcClassLoaders = null;
     private transient boolean _persistentTypesLoaded = false;
 
     // lifecycle listeners to pass to each broker
@@ -153,6 +155,7 @@ public abstract class AbstractBrokerFact
     protected AbstractBrokerFactory(OpenJPAConfiguration config) {
         _conf = config;
         _brokers = newBrokerSet();
+        getPcClassLoaders();
     }
 
     /**
@@ -232,7 +235,7 @@ public abstract class AbstractBrokerFact
         if (remote.areRemoteEventsEnabled())
             broker.addTransactionListener(remote);
 
-       loadPersistentTypes();
+       loadPersistentTypes(broker.getClassLoader());
         _brokers.add(broker);
         _conf.setReadOnly(Configuration.INIT_STATE_FROZEN);
     }
@@ -259,7 +262,7 @@ public abstract class AbstractBrokerFact
      * Load the configured persistent classes list. Performed automatically
      * whenever a broker is created.
      */
-    public void loadPersistentTypes() {
+    public void loadPersistentTypes(ClassLoader envLoader) {
         // if we've loaded the persistent types and the class name list
         // is empty, then we can simply return. Note that there is a
         // potential threading scenario in which _persistentTypesLoaded is
@@ -272,11 +275,12 @@ public abstract class AbstractBrokerFact
             return;
 
         // cache persistent type names if not already
-        ClassLoader loader = _conf.getClassLoader();
+        ClassLoader loader = _conf.getClassResolverInstance().
+            getClassLoader(getClass(), envLoader);
         Collection<Class<?>> toRedefine = new ArrayList<Class<?>>();
         if (!_persistentTypesLoaded) {
             Collection<Class<?>> clss = _conf.getMetaDataRepositoryInstance().
-                loadPersistentTypes(false, _conf.isInitializeEagerly());
+                loadPersistentTypes(false, loader, _conf.isInitializeEagerly());
             if (clss.isEmpty())
                 _pcClassNames = Collections.emptyList();
             else {
@@ -287,27 +291,27 @@ public abstract class AbstractBrokerFact
                     if (needsSub(cls))
                         toRedefine.add(cls);
                 }
-//                getPcClassLoaders().add(loader);
+                getPcClassLoaders().add(loader);
                 _pcClassNames = c;
             }
             _persistentTypesLoaded = true;
         } else {
             // reload with this loader
-//            if (getPcClassLoaders().add(loader)) {
-//                for (String clsName : _pcClassNames) {
-//                    try {
-//                        Class<?> cls = Class.forName(clsName, true, loader);
-//                        if (needsSub(cls))
-//                            toRedefine.add(cls);
-//                    } catch (Throwable t) {
-//                        _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(null, t);
-//                    }
-//                }
-//            }
+            if (getPcClassLoaders().add(loader)) {
+                for (String clsName : _pcClassNames) {
+                    try {
+                        Class<?> cls = Class.forName(clsName, true, loader);
+                        if (needsSub(cls))
+                            toRedefine.add(cls);
+                    } catch (Throwable t) {
+                        _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(null, t);
+                    }
+                }
+            }
         }
 
         // get the ManagedClassSubclasser into the loop
-        ManagedClassSubclasser.prepareUnenhancedClasses(_conf, toRedefine);
+        ManagedClassSubclasser.prepareUnenhancedClasses(_conf, toRedefine, envLoader);
     }
 
     private boolean needsSub(Class<?> cls) {
@@ -809,12 +813,12 @@ public abstract class AbstractBrokerFact
     /**
      * Method insures that deserialized EMF has this reference re-instantiated
      */
-//    private Collection<ClassLoader> getPcClassLoaders() {
-//       if (_pcClassLoaders == null)
-//         _pcClassLoaders = new ConcurrentReferenceHashSet<ClassLoader>(ConcurrentReferenceHashSet.WEAK);
-//          
-//       return _pcClassLoaders;
-//    }
+    private Collection<ClassLoader> getPcClassLoaders() {
+       if (_pcClassLoaders == null)
+         _pcClassLoaders = new ConcurrentReferenceHashSet<ClassLoader>(ConcurrentReferenceHashSet.WEAK);
+          
+       return _pcClassLoaders;
+    }
 
     /**
      * <P>
@@ -857,13 +861,14 @@ public abstract class AbstractBrokerFact
         }
         // Don't catch any exceptions here because we want to fail-fast if something bad happens when we're preloading.
         Options o = Configurations.parseProperties(Configurations.getProperties(_conf.getMetaDataRepository()));
-        if (MetaDataRepository.needsPreload(o)) {
+        if (MetaDataRepository.needsPreload(o) == true) {
             MetaDataRepository mdr = _conf.getMetaDataRepositoryInstance();
             mdr.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
             mdr.setResolve(MetaDataRepository.MODE_MAPPING_INIT, true);
 
             // Load persistent classes and hook in subclasser
-            loadPersistentTypes();
+            loadPersistentTypes((ClassLoader) AccessController.doPrivileged(J2DoPrivHelper
+                .getContextClassLoaderAction()));
             mdr.preload();
         }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCResultObjectProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCResultObjectProvider.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCResultObjectProvider.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCResultObjectProvider.java Sat Nov  5 17:17:26 2011
@@ -62,10 +62,13 @@ public abstract class AbstractPCResultOb
         load(sm, fetch);
     }
 
-    public Object getResultObject() throws Exception {
-        Class<?> type = getPCType();
-        MetaDataRepository repos = ctx.getConfiguration().getMetaDataRepositoryInstance();
-        ClassMetaData meta = repos.getMetaData(type, true);
+    public Object getResultObject()
+        throws Exception {
+        Class type = getPCType();
+        MetaDataRepository repos = ctx.getConfiguration().
+            getMetaDataRepositoryInstance();
+        ClassMetaData meta = repos.getMetaData
+            (type, ctx.getClassLoader(), true);
 
         Object oid = getObjectId(meta);
         Object res = ctx.find(oid, null, null, this, 0);
@@ -78,25 +81,30 @@ public abstract class AbstractPCResultOb
      * Implement this method to extract the object id value from the
      * current record of the input.
      */
-    protected abstract Object getObjectId(ClassMetaData meta) throws Exception;
+    protected abstract Object getObjectId(ClassMetaData meta)
+        throws Exception;
 
     /**
      * Implement this method to extract the type of the pc stored
      * in the current record of the input.
      */
-    protected abstract Class<?> getPCType() throws Exception;
+    protected abstract Class getPCType()
+        throws Exception;
 
     /**
      * Load data from the current input record into the given state
      * manager. Remember to call {@link OpenJPAStateManager#setVersion} to set
      * the optimistic versioning information, if it has any.
      */
-    protected abstract void load(OpenJPAStateManager sm, FetchConfiguration fetch) throws Exception;
+    protected abstract void load(OpenJPAStateManager sm, 
+        FetchConfiguration fetch)
+        throws Exception;
 
     /**
      * Override if desired. Does nothing by default.
      */
-    public void open() throws Exception {
+    public void open()
+        throws Exception {
     }
 
     /**
@@ -113,14 +121,16 @@ public abstract class AbstractPCResultOb
      *
      * @see ResultObjectProvider#next
      */
-    public abstract boolean next() throws Exception;
+    public abstract boolean next()
+        throws Exception;
 
     /**
      * Override if desired. Throws an exception by default.
      *
      * @see ResultObjectProvider#absolute
      */
-    public boolean absolute(int pos) throws Exception {
+    public boolean absolute(int pos)
+        throws Exception {
         throw new UnsupportedOperationException();
     }
 
@@ -129,7 +139,8 @@ public abstract class AbstractPCResultOb
      *
      * @see ResultObjectProvider#size
      */
-    public int size() throws Exception {
+    public int size()
+        throws Exception {
         return Integer.MAX_VALUE;
     }
 
@@ -138,7 +149,8 @@ public abstract class AbstractPCResultOb
      *
      * @see ResultObjectProvider#reset
      */
-    public void reset() throws Exception {
+    public void reset()
+        throws Exception {
         throw new UnsupportedOperationException();
     }
 
@@ -147,7 +159,8 @@ public abstract class AbstractPCResultOb
      *
      * @see ResultObjectProvider#close
      */
-    public void close() throws Exception {
+    public void close()
+        throws Exception {
     }
 
     /**

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java Sat Nov  5 17:17:26 2011
@@ -247,7 +247,8 @@ public class AttachManager {
         //### need to handle ACT_RUN without also ACT_CASCADE
         ClassMetaData meta = _broker.getConfiguration().
             getMetaDataRepositoryInstance().getMetaData(
-                ImplHelper.getManagedInstance(toAttach).getClass(), true);
+                ImplHelper.getManagedInstance(toAttach).getClass(),
+                _broker.getClassLoader(), true);
         return getStrategy(toAttach).attach(this, toAttach, meta, into,
             owner, ownerMeta, explicit);
     }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java Sat Nov  5 17:17:26 2011
@@ -39,7 +39,11 @@ import org.apache.openjpa.util.UserExcep
  */
 public class Bootstrap {
 
-    private static final Class<?>[] CONFIGURATION_ARG = { ConfigurationProvider.class };
+    private static final Class<?>[] CONFIGURATION_ARG =
+        new Class<?>[]{ ConfigurationProvider.class };
+    
+    private static final Class<?>[] CONFIGURATION_CLASSLOADER_ARGS =
+        new Class<?>[] { ConfigurationProvider.class, ClassLoader.class };
 
     private static Localizer s_loc = Localizer.forPackage(Bootstrap.class);
 
@@ -47,24 +51,30 @@ public class Bootstrap {
      * Return a new factory for the default configuration.
      */
     public static BrokerFactory newBrokerFactory() {
-        return Bootstrap.newBrokerFactory(null);
+        return Bootstrap.newBrokerFactory(null, null);
     }
 
     /**
-     * Return a new factory for the given configuration. 
+     * Return a new factory for the given configuration. The classloader
+     * will be used to load the factory class. If no classloader is given,
+     * the thread's context classloader is used.
      */
-    public static BrokerFactory newBrokerFactory(ConfigurationProvider conf) {
+    public static BrokerFactory newBrokerFactory(ConfigurationProvider conf,
+        ClassLoader loader) {
         try {
-            BrokerFactory factory = invokeFactory(conf, "newInstance", CONFIGURATION_ARG, new Object[] { conf });
+            BrokerFactory factory =
+                invokeFactory(conf, loader, "newInstance", CONFIGURATION_ARG, new Object[] { conf });
             factory.postCreationCallback();
             return factory;
         } catch (InvocationTargetException ite) {
             Throwable cause = ite.getTargetException();
             if (cause instanceof OpenJPAException)
                 throw (OpenJPAException) cause;
-            throw new InternalException(s_loc.get("new-brokerfactory-excep", getFactoryClassName(conf), cause));
+            throw new InternalException(s_loc.get("new-brokerfactory-excep",
+                getFactoryClassName(conf, loader)), cause);
         } catch (Exception e) {
-            throw new UserException(s_loc.get("bad-new-brokerfactory", getFactoryClassName(conf)), e).setFatal(true);
+            throw new UserException(s_loc.get("bad-new-brokerfactory",
+                getFactoryClassName(conf, loader)), e).setFatal(true);
         }
     }
 
@@ -72,41 +82,59 @@ public class Bootstrap {
      * Return a pooled factory for the default configuration.
      */
     public static BrokerFactory getBrokerFactory() {
-        return Bootstrap.getBrokerFactory(null);
+        return Bootstrap.getBrokerFactory(null, null);
     }
 
     /**
-     * Return a pooled factory for the given configuration. 
+     * Return a pooled factory for the given configuration. The classloader
+     * will be used to load the factory class. If no classloader is given,
+     * the thread's context classloader is used.
      */
-    public static BrokerFactory getBrokerFactory(ConfigurationProvider conf) {
+    public static BrokerFactory getBrokerFactory(ConfigurationProvider conf,
+        ClassLoader loader) {
         try {
-            return invokeFactory(conf, "getInstance", CONFIGURATION_ARG, new Object[] { conf});
+            return invokeFactory(conf, loader, "getInstance", CONFIGURATION_CLASSLOADER_ARGS, new Object[] { conf,
+                loader });
         } catch (InvocationTargetException ite) {
             Throwable cause = ite.getTargetException();
             if (cause instanceof OpenJPAException)
                 throw (OpenJPAException) cause;
-            throw new InternalException(s_loc.get("brokerfactory-excep", getFactoryClassName(conf)), cause);
+            throw new InternalException(s_loc.get("brokerfactory-excep",
+                getFactoryClassName(conf, loader)), cause);
         } catch (Exception e) {
-            throw new UserException(s_loc.get("bad-brokerfactory", getFactoryClassName(conf)), e).setFatal(true);
+            throw new UserException(s_loc.get("bad-brokerfactory",
+                getFactoryClassName(conf, loader)), e).setFatal(true);
         }
     }
 
-    private static BrokerFactory invokeFactory(ConfigurationProvider conf, String methodName, 
-    		Class<?>[] argTypes, Object[] args)
-        throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+    private static BrokerFactory invokeFactory(ConfigurationProvider conf,
+        ClassLoader loader, String methodName, Class<?>[] argTypes, Object[] args)
+        throws InvocationTargetException, NoSuchMethodException,
+            IllegalAccessException {
         if (conf == null)
             conf = new MapConfigurationProvider();
         ProductDerivations.beforeConfigurationConstruct(conf);
 
-        Class<?> cls = getFactoryClass(conf);
-        Method meth = cls.getMethod(methodName, argTypes); 
+        Class cls = getFactoryClass(conf, loader);
+        Method meth;
+        try {
+            meth = cls.getMethod(methodName, argTypes); 
+        } catch (NoSuchMethodException nsme) {
+            // handle cases where there is a mismatch between loaders by falling
+            // back to the configuration's class loader for broker resolution
+            cls = getFactoryClass(conf,
+                AccessController.doPrivileged(
+                    J2DoPrivHelper.getClassLoaderAction(conf.getClass()))); 
+            meth = cls.getMethod(methodName, argTypes); 
+        }
 
         return (BrokerFactory) meth.invoke(null, args);
     }
 
-    private static String getFactoryClassName(ConfigurationProvider conf) {
+    private static String getFactoryClassName(ConfigurationProvider conf,
+        ClassLoader loader) {
         try {
-            return getFactoryClass(conf).getName();
+            return getFactoryClass(conf, loader).getName();
         } catch (Exception e) {
             return "<" + e.toString() + ">";
         }
@@ -115,21 +143,28 @@ public class Bootstrap {
     /**
      * Instantiate the factory class designated in properties.
      */
-    private static Class<?> getFactoryClass(ConfigurationProvider conf) {
+    private static Class getFactoryClass(ConfigurationProvider conf,
+        ClassLoader loader) {
+        if (loader == null)
+            loader = AccessController.doPrivileged(
+                J2DoPrivHelper.getContextClassLoaderAction()); 
+
         Object cls = BrokerFactoryValue.get(conf);
         if (cls instanceof Class)
-            return (Class<?>) cls;
+            return (Class) cls;
 
         BrokerFactoryValue value = new BrokerFactoryValue();
         value.setString((String) cls);
         String clsName = value.getClassName();
         if (clsName == null)
-            throw new UserException(s_loc.get("no-brokerfactory", conf.getProperties())).setFatal(true);
+            throw new UserException(s_loc.get("no-brokerfactory", 
+                conf.getProperties())).setFatal(true);
 
         try {
-            return Class.forName(clsName, true, conf.getClassLoader());
+            return Class.forName(clsName, true, loader);
         } catch (Exception e) {
-            throw new UserException(s_loc.get("bad-brokerfactory-class", clsName), e).setFatal(true);
+            throw new UserException(s_loc.get("bad-brokerfactory-class",
+                clsName), e).setFatal(true);
 		}
 	}
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Broker.java Sat Nov  5 17:17:26 2011
@@ -53,7 +53,8 @@ public interface Broker
      * after the first invocation with non-null arguments,
      * subsequent invocations of this method are ignored.
      */
-    public void setImplicitBehavior(OpCallbacks call, RuntimeExceptionTranslator ex);
+    public void setImplicitBehavior(OpCallbacks call,
+        RuntimeExceptionTranslator ex);
 
     /**
      * Return the factory that produced this broker.
@@ -287,7 +288,7 @@ public interface Broker
      *
      * @since 0.3.3
      */
-    public void addLifecycleListener(Object listener, Class<?>[] classes);
+    public void addLifecycleListener(Object listener, Class[] classes);
 
     /**
      * Remove a listener for lifecycle-related events.
@@ -468,7 +469,7 @@ public interface Broker
     /**
      * Persist the given objects.
      */
-    public void persistAll(Collection<?> objs, OpCallbacks call);
+    public void persistAll(Collection objs, OpCallbacks call);
 
     /**
      * Make the given instance persistent. Unlike other persist operations,
@@ -489,7 +490,7 @@ public interface Broker
     /**
      * Delete the given objects.
      */
-    public void deleteAll(Collection<?> objs, OpCallbacks call);
+    public void deleteAll(Collection objs, OpCallbacks call);
 
     /**
      * Release the given object from management. This operation is not
@@ -501,7 +502,7 @@ public interface Broker
      * Release the given objects from management. This operation is not
      * recursive.
      */
-    public void releaseAll(Collection<?> objs, OpCallbacks call);
+    public void releaseAll(Collection objs, OpCallbacks call);
 
     /**
      * Refresh the state of the given object.
@@ -511,7 +512,7 @@ public interface Broker
     /**
      * Refresh the state of the given objects.
      */
-    public void refreshAll(Collection<?> objs, OpCallbacks call);
+    public void refreshAll(Collection objs, OpCallbacks call);
 
     /**
      * Evict the given object.
@@ -521,7 +522,7 @@ public interface Broker
     /**
      * Evict the given objects.
      */
-    public void evictAll(Collection<?> objs, OpCallbacks call);
+    public void evictAll(Collection objs, OpCallbacks call);
 
     /**
      * Evict all clean objects.
@@ -532,7 +533,7 @@ public interface Broker
      * Evict all persistent-clean and persistent-nontransactional
      * instances in the given {@link Extent}.
      */
-    public void evictAll(Extent<?> extent, OpCallbacks call);
+    public void evictAll(Extent extent, OpCallbacks call);
 
     /**
      * Detach all objects in place.  A flush will be performed before
@@ -572,7 +573,7 @@ public interface Broker
      * @param objs the instances to detach
      * @return the detached instances
      */
-    public Object[] detachAll(Collection<?> objs, OpCallbacks call);
+    public Object[] detachAll(Collection objs, OpCallbacks call);
 
     /**
      * Import the specified detached object into the broker.
@@ -593,7 +594,8 @@ public interface Broker
      * @return the re-attached instances
      * @param copyNew whether to copy new instances
      */
-    public Object[] attachAll(Collection<?> objs, boolean copyNew,  OpCallbacks call);
+    public Object[] attachAll(Collection objs, boolean copyNew,
+        OpCallbacks call);
 
     /**
      * Create a new instance of type <code>cls</code>. If <code>cls</code> is
@@ -606,7 +608,7 @@ public interface Broker
      * @throws IllegalArgumentException if <code>cls</code> is not a managed
      * type or interface.
      */
-    public Object newInstance(Class<?> cls);
+    public Object newInstance(Class cls);
 
     /**
      * Returns <code>true</code> if <code>obj</code> is a detached object
@@ -618,13 +620,13 @@ public interface Broker
     /**
      * Return an extent of the given class, optionally including subclasses.
      */
-    public <T> Extent<T> newExtent(Class<T> cls, boolean subs);
+    public Extent newExtent(Class cls, boolean subs);
 
     /**
      * Create a new query from the given data, with the given candidate class
      * and language.
      */
-    public Query newQuery(String language, Class<?> cls, Object query);
+    public Query newQuery(String language, Class cls, Object query);
 
     /**
      * Create a new query in the given language.
@@ -672,7 +674,8 @@ public interface Broker
      * giving up, or -1 for no limit
      * @since 0.3.1
      */
-    public void lockAll(Collection<?> objs, int level, int timeout, OpCallbacks call);
+    public void lockAll(Collection objs, int level, int timeout,
+        OpCallbacks call);
 
     /**
      * Ensure that the given instances are locked at the current lock level, as
@@ -680,7 +683,7 @@ public interface Broker
      *
      * @since 0.3.1
      */
-    public void lockAll(Collection<?> objs, OpCallbacks call);
+    public void lockAll(Collection objs, OpCallbacks call);
 
     /**
      * Cancel all pending data store statements. If statements are cancelled
@@ -697,7 +700,7 @@ public interface Broker
      *
      * @since 0.3.0
      */
-    public void dirtyType(Class<?> cls);
+    public void dirtyType(Class cls);
 
     /**
      * Begin a logical operation. This indicates to the broker the

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java Sat Nov  5 17:17:26 2011
@@ -180,6 +180,9 @@ public class BrokerImpl
     private transient OpenJPAConfiguration _conf = null;
     private transient MetaDataRepository _repo = null;
 
+    // cache class loader associated with the broker
+    private transient ClassLoader _loader = null;
+
     // user state
     private Synchronization _sync = null;
     private Map<Object, Object> _userObjects = null;
@@ -326,6 +329,8 @@ public class BrokerImpl
         boolean fromDeserialization, boolean fromWriteBehindCallback) {
         _fromWriteBehindCallback = fromWriteBehindCallback;
         _initializeWasInvoked = true;
+        _loader = AccessController.doPrivileged(
+            J2DoPrivHelper.getContextClassLoaderAction());
         if (!fromDeserialization){
             _conf = factory.getConfiguration();
             _repo = _conf.getMetaDataRepositoryInstance();
@@ -482,6 +487,10 @@ public class BrokerImpl
         return _runtime;
     }
 
+    public ClassLoader getClassLoader() {
+        return _loader;
+    }
+
     public DelegatingStoreManager getStoreManager() {
         return _store;
     }
@@ -735,7 +744,7 @@ public class BrokerImpl
     // Events
     // ////////
 
-    public void addLifecycleListener(Object listener, Class<?>[] classes) {
+    public void addLifecycleListener(Object listener, Class[] classes) {
         beginOperation(false);
         try {
             _lifeEventManager.addListener(listener, classes);
@@ -1032,22 +1041,23 @@ public class BrokerImpl
         return sm;
     }
 
-    public Object[] findAll(Collection<?> oids, boolean validate, FindCallbacks call) {
+    public Object[] findAll(Collection oids, boolean validate,
+        FindCallbacks call) {
         int flags = OID_COPY | OID_ALLOW_NEW | OID_NODELETED;
-        if (!validate) {
+        if (!validate)
             flags |= OID_NOVALIDATE;
-        }
         return findAll(oids, _fc, null, null, flags, call);
     }
 
-    public Object[] findAll(Collection<?> oids, FetchConfiguration fetch, BitSet exclude, Object edata, int flags) {
+    public Object[] findAll(Collection oids, FetchConfiguration fetch,
+        BitSet exclude, Object edata, int flags) {
         return findAll(oids, fetch, exclude, edata, flags, null);
     }
 
     /**
      * Internal finder.
      */
-    protected Object[] findAll(Collection<?> oids, FetchConfiguration fetch,
+    protected Object[] findAll(Collection oids, FetchConfiguration fetch,
         BitSet exclude, Object edata, int flags, FindCallbacks call) {
         findAllDepth ++;
 
@@ -1110,8 +1120,10 @@ public class BrokerImpl
             // pass all state managers in need of loading or validation to the
             // store manager
             if (load != null) {
-                PCState state = (transState) ? PCState.PCLEAN : PCState.PNONTRANS;
-                Collection<Object> failed = _store.loadAll(load, state, StoreManager.FORCE_LOAD_NONE, fetch, edata);
+                PCState state = (transState) ? PCState.PCLEAN
+                    : PCState.PNONTRANS;
+                Collection<Object> failed = _store.loadAll(load, state,
+                    StoreManager.FORCE_LOAD_NONE, fetch, edata);
 
                 // set failed instances to null
                 if (failed != null && !failed.isEmpty()) {
@@ -1223,7 +1235,7 @@ public class BrokerImpl
 
         beginOperation(false);
         try {
-            ClassMetaData meta = _repo.getMetaData(cls, false);
+            ClassMetaData meta = _repo.getMetaData(cls, _loader, false);
             if (meta == null
                 || meta.getIdentityType() == ClassMetaData.ID_UNKNOWN)
                 return null;
@@ -1246,7 +1258,7 @@ public class BrokerImpl
 
         beginOperation(false);
         try {
-            ClassMetaData meta = _repo.getMetaData(cls, true);
+            ClassMetaData meta = _repo.getMetaData(cls, _loader, true);
             switch (meta.getIdentityType()) {
             case ClassMetaData.ID_DATASTORE:
                 // delegate to store manager for datastore ids
@@ -1308,9 +1320,9 @@ public class BrokerImpl
         Class<?> pcType = _store.getManagedType(oid);
         ClassMetaData meta;
         if (pcType != null)
-            meta = _repo.getMetaData(pcType, true);
+            meta = _repo.getMetaData(pcType, _loader, true);
         else
-            meta = _repo.getMetaData(oid, true);
+            meta = _repo.getMetaData(oid, _loader, true);
 
         // copy the oid if needed
         if (copy && _compat.getCopyObjectIds()) {
@@ -2075,7 +2087,7 @@ public class BrokerImpl
     protected void flush(int reason) {
         // this will enlist proxied states as necessary so we know whether we
         // have anything to flush
-        Collection<StateManagerImpl> transactional = getTransactionalStates();
+        Collection transactional = getTransactionalStates();
 
         // do we actually have to flush?  only if our flags say so, or if
         // we have transaction listeners that need to be invoked for commit
@@ -2090,14 +2102,13 @@ public class BrokerImpl
         if (!flush && (reason != FLUSH_COMMIT || !listeners))
             return;
 
-        ManagedObjectCollection mobjs = null;
+        Collection mobjs = null;
         _flags |= FLAG_PRESTORING;
         try {
             if (flush) {
                 // call pre store on all currently transactional objs
-                for (StateManagerImpl sm : transactional) {
-                    sm.beforeFlush(reason, _call);
-                }
+                for (Iterator itr = transactional.iterator(); itr.hasNext();)
+                    ((StateManagerImpl) itr.next()).beforeFlush(reason, _call);
                 flushAdditions(transactional, reason);
             }
 
@@ -2172,7 +2183,9 @@ public class BrokerImpl
 
             // mark states as flushed
             if (flush) {
-                for (StateManagerImpl sm : transactional) {
+                StateManagerImpl sm;
+                for (Iterator itr = transactional.iterator(); itr.hasNext();) {
+                    sm = (StateManagerImpl) itr.next();
                     try {
                         // the state may have become transient, such as if
                         // it is embedded and the owner has been deleted during
@@ -2210,7 +2223,7 @@ public class BrokerImpl
     /**
      * Flush newly-transactional objects.
      */
-    private void flushAdditions(Collection<StateManagerImpl> transactional, int reason) {
+    private void flushAdditions(Collection transactional, int reason) {
         boolean loop;
         do {
             // flush new transactional instances; note logical or
@@ -2222,7 +2235,7 @@ public class BrokerImpl
     /**
      * Flush transactional additions.
      */
-    private boolean flushTransAdditions(Collection<StateManagerImpl> transactional, int reason) {
+    private boolean flushTransAdditions(Collection transactional, int reason) {
         if (_transAdditions == null || _transAdditions.isEmpty())
             return false;
 
@@ -2230,7 +2243,8 @@ public class BrokerImpl
         transactional.addAll(_transAdditions);
 
         // copy the change set, then clear it for the next iteration
-        StateManagerImpl[] states = _transAdditions.toArray(new StateManagerImpl[_transAdditions.size()]);
+        StateManagerImpl[] states = (StateManagerImpl[]) _transAdditions.
+            toArray(new StateManagerImpl[_transAdditions.size()]);
         _transAdditions = null;
 
         for (int i = 0; i < states.length; i++)
@@ -2241,14 +2255,15 @@ public class BrokerImpl
     /**
      * Delete new dereferenced objects.
      */
-    private boolean deleteDerefAdditions(Collection<StateManagerImpl> derefs) {
+    private boolean deleteDerefAdditions(Collection derefs) {
         if (_derefAdditions == null || _derefAdditions.isEmpty())
             return false;
 
         // remember these additions in case one becomes derefed again later
         derefs.addAll(_derefAdditions);
 
-        StateManagerImpl[] states = _derefAdditions.toArray(new StateManagerImpl[_derefAdditions.size()]);
+        StateManagerImpl[] states = (StateManagerImpl[]) _derefAdditions.
+            toArray(new StateManagerImpl[_derefAdditions.size()]);
         _derefAdditions = null;
 
         for (int i = 0; i < states.length; i++)
@@ -2260,7 +2275,8 @@ public class BrokerImpl
      * Delete a dereferenced dependent.
      */
     private void deleteDeref(StateManagerImpl sm) {
-        int action = processArgument(OpCallbacks.OP_DELETE, sm.getManagedInstance(), sm, null);
+        int action = processArgument(OpCallbacks.OP_DELETE,
+            sm.getManagedInstance(), sm, null);
         if ((action & OpCallbacks.ACT_RUN) != 0)
             sm.delete();
         if ((action & OpCallbacks.ACT_CASCADE) != 0)
@@ -2271,7 +2287,8 @@ public class BrokerImpl
      * Determine the action to take based on the user's given callbacks and
      * our implicit behavior.
      */
-    private int processArgument(int op, Object obj, OpenJPAStateManager sm, OpCallbacks call) {
+    private int processArgument(int op, Object obj, OpenJPAStateManager sm,
+        OpCallbacks call) {
         if (call != null)
             return call.processArgument(op, obj, sm);
         if (_call != null)
@@ -2341,15 +2358,14 @@ public class BrokerImpl
         _fc.setWriteLockLevel(LOCK_NONE);
         _fc.setLockTimeout(-1);
 
-        TransactionalCache transStates;
-        if (hasTransactionalObjects()) {
+        Collection transStates;
+        if (hasTransactionalObjects())
             transStates = _transCache;
-        } else {
-        	transStates = new TransactionalCache(true);
-        }
+        else
+            transStates = Collections.EMPTY_SET;
 
         // fire after rollback/commit event
-        ManagedObjectCollection mobjs = null;
+        Collection mobjs = null;
         if (_transEventManager.hasEndListeners()) {
             mobjs = new ManagedObjectCollection(transStates);
             int eventType = (rollback) ? TransactionEvent.AFTER_ROLLBACK
@@ -2384,7 +2400,9 @@ public class BrokerImpl
         }
 
         // perform commit or rollback state transitions on each instance
-        for (StateManagerImpl sm : transStates) {
+        StateManagerImpl sm;
+        for (Iterator itr = transStates.iterator(); itr.hasNext();) {
+            sm = (StateManagerImpl) itr.next();
             try {
                 if (rollback) {
                     // tell objects that may have been derefed then flushed
@@ -2444,7 +2462,7 @@ public class BrokerImpl
         return persist(obj, id, true, call);
     }
 
-    public void persistAll(Collection<?> objs, OpCallbacks call) {
+    public void persistAll(Collection objs, OpCallbacks call) {
         persistAll(objs, true, call);
     }
 
@@ -2452,7 +2470,7 @@ public class BrokerImpl
      * Persist the given objects.  Indicate whether this was an explicit persist
      * (PNEW) or a provisonal persist (PNEWPROVISIONAL).
      */
-    public void persistAll(Collection<?> objs, boolean explicit, 
+    public void persistAll(Collection objs, boolean explicit, 
         OpCallbacks call) {
         if (objs.isEmpty())
             return;
@@ -2611,7 +2629,7 @@ public class BrokerImpl
             }
         }
 
-        ClassMetaData meta = _repo.getMetaData(obj.getClass(), true);
+        ClassMetaData meta = _repo.getMetaData(obj.getClass(), _loader, true);
         if (fireEvent) {
             fireLifecycleEvent(obj, null, meta, LifecycleEvent.BEFORE_PERSIST);
         }
@@ -2665,7 +2683,7 @@ public class BrokerImpl
         if (pc.pcGetStateManager() != null)
             throw newDetachedException(obj, errOp);
 
-        ClassMetaData meta = _repo.getMetaData(obj.getClass(), true);
+        ClassMetaData meta = _repo.getMetaData(obj.getClass(), _loader, true);
         StateManagerImpl sm = newStateManagerImpl(StateManagerId.
             newInstance(this), meta);
         sm.initialize(pc, PCState.TLOADED);
@@ -2689,7 +2707,7 @@ public class BrokerImpl
         }
     }
 
-    public void deleteAll(Collection<?> objs, OpCallbacks call) {
+    public void deleteAll(Collection objs, OpCallbacks call) {
         beginOperation(true);
         try {
             assertWriteOperation();
@@ -2786,7 +2804,7 @@ public class BrokerImpl
             Exceptions.toString(obj))).setFailedObject(obj);
     }
 
-    public void releaseAll(Collection<?> objs, OpCallbacks call) {
+    public void releaseAll(Collection objs, OpCallbacks call) {
         beginOperation(false);
         try {
             List<Exception> exceps = null;
@@ -2929,7 +2947,7 @@ public class BrokerImpl
             if (sm == null) {
                 MetaDataRepository repos = _conf.
                     getMetaDataRepositoryInstance();
-                ClassMetaData meta = repos.getMetaData(type, true);
+                ClassMetaData meta = repos.getMetaData(type, _loader, true);
                 // construct a new state manager with all info known
                 sm = newStateManagerImpl(oid, meta);
                 sm.setObjectId(oid);
@@ -2941,7 +2959,7 @@ public class BrokerImpl
         }
     }
     
-    public void refreshAll(Collection<?> objs, OpCallbacks call) {
+    public void refreshAll(Collection objs, OpCallbacks call) {
         if (objs == null || objs.isEmpty())
             return;
 
@@ -3007,7 +3025,7 @@ public class BrokerImpl
      * This method is called with the full set of objects reachable via
      * cascade-refresh relations from the user-given instances.
      */
-    protected void refreshInternal(Collection<?> objs, OpCallbacks call) {
+    protected void refreshInternal(Collection objs, OpCallbacks call) {
     	if (objs == null || objs.isEmpty())
     		return;
         List<Exception> exceps = null;
@@ -3124,7 +3142,8 @@ public class BrokerImpl
     }
     
     
-    public void retrieveAll(Collection<?> objs, boolean dfgOnly, OpCallbacks call) {
+    public void retrieveAll(Collection objs, boolean dfgOnly,
+        OpCallbacks call) {
         if (objs == null || objs.isEmpty())
             return;
         if (objs.size() == 1) {
@@ -3260,7 +3279,7 @@ public class BrokerImpl
         }
     }
 
-    public void evictAll(Collection<?> objs, OpCallbacks call) {
+    public void evictAll(Collection objs, OpCallbacks call) {
         List<Exception> exceps = null;
         beginOperation(false);
         try {
@@ -3277,7 +3296,7 @@ public class BrokerImpl
         throwNestedExceptions(exceps, false);
     }
 
-    public void evictAll(Extent<?> extent, OpCallbacks call) {
+    public void evictAll(Extent extent, OpCallbacks call) {
         if (extent == null)
             return;
 
@@ -3349,7 +3368,7 @@ public class BrokerImpl
         }
     }
 
-    public Object[] detachAll(Collection<?> objs, OpCallbacks call) {
+    public Object[] detachAll(Collection objs, OpCallbacks call) {
         if (objs == null)
             return null;
         if (objs.isEmpty())
@@ -3466,7 +3485,8 @@ public class BrokerImpl
         }
     }
 
-    public Object[] attachAll(Collection<?> objs, boolean copyNew, OpCallbacks call) {
+    public Object[] attachAll(Collection objs, boolean copyNew,
+        OpCallbacks call) {
         if (objs == null)
             return null;
         if (objs.isEmpty())
@@ -3492,7 +3512,7 @@ public class BrokerImpl
         }
     }
 
-    public void nontransactionalAll(Collection<?> objs, OpCallbacks call) {
+    public void nontransactionalAll(Collection objs, OpCallbacks call) {
         beginOperation(true);
         try {
             List<Exception> exceps = null;
@@ -3533,7 +3553,7 @@ public class BrokerImpl
     /**
      * Make the given instances transactional.
      */
-    public void transactionalAll(Collection<?> objs, boolean updateVersion,
+    public void transactionalAll(Collection objs, boolean updateVersion,
         OpCallbacks call) {
         if (objs.isEmpty())
             return;
@@ -3565,7 +3585,7 @@ public class BrokerImpl
 
                     if (sm == null) {
                         // manage transient instance
-                        meta = _repo.getMetaData(obj.getClass(), true);
+                        meta = _repo.getMetaData(obj.getClass(), _loader, true);
 
                         sm = newStateManagerImpl
                             (StateManagerId.newInstance(this), meta);
@@ -3636,7 +3656,7 @@ public class BrokerImpl
                 _flags |= FLAG_FLUSH_REQUIRED; // version check/up
             } else if (sm == null) {
                 // manage transient instance
-                ClassMetaData meta = _repo.getMetaData(obj.getClass(), true);
+                ClassMetaData meta = _repo.getMetaData(obj.getClass(), _loader, true);
                 Object id = StateManagerId.newInstance(this);
                 sm = newStateManagerImpl(id, meta);
                 sm.initialize(assertPersistenceCapable(obj),
@@ -3655,10 +3675,12 @@ public class BrokerImpl
     /**
      * Transition the given state managers to transactional.
      */
-    private void transactionalStatesAll(Collection<StateManagerImpl> sms, Collection<?> failed, 
-    		List<Exception> exceps) {
+    private void transactionalStatesAll(Collection sms, Collection failed,
+        List<Exception> exceps) {
         // make instances transactional and make sure they are loaded
-        for (StateManagerImpl sm : sms) {
+        StateManagerImpl sm;
+        for (Iterator<?> itr = sms.iterator(); itr.hasNext();) {
+            sm = (StateManagerImpl) itr.next();
             if (failed != null && failed.contains(sm.getId()))
                 continue;
 
@@ -3676,14 +3698,15 @@ public class BrokerImpl
     // Extent, Query
     /////////////////
 
-    public <T> Extent<T> newExtent(Class<T> type, boolean subclasses) {
+    public Extent newExtent(Class type, boolean subclasses) {
         return newExtent(type, subclasses, null);
     }
 
-    private <T> Extent<T> newExtent(Class<T> type, boolean subclasses, FetchConfiguration fetch) {
+    private Extent newExtent(Class type, boolean subclasses,
+        FetchConfiguration fetch) {
         beginOperation(true);
         try {
-            ExtentImpl<T> extent = new ExtentImpl<T>(this, type, subclasses, fetch);
+            ExtentImpl extent = new ExtentImpl(this, type, subclasses, fetch);
             if (_extents == null)
                 _extents = new ReferenceHashSet(ReferenceHashSet.WEAK);
             _extents.add(extent);
@@ -3698,14 +3721,14 @@ public class BrokerImpl
         }
     }
 
-    public <T> Iterator<T> extentIterator(Class<T> type, boolean subclasses,
-    		FetchConfiguration fetch, boolean ignoreChanges) {
-        Extent<T> extent = newExtent(type, subclasses, fetch);
+    public Iterator extentIterator(Class type, boolean subclasses,
+        FetchConfiguration fetch, boolean ignoreChanges) {
+        Extent extent = newExtent(type, subclasses, fetch);
         extent.setIgnoreChanges(ignoreChanges);
         return extent.iterator();
     }
 
-    public Query newQuery(String lang, Class<?> cls, Object query) {
+    public Query newQuery(String lang, Class cls, Object query) {
         Query q = newQuery(lang, query);
         q.setCandidateType(cls, true);
         return q;
@@ -3792,7 +3815,7 @@ public class BrokerImpl
                 SequenceMetaData smd = (fmd == null)
                     ? meta.getIdentitySequenceMetaData()
                     : fmd.getValueSequenceMetaData();
-                return smd.getInstance();
+                return smd.getInstance(_loader);
             default:
                 // use store manager for native sequence
                 if (fmd == null) {
@@ -3811,7 +3834,7 @@ public class BrokerImpl
                     }
 
                     if (smd != null) {
-                        return smd.getInstance();
+                        return smd.getInstance(_loader);
                     } else {
                         return _store.getDataStoreIdSequence(meta);
                     }
@@ -3862,7 +3885,7 @@ public class BrokerImpl
         }
     }
 
-    public void lockAll(Collection<?> objs, OpCallbacks call) {
+    public void lockAll(Collection objs, OpCallbacks call) {
         if (objs.isEmpty())
             return;
 
@@ -3875,7 +3898,8 @@ public class BrokerImpl
         }
     }
 
-    public void lockAll(Collection<?> objs, int level, int timeout, OpCallbacks call) {
+    public void lockAll(Collection objs, int level, int timeout,
+        OpCallbacks call) {
         if (objs.isEmpty())
             return;
         if (objs.size() == 1) {
@@ -3904,9 +3928,8 @@ public class BrokerImpl
             }
 
             _lm.lockAll(sms, level, timeout, null);
-            for (Iterator<StateManagerImpl> itr = sms.iterator(); itr.hasNext();) {
+            for (Iterator<StateManagerImpl> itr = sms.iterator(); itr.hasNext();)
                 itr.next().readLocked(level, level);
-            }
         } catch (OpenJPAException ke) {
             throw ke;
         } catch (RuntimeException re) {
@@ -3978,7 +4001,7 @@ public class BrokerImpl
     // Cache
     /////////
 
-    public Collection<Object> getManagedObjects() {
+    public Collection getManagedObjects() {
         beginOperation(false);
         try {
             return new ManagedObjectCollection(getManagedStates());
@@ -3987,7 +4010,7 @@ public class BrokerImpl
         }
     }
 
-    public Collection<Object> getTransactionalObjects() {
+    public Collection getTransactionalObjects() {
         beginOperation(false);
         try {
             return new ManagedObjectCollection(getTransactionalStates());
@@ -3996,16 +4019,17 @@ public class BrokerImpl
         }
     }
 
-    public Collection<Object> getPendingTransactionalObjects() {
+    public Collection getPendingTransactionalObjects() {
         beginOperation(false);
         try {
-            return new ManagedObjectCollection(getPendingTransactionalStates());
+            return new ManagedObjectCollection
+                (getPendingTransactionalStates());
         } finally {
             endOperation();
         }
     }
 
-    public Collection<Object> getDirtyObjects() {
+    public Collection getDirtyObjects() {
         beginOperation(false);
         try {
             return new ManagedObjectCollection(getDirtyStates());
@@ -4025,7 +4049,7 @@ public class BrokerImpl
     /**
      * Return a copy of all managed state managers.
      */
-    protected Collection<StateManagerImpl> getManagedStates() {
+    protected Collection getManagedStates() {
         return _cache.copy();
     }
 
@@ -4053,9 +4077,9 @@ public class BrokerImpl
     /**
      * Return a copy of all dirty state managers.
      */
-    protected Collection<StateManagerImpl> getDirtyStates() {
+    protected Collection getDirtyStates() {
         if (!hasTransactionalObjects())
-            return Collections.emptySet();
+            return Collections.EMPTY_SET;
 
         return _transCache.copyDirty();
     }
@@ -4064,9 +4088,9 @@ public class BrokerImpl
      * Return a copy of all state managers which will become
      * transactional upon the next transaction.
      */
-    protected Collection<StateManagerImpl> getPendingTransactionalStates() {
+    protected Collection getPendingTransactionalStates() {
         if (_pending == null)
-            return Collections.emptySet();
+            return Collections.EMPTY_SET;
         return new LinkedHashSet<StateManagerImpl>(_pending);
     }
 
@@ -4275,7 +4299,7 @@ public class BrokerImpl
         }
     }
 
-    public void dirtyType(Class<?> cls) {
+    public void dirtyType(Class cls) {
         if (cls == null)
             return;
 
@@ -4289,21 +4313,21 @@ public class BrokerImpl
         }
     }
 
-    public Collection<Class<?>> getPersistedTypes() {
+    public Collection getPersistedTypes() {
         if (_persistedClss == null || _persistedClss.isEmpty())
-            return Collections.emptySet();
+            return Collections.EMPTY_SET;
         return Collections.unmodifiableCollection(_persistedClss);
     }
 
-    public Collection<Class<?>> getUpdatedTypes() {
+    public Collection getUpdatedTypes() {
         if (_updatedClss == null || _updatedClss.isEmpty())
-            return Collections.emptySet();
+            return Collections.EMPTY_SET;
         return Collections.unmodifiableCollection(_updatedClss);
     }
 
-    public Collection<Class<?>> getDeletedTypes() {
+    public Collection getDeletedTypes() {
         if (_deletedClss == null || _deletedClss.isEmpty())
-            return Collections.emptySet();
+            return Collections.EMPTY_SET;
         return Collections.unmodifiableCollection(_deletedClss);
     }
 
@@ -4359,6 +4383,7 @@ public class BrokerImpl
         _deletedClss = null;
         _derefCache = null;
         _pending = null;
+        _loader = null;
         _transEventManager = null;
         _lifeEventManager = null;
 
@@ -4382,9 +4407,9 @@ public class BrokerImpl
         }
 
         if (_extents != null) {
-            Extent<?> e;
+            Extent e;
             for (Iterator<?> itr = _extents.iterator(); itr.hasNext();) {
-                e = (Extent<?>) itr.next();
+                e = (Extent) itr.next();
                 try {
                     e.closeAll();
                 } catch (RuntimeException re) {
@@ -4429,11 +4454,12 @@ public class BrokerImpl
     // State management
     ////////////////////
 
-    public Object newInstance(Class<?> cls) {
+    public Object newInstance(Class cls) {
         assertOpen();
 
         if (!cls.isInterface() && Modifier.isAbstract(cls.getModifiers()))
-            throw new UnsupportedOperationException(_loc.get("new-abstract", cls).getMessage());
+            throw new UnsupportedOperationException(_loc.get
+                ("new-abstract", cls).getMessage());
 
         // 1.5 doesn't initialize classes without a true Class.forName
         if (!PCRegistry.isRegistered(cls)) {
@@ -4445,7 +4471,7 @@ public class BrokerImpl
             }
         }
 
-        if (_repo.getMetaData(cls, false) == null)
+        if (_repo.getMetaData(cls, getClassLoader(), false) == null)
             throw new IllegalArgumentException(
                 _loc.get("no-interface-metadata", cls.getName()).getMessage());
 
@@ -4467,7 +4493,7 @@ public class BrokerImpl
                 if (pc.pcGetStateManager() == null) {
                     // If the statemanager is null the call to pcFetchObjectId always returns null. Create a new object
                     // id.
-                    return ApplicationIds.create(pc, _repo.getMetaData(pc.getClass(), true));
+                    return ApplicationIds.create(pc, _repo.getMetaData(pc.getClass(), null, true));
                 }
                 return pc.pcFetchObjectId();
             }
@@ -4556,7 +4582,7 @@ public class BrokerImpl
             return detached.booleanValue();
 
         // last resort: instance is detached if it has a store record
-        ClassMetaData meta = _repo.getMetaData(ImplHelper.getManagedInstance(pc).getClass(), true);
+        ClassMetaData meta = _repo.getMetaData(ImplHelper.getManagedInstance(pc).getClass(), _loader, true);
         Object oid = ApplicationIds.create(pc, meta);
         if (oid == null)
             return false;
@@ -4685,7 +4711,8 @@ public class BrokerImpl
      * Return an object not found exception containing nested exceptions
      * for all of the given failed objects.
      */
-    private static ObjectNotFoundException newObjectNotFoundException(Collection<?> failed) {
+    private static ObjectNotFoundException newObjectNotFoundException
+        (Collection failed) {
         Throwable[] t = new Throwable[failed.size()];
         int idx = 0;
         for (Iterator<?> itr = failed.iterator(); itr.hasNext(); idx++)
@@ -4774,11 +4801,11 @@ public class BrokerImpl
      * Transactional cache that holds soft refs to clean instances.
      */
     static class TransactionalCache
-        implements Set<StateManagerImpl>, Serializable {
+        implements Set, Serializable {
 
         private final boolean _orderDirty;
-        private Set<StateManagerImpl> _dirty;
-        private Set<StateManagerImpl> _clean;
+        private Set<StateManagerImpl> _dirty = null;
+        private Set<StateManagerImpl> _clean = null;
 
         public TransactionalCache(boolean orderDirty) {
             _orderDirty = orderDirty;
@@ -4787,31 +4814,31 @@ public class BrokerImpl
         /**
          * Return a copy of all transactional state managers.
          */
-        public Collection<StateManagerImpl> copy() {
+        public Collection copy() {
             if (isEmpty()) {
                 // Transaction Listeners may add entities to the transaction. 
-                return new LinkedHashSet<StateManagerImpl>();
+                return new LinkedHashSet();
             }
 
             // size may not be entirely accurate due to refs expiring, so
             // manually copy each object; doesn't matter this way if size too
             // big by some
-            Set<StateManagerImpl> copy = new LinkedHashSet<StateManagerImpl>(size());
+            Set copy = new LinkedHashSet(size());
             if (_dirty != null)
-                for (StateManagerImpl dirty : _dirty)
-                    copy.add(dirty);
+                for (Iterator<StateManagerImpl> itr = _dirty.iterator(); itr.hasNext();)
+                    copy.add(itr.next());
             if (_clean != null)
-                for (StateManagerImpl clean : _clean)
-                    copy.add(clean);
+                for (Iterator<StateManagerImpl> itr = _clean.iterator(); itr.hasNext();)
+                    copy.add(itr.next());
             return copy;
         }
 
         /**
          * Return a copy of all dirty state managers.
          */
-        public Collection<StateManagerImpl> copyDirty() {
+        public Collection copyDirty() {
             if (_dirty == null || _dirty.isEmpty())
-                return Collections.emptySet();
+                return Collections.EMPTY_SET;
             return new LinkedHashSet<StateManagerImpl>(_dirty);
         }
 
@@ -4863,7 +4890,7 @@ public class BrokerImpl
             return _clean != null && _clean.remove(sm);
         }
 
-        public Iterator<StateManagerImpl> iterator() {
+        public Iterator iterator() {
             IteratorChain chain = new IteratorChain();
             if (_dirty != null && !_dirty.isEmpty())
                 chain.addIterator(_dirty.iterator());
@@ -4877,7 +4904,7 @@ public class BrokerImpl
                 || (_clean != null && _clean.contains(obj));
         }
 
-        public boolean containsAll(Collection<?> coll) {
+        public boolean containsAll(Collection coll) {
             for (Iterator<?> itr = coll.iterator(); itr.hasNext();)
                 if (!contains(itr.next()))
                     return false;
@@ -4905,11 +4932,11 @@ public class BrokerImpl
             return size;
         }
 
-        public boolean add(StateManagerImpl obj) {
+        public boolean add(Object obj) {
             throw new UnsupportedOperationException();
         }
 
-        public boolean addAll(Collection<? extends StateManagerImpl> coll) {
+        public boolean addAll(Collection coll) {
             throw new UnsupportedOperationException();
         }
 
@@ -4917,11 +4944,11 @@ public class BrokerImpl
             throw new UnsupportedOperationException();
         }
 
-        public boolean removeAll(Collection<?> coll) {
+        public boolean removeAll(Collection coll) {
             throw new UnsupportedOperationException();
         }
 
-        public boolean retainAll(Collection<?> c) {
+        public boolean retainAll(Collection c) {
             throw new UnsupportedOperationException();
         }
 
@@ -4929,10 +4956,9 @@ public class BrokerImpl
             throw new UnsupportedOperationException();
         }
 
-		@Override
-		public <T> T[] toArray(T[] a) {
+        public Object[] toArray(Object[] arr) {
             throw new UnsupportedOperationException();
-		}
+        }
     }
 
     /**
@@ -4989,15 +5015,15 @@ public class BrokerImpl
      * with the corresponding managed objects.
      */
     private static class ManagedObjectCollection
-        extends AbstractCollection<Object> {
+        extends AbstractCollection {
 
-        private final Collection<? extends OpenJPAStateManager> _states;
+        private final Collection _states;
 
-        public ManagedObjectCollection(Collection<? extends OpenJPAStateManager> states) {
+        public ManagedObjectCollection(Collection states) {
             _states = states;
         }
 
-        public Collection<? extends OpenJPAStateManager> getStateManagers() {
+        public Collection getStateManagers() {
             return _states;
         }
 
@@ -5005,16 +5031,17 @@ public class BrokerImpl
             return _states.size();
         }
 
-        public Iterator<Object> iterator() {
-            return new Iterator<Object>() {
-                private final Iterator<? extends OpenJPAStateManager> _itr = _states.iterator();
+        public Iterator iterator() {
+            return new Iterator() {
+                private final Iterator _itr = _states.iterator();
 
                 public boolean hasNext() {
                     return _itr.hasNext();
                 }
 
                 public Object next() {
-                    return ((OpenJPAStateManager) _itr.next()).getManagedInstance();
+                    return ((OpenJPAStateManager) _itr.next()).
+                        getManagedInstance();
                 }
 
                 public void remove() {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBroker.java Sat Nov  5 17:17:26 2011
@@ -170,6 +170,14 @@ public class DelegatingBroker
         }
     }
 
+    public ClassLoader getClassLoader() {
+        try {
+            return _broker.getClassLoader();
+        } catch (RuntimeException re) {
+            throw translate(re);
+        }
+    }
+
     public LockManager getLockManager() {
         try {
             return _broker.getLockManager();

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingStoreManager.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingStoreManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingStoreManager.java Sat Nov  5 17:17:26 2011
@@ -127,7 +127,7 @@ public abstract class DelegatingStoreMan
         _store.beforeStateChange(sm, fromState, toState);
     }
 
-    public Collection<Exception> flush(Collection<? extends OpenJPAStateManager> sms) {
+    public Collection<Exception> flush(Collection<OpenJPAStateManager> sms) {
         return _store.flush(sms);
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java Sat Nov  5 17:17:26 2011
@@ -48,10 +48,12 @@ class DetachedStateAttachStrategy
             return null;
 
         Broker broker = manager.getBroker();
-        PersistenceCapable pc = ImplHelper.toPersistenceCapable(toAttach, broker.getConfiguration());
+        PersistenceCapable pc = ImplHelper.toPersistenceCapable(toAttach,
+            broker.getConfiguration());
         ClassMetaData meta = broker.getConfiguration().
             getMetaDataRepositoryInstance().getMetaData(
-                ImplHelper.getManagedInstance(toAttach).getClass(), true);
+                ImplHelper.getManagedInstance(toAttach).getClass(),
+                broker.getClassLoader(), true);
 
         switch (meta.getIdentityType()) {
             case ClassMetaData.ID_DATASTORE:

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java Sat Nov  5 17:17:26 2011
@@ -52,7 +52,8 @@ public class DetachedValueStateManager
     public DetachedValueStateManager(Object pc, StoreContext ctx) {
         this(ImplHelper.toPersistenceCapable(pc, ctx.getConfiguration()),
             ctx.getConfiguration().getMetaDataRepositoryInstance()
-                .getMetaData(ImplHelper.getManagedInstance(pc).getClass(), true), ctx);
+                .getMetaData(ImplHelper.getManagedInstance(pc).getClass(),
+            ctx.getClassLoader(), true), ctx);
     }
 
     public DetachedValueStateManager(PersistenceCapable pc, ClassMetaData meta,

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java Sat Nov  5 17:17:26 2011
@@ -94,8 +94,8 @@ public class ExpressionStoreQuery
         new StringContains(), new WildcardMatch(),
     };
 
-    protected final ExpressionParser _parser;
-    protected transient Object _parsed;
+    private final ExpressionParser _parser;
+    private transient Object _parsed;
 
     /**
      * Construct a query with a parser for the language.
@@ -172,7 +172,7 @@ public class ExpressionStoreQuery
 
     public Executor newInMemoryExecutor(ClassMetaData meta, boolean subs) {
         return new InMemoryExecutor(this, meta, subs, _parser,
-            ctx.getCompilation(), new InMemoryExpressionFactory());
+            ctx.getCompilation());
     }
 
     public Executor newDataStoreExecutor(ClassMetaData meta, boolean subs) {
@@ -576,7 +576,7 @@ public class ExpressionStoreQuery
     /**
      * Runs the expression query in memory.
      */
-    public static class InMemoryExecutor
+    private static class InMemoryExecutor
         extends AbstractExpressionExecutor
         implements Executor, Serializable {
 
@@ -588,10 +588,10 @@ public class ExpressionStoreQuery
 
         public InMemoryExecutor(ExpressionStoreQuery q,
             ClassMetaData candidate, boolean subclasses,
-            ExpressionParser parser, Object parsed, InMemoryExpressionFactory factory) {
+            ExpressionParser parser, Object parsed) {
             _meta = candidate;
             _subs = subclasses;
-            _factory = factory;
+            _factory = new InMemoryExpressionFactory();
 
             _exps = new QueryExpressions[] {
                 parser.eval(parsed, q, _factory, _meta)
@@ -637,9 +637,9 @@ public class ExpressionStoreQuery
                 Object obj;
                 while (itr.hasNext()) {
                     obj = itr.next();
-                    if (_factory.matches(_exps[0], _meta, _subs, obj, ctx, params)) {
+                    if (_factory.matches(_exps[0], _meta, _subs, obj, ctx,
+                        params))
                         results.add(obj);
-                    }
                 }
             }
             finally {
@@ -703,7 +703,6 @@ public class ExpressionStoreQuery
         public Class[] getProjectionTypes(StoreQuery q) {
             return _projTypes;
         }
-        
 
         /**
          * Throws an exception if a variable is found.



Mime
View raw message