Methods Summary |
---|
public static java.util.Properties | getConnectionProperties(java.util.Properties properties)Transform JDBC connection properties.
Passed in the form hibernate.connection.* to the
format accepted by DriverManager by triming the leading "hibernate.connection".
Iterator iter = properties.keySet().iterator();
Properties result = new Properties();
while ( iter.hasNext() ) {
String prop = (String) iter.next();
if ( prop.indexOf(Environment.CONNECTION_PREFIX) > -1 && !SPECIAL_PROPERTIES.contains(prop) ) {
result.setProperty(
prop.substring( Environment.CONNECTION_PREFIX.length()+1 ),
properties.getProperty(prop)
);
}
}
String userName = properties.getProperty(Environment.USER);
if (userName!=null) result.setProperty( "user", userName );
return result;
|
public static ConnectionProvider | newConnectionProvider()Instantiate a ConnectionProvider using System properties.
return newConnectionProvider( Environment.getProperties() );
|
public static ConnectionProvider | newConnectionProvider(java.util.Properties properties)Instantiate a ConnectionProvider using given properties.
Method newConnectionProvider.
return newConnectionProvider( properties, null );
|
public static ConnectionProvider | newConnectionProvider(java.util.Properties properties, java.util.Map connectionProviderInjectionData)Instantiate a ConnectionProvider using given properties.
Method newConnectionProvider.
ConnectionProvider connections;
String providerClass = properties.getProperty(Environment.CONNECTION_PROVIDER);
if ( providerClass!=null ) {
try {
log.info("Initializing connection provider: " + providerClass);
connections = (ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();
}
catch (Exception e) {
log.fatal("Could not instantiate connection provider", e);
throw new HibernateException("Could not instantiate connection provider: " + providerClass);
}
}
else if ( properties.getProperty(Environment.DATASOURCE)!=null ) {
connections = new DatasourceConnectionProvider();
}
else if ( properties.getProperty(Environment.C3P0_MAX_SIZE)!=null ) {
connections = new C3P0ConnectionProvider();
}
else if (
properties.getProperty(Environment.PROXOOL_XML)!=null ||
properties.getProperty(Environment.PROXOOL_PROPERTIES)!=null ||
properties.getProperty(Environment.PROXOOL_EXISTING_POOL)!=null
) {
connections = new ProxoolConnectionProvider();
}
else if ( properties.getProperty(Environment.URL)!=null ) {
connections = new DriverManagerConnectionProvider();
}
else {
connections = new UserSuppliedConnectionProvider();
}
if ( connectionProviderInjectionData != null && connectionProviderInjectionData.size() != 0 ) {
//inject the data
try {
BeanInfo info = Introspector.getBeanInfo( connections.getClass() );
PropertyDescriptor[] descritors = info.getPropertyDescriptors();
int size = descritors.length;
for (int index = 0 ; index < size ; index++) {
String propertyName = descritors[index].getName();
if ( connectionProviderInjectionData.containsKey( propertyName ) ) {
Method method = descritors[index].getWriteMethod();
method.invoke( connections, new Object[] { connectionProviderInjectionData.get( propertyName ) } );
}
}
}
catch (IntrospectionException e) {
throw new HibernateException("Unable to inject objects into the conenction provider", e);
}
catch (IllegalAccessException e) {
throw new HibernateException("Unable to inject objects into the conenction provider", e);
}
catch (InvocationTargetException e) {
throw new HibernateException("Unable to inject objects into the conenction provider", e);
}
}
connections.configure(properties);
return connections;
|