mirror of https://github.com/apache/openjpa.git
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:
parent
ea8dc8b630
commit
3905b52a90
|
@ -65,7 +65,7 @@ public class JDBCBrokerFactory
|
|||
* Factory method for obtaining a possibly-pooled factory from properties.
|
||||
* 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();
|
||||
Object key = toPoolKey(props);
|
||||
JDBCBrokerFactory factory = (JDBCBrokerFactory) getPooledFactoryForKey(key);
|
||||
|
@ -73,7 +73,7 @@ public class JDBCBrokerFactory
|
|||
return factory;
|
||||
|
||||
// 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);
|
||||
return factory;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,11 @@ import org.apache.openjpa.util.UserException;
|
|||
*/
|
||||
public class Bootstrap {
|
||||
|
||||
private static final Class[] FACTORY_ARGS =
|
||||
new Class[]{ 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);
|
||||
|
||||
|
@ -59,7 +62,8 @@ public class Bootstrap {
|
|||
public static BrokerFactory newBrokerFactory(ConfigurationProvider conf,
|
||||
ClassLoader loader) {
|
||||
try {
|
||||
BrokerFactory factory = invokeFactory(conf, loader, "newInstance");
|
||||
BrokerFactory factory =
|
||||
invokeFactory(conf, loader, "newInstance", CONFIGURATION_ARG, new Object[] { conf });
|
||||
factory.postCreationCallback();
|
||||
return factory;
|
||||
} catch (InvocationTargetException ite) {
|
||||
|
@ -89,7 +93,8 @@ public class Bootstrap {
|
|||
public static BrokerFactory getBrokerFactory(ConfigurationProvider conf,
|
||||
ClassLoader loader) {
|
||||
try {
|
||||
return invokeFactory(conf, loader, "getInstance");
|
||||
return invokeFactory(conf, loader, "getInstance", CONFIGURATION_CLASSLOADER_ARGS, new Object[] { conf,
|
||||
loader });
|
||||
} catch (InvocationTargetException ite) {
|
||||
Throwable cause = ite.getTargetException();
|
||||
if (cause instanceof OpenJPAException)
|
||||
|
@ -103,7 +108,7 @@ public class Bootstrap {
|
|||
}
|
||||
|
||||
private static BrokerFactory invokeFactory(ConfigurationProvider conf,
|
||||
ClassLoader loader, String methodName)
|
||||
ClassLoader loader, String methodName, Class<?>[] argTypes, Object[] args)
|
||||
throws InvocationTargetException, NoSuchMethodException,
|
||||
IllegalAccessException {
|
||||
if (conf == null)
|
||||
|
@ -113,17 +118,17 @@ public class Bootstrap {
|
|||
Class cls = getFactoryClass(conf, loader);
|
||||
Method meth;
|
||||
try {
|
||||
meth = cls.getMethod(methodName, FACTORY_ARGS);
|
||||
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, 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,
|
||||
|
|
Loading…
Reference in New Issue