OPENJPA-1692: Update method signature for BrokerFactory.getInstance(...) to take a classloader.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@953830 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2010-06-11 18:51:47 +00:00
parent ea8dc8b630
commit 3905b52a90
2 changed files with 15 additions and 10 deletions

View File

@ -65,7 +65,7 @@ public class JDBCBrokerFactory
* Factory method for obtaining a possibly-pooled factory from properties. * Factory method for obtaining a possibly-pooled factory from properties.
* Invoked from {@link Bootstrap#getBrokerFactory}. * Invoked from {@link Bootstrap#getBrokerFactory}.
*/ */
public static JDBCBrokerFactory getInstance(ConfigurationProvider cp) { public static JDBCBrokerFactory getInstance(ConfigurationProvider cp, ClassLoader loader) {
Map<String, Object> props = cp.getProperties(); Map<String, Object> props = cp.getProperties();
Object key = toPoolKey(props); Object key = toPoolKey(props);
JDBCBrokerFactory factory = (JDBCBrokerFactory) getPooledFactoryForKey(key); JDBCBrokerFactory factory = (JDBCBrokerFactory) getPooledFactoryForKey(key);
@ -73,7 +73,7 @@ public class JDBCBrokerFactory
return factory; return factory;
// The creation of all BrokerFactories should be driven through Bootstrap. // The creation of all BrokerFactories should be driven through Bootstrap.
factory = (JDBCBrokerFactory) Bootstrap.newBrokerFactory(cp, null); factory = (JDBCBrokerFactory) Bootstrap.newBrokerFactory(cp, loader);
pool(key, factory); pool(key, factory);
return factory; return factory;
} }

View File

@ -39,8 +39,11 @@ import org.apache.openjpa.util.UserException;
*/ */
public class Bootstrap { public class Bootstrap {
private static final Class[] FACTORY_ARGS = private static final Class<?>[] CONFIGURATION_ARG =
new Class[]{ ConfigurationProvider.class }; 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); private static Localizer s_loc = Localizer.forPackage(Bootstrap.class);
@ -59,7 +62,8 @@ public class Bootstrap {
public static BrokerFactory newBrokerFactory(ConfigurationProvider conf, public static BrokerFactory newBrokerFactory(ConfigurationProvider conf,
ClassLoader loader) { ClassLoader loader) {
try { try {
BrokerFactory factory = invokeFactory(conf, loader, "newInstance"); BrokerFactory factory =
invokeFactory(conf, loader, "newInstance", CONFIGURATION_ARG, new Object[] { conf });
factory.postCreationCallback(); factory.postCreationCallback();
return factory; return factory;
} catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) {
@ -89,7 +93,8 @@ public class Bootstrap {
public static BrokerFactory getBrokerFactory(ConfigurationProvider conf, public static BrokerFactory getBrokerFactory(ConfigurationProvider conf,
ClassLoader loader) { ClassLoader loader) {
try { try {
return invokeFactory(conf, loader, "getInstance"); return invokeFactory(conf, loader, "getInstance", CONFIGURATION_CLASSLOADER_ARGS, new Object[] { conf,
loader });
} catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) {
Throwable cause = ite.getTargetException(); Throwable cause = ite.getTargetException();
if (cause instanceof OpenJPAException) if (cause instanceof OpenJPAException)
@ -103,7 +108,7 @@ public class Bootstrap {
} }
private static BrokerFactory invokeFactory(ConfigurationProvider conf, private static BrokerFactory invokeFactory(ConfigurationProvider conf,
ClassLoader loader, String methodName) ClassLoader loader, String methodName, Class<?>[] argTypes, Object[] args)
throws InvocationTargetException, NoSuchMethodException, throws InvocationTargetException, NoSuchMethodException,
IllegalAccessException { IllegalAccessException {
if (conf == null) if (conf == null)
@ -113,17 +118,17 @@ public class Bootstrap {
Class cls = getFactoryClass(conf, loader); Class cls = getFactoryClass(conf, loader);
Method meth; Method meth;
try { try {
meth = cls.getMethod(methodName, FACTORY_ARGS); meth = cls.getMethod(methodName, argTypes);
} catch (NoSuchMethodException nsme) { } catch (NoSuchMethodException nsme) {
// handle cases where there is a mismatch between loaders by falling // handle cases where there is a mismatch between loaders by falling
// back to the configuration's class loader for broker resolution // back to the configuration's class loader for broker resolution
cls = getFactoryClass(conf, cls = getFactoryClass(conf,
AccessController.doPrivileged( AccessController.doPrivileged(
J2DoPrivHelper.getClassLoaderAction(conf.getClass()))); J2DoPrivHelper.getClassLoaderAction(conf.getClass())));
meth = cls.getMethod(methodName, FACTORY_ARGS); meth = cls.getMethod(methodName, argTypes);
} }
return (BrokerFactory) meth.invoke(null, new Object[]{ conf }); return (BrokerFactory) meth.invoke(null, args);
} }
private static String getFactoryClassName(ConfigurationProvider conf, private static String getFactoryClassName(ConfigurationProvider conf,