Provide a way to supply prebuild ConnectionProvider to Hibernate
----------------------------------------------------------------
Key: HHH-6609
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6609
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.6.7
Reporter: Christoph Läubrich
Currently it is only possible to provide a ConnectionProvider via the property
Environment.CONNECTION_PROVIDER which only accepts a class-name which later is
instantiated via ConnectionProviderFactory:
private static ConnectionProvider initializeConnectionProviderFromConfig(String
providerClass) {
ConnectionProvider connections;
try {
log.info( "Initializing connection provider: " + providerClass );
connections = (ConnectionProvider) ReflectHelper.classForName( providerClass
).newInstance();
}
catch ( Exception e ) {
log.error( "Could not instantiate connection provider", e );
throw new HibernateException( "Could not instantiate connection provider: " +
providerClass );
}
return connections;
}
This aproch is okay for connectionprovider which are very generic and can build up
completely by the configuration, but under some circumstances the creation and setup is
out of scope of the Provider implementation class.
For this case it would be helpfull to have a configuration property like
Environment.CONNECTION_PROVIDER_REFERENCE and a static public Method in the
ConnectionProviderFactory like
ConnectionProviderFactory.addConnectionProviderReference(ConnectionProvider provider,
String reference)
So it would be possible to make something like this:
ConnectionProvider provider = new MySpecialProvider(x, y, z);
provider.doSpecialSetup(d);
ConnectionProviderFactory.addConnectionProviderReference(provider,
"MySpecialProvider");
.
.
.
Configuration configuration = new Configuration();
configuration.setProperty(Environment.CONNECTION_PROVIDER_REFERENCE,
"MySpecialProvider");
SessionFactory factory = configuration.buildSessionFactory();
The only alternative to this in current days is to create a ConnectionProvider class which
completely relies on static setup methods, making the code relativly complicated and error
prone, as well as introducing class not found problems if the provider is not in the same
class loader context as hibernate or the module which creates the configuration (for
example in OSGi applications).
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira