public void configure(Properties props) throws HibernateException {
// Get the configurator files (if available)
String jaxpFile = props.getProperty(Environment.PROXOOL_XML);
String propFile = props.getProperty(Environment.PROXOOL_PROPERTIES);
String externalConfig = props.getProperty(Environment.PROXOOL_EXISTING_POOL);
// Default the Proxool alias setting
proxoolAlias = props.getProperty(Environment.PROXOOL_POOL_ALIAS);
// Configured outside of Hibernate (i.e. Servlet container, or Java Bean Container
// already has Proxool pools running, and this provider is to just borrow one of these
if ( "true".equals(externalConfig) ) {
// Validate that an alias name was provided to determine which pool to use
if ( !StringHelper.isNotEmpty( proxoolAlias ) ) {
String msg = "Cannot configure Proxool Provider to use an existing in memory pool without the " + Environment.PROXOOL_POOL_ALIAS + " property set.";
log.error( msg );
throw new HibernateException( msg );
}
// Append the stem to the proxool pool alias
proxoolAlias = PROXOOL_JDBC_STEM + proxoolAlias;
// Set the existing pool flag to true
existingPool = true;
log.info( "Configuring Proxool Provider using existing pool in memory: " + proxoolAlias );
// Configured using the JAXP Configurator
}
else if ( StringHelper.isNotEmpty( jaxpFile ) ) {
log.info( "Configuring Proxool Provider using JAXPConfigurator: " + jaxpFile );
// Validate that an alias name was provided to determine which pool to use
if ( !StringHelper.isNotEmpty( proxoolAlias ) ) {
String msg = "Cannot configure Proxool Provider to use JAXP without the " + Environment.PROXOOL_POOL_ALIAS + " property set.";
log.error( msg );
throw new HibernateException( msg );
}
try {
JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader( jaxpFile ), false );
}
catch ( ProxoolException e ) {
String msg = "Proxool Provider unable to load JAXP configurator file: " + jaxpFile;
log.error( msg, e );
throw new HibernateException( msg, e );
}
// Append the stem to the proxool pool alias
proxoolAlias = PROXOOL_JDBC_STEM + proxoolAlias;
log.info("Configuring Proxool Provider to use pool alias: " + proxoolAlias);
// Configured using the Properties File Configurator
}
else if ( StringHelper.isNotEmpty( propFile ) ) {
log.info( "Configuring Proxool Provider using Properties File: " + propFile );
// Validate that an alias name was provided to determine which pool to use
if ( !StringHelper.isNotEmpty( proxoolAlias ) ) {
String msg = "Cannot configure Proxool Provider to use Properties File without the " + Environment.PROXOOL_POOL_ALIAS + " property set.";
log.error( msg );
throw new HibernateException( msg );
}
try {
PropertyConfigurator.configure( ConfigHelper.getConfigProperties( propFile ) );
}
catch ( ProxoolException e ) {
String msg = "Proxool Provider unable to load load Property configurator file: " + propFile;
log.error( msg, e );
throw new HibernateException( msg, e );
}
// Append the stem to the proxool pool alias
proxoolAlias = PROXOOL_JDBC_STEM + proxoolAlias;
log.info("Configuring Proxool Provider to use pool alias: " + proxoolAlias);
}
// Remember Isolation level
isolation = PropertiesHelper.getInteger(Environment.ISOLATION, props);
if (isolation!=null) {
log.info("JDBC isolation level: " + Environment.isolationLevelToString( isolation.intValue() ) );
}
autocommit = PropertiesHelper.getBoolean(Environment.AUTOCOMMIT, props);
log.info("autocommit mode: " + autocommit);
}
Initialize the connection provider from given properties. |