diff --git a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java index b8a8fbd8cd..bb47c7a9c4 100644 --- a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java +++ b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2007, 2013, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution - * statements applied by the authors.  All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -27,32 +27,35 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Map; -import java.util.Properties; -import org.jboss.logging.Logger; import org.logicalcobwebs.proxool.ProxoolException; import org.logicalcobwebs.proxool.ProxoolFacade; import org.logicalcobwebs.proxool.configuration.JAXPConfigurator; import org.logicalcobwebs.proxool.configuration.PropertyConfigurator; +import org.jboss.logging.Logger; + import org.hibernate.HibernateException; import org.hibernate.cfg.Environment; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.internal.util.ConfigHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.UnknownUnwrapTypeException; -import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; /** * A connection provider that uses a Proxool connection pool. Hibernate will use this by * default if the hibernate.proxool.* properties are set. + * * @see ConnectionProvider */ public class ProxoolConnectionProvider implements ConnectionProvider, Configurable, Stoppable { - - public static final ProxoolMessageLogger LOG = Logger.getMessageLogger(ProxoolMessageLogger.class, ProxoolConnectionProvider.class.getName()); + private static final ProxoolMessageLogger LOG = Logger.getMessageLogger( + ProxoolMessageLogger.class, + ProxoolConnectionProvider.class.getName() + ); private static final String PROXOOL_JDBC_STEM = "proxool."; @@ -67,21 +70,20 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab private boolean autocommit; - /** - * Grab a connection - * @return a JDBC connection - * @throws SQLException - */ @Override public Connection getConnection() throws SQLException { - // get a connection from the pool (thru DriverManager, cfr. Proxool doc) - Connection c = DriverManager.getConnection(proxoolAlias); + // get a connection from the pool (thru DriverManager, cfr. Proxool doc) + final Connection c = DriverManager.getConnection( proxoolAlias ); // set the Transaction Isolation if defined - if (isolation!=null) c.setTransactionIsolation( isolation ); + if ( isolation != null ) { + c.setTransactionIsolation( isolation ); + } // toggle autoCommit to false if set - if ( c.getAutoCommit()!=autocommit ) c.setAutoCommit(autocommit); + if ( c.getAutoCommit() != autocommit ) { + c.setAutoCommit( autocommit ); + } // return the connection return c; @@ -94,7 +96,7 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab } @Override - @SuppressWarnings( {"unchecked"}) + @SuppressWarnings({"unchecked"}) public T unwrap(Class unwrapType) { if ( ConnectionProvider.class.equals( unwrapType ) || ProxoolConnectionProvider.class.isAssignableFrom( unwrapType ) ) { @@ -105,39 +107,28 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab } } - /** - * Dispose of a used connection. - * @param conn a JDBC connection - * @throws SQLException - */ @Override public void closeConnection(Connection conn) throws SQLException { conn.close(); } - /** - * Initialize the connection provider from given properties. - * @param props SessionFactory properties - */ @Override - public void configure(Map props) { - + public void configure(Map props) { // Get the configurator files (if available) - String jaxpFile = (String)props.get(Environment.PROXOOL_XML); - String propFile = (String)props.get(Environment.PROXOOL_PROPERTIES); - String externalConfig = (String)props.get(Environment.PROXOOL_EXISTING_POOL); + final String jaxpFile = (String) props.get( Environment.PROXOOL_XML ); + final String propFile = (String) props.get( Environment.PROXOOL_PROPERTIES ); + final String externalConfig = (String) props.get( Environment.PROXOOL_EXISTING_POOL ); // Default the Proxool alias setting - proxoolAlias = (String)props.get(Environment.PROXOOL_POOL_ALIAS); + proxoolAlias = (String) props.get( 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) ) { - + if ( "true".equals( externalConfig ) ) { // Validate that an alias name was provided to determine which pool to use if ( !StringHelper.isNotEmpty( proxoolAlias ) ) { - String msg = LOG.unableToConfigureProxoolProviderToUseExistingInMemoryPool(Environment.PROXOOL_POOL_ALIAS); - LOG.error(msg); + final String msg = LOG.unableToConfigureProxoolProviderToUseExistingInMemoryPool( Environment.PROXOOL_POOL_ALIAS ); + LOG.error( msg ); throw new HibernateException( msg ); } // Append the stem to the proxool pool alias @@ -146,77 +137,79 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab // Set the existing pool flag to true existingPool = true; - LOG.configuringProxoolProviderUsingExistingPool(proxoolAlias); + LOG.configuringProxoolProviderUsingExistingPool( proxoolAlias ); // Configured using the JAXP Configurator } else if ( StringHelper.isNotEmpty( jaxpFile ) ) { - - LOG.configuringProxoolProviderUsingJaxpConfigurator(jaxpFile); + LOG.configuringProxoolProviderUsingJaxpConfigurator( jaxpFile ); // Validate that an alias name was provided to determine which pool to use if ( !StringHelper.isNotEmpty( proxoolAlias ) ) { - String msg = LOG.unableToConfigureProxoolProviderToUseJaxp(Environment.PROXOOL_POOL_ALIAS); - LOG.error(msg); + final String msg = LOG.unableToConfigureProxoolProviderToUseJaxp( Environment.PROXOOL_POOL_ALIAS ); + LOG.error( msg ); throw new HibernateException( msg ); } try { JAXPConfigurator.configure( ConfigHelper.getConfigStreamReader( jaxpFile ), false ); } - catch ( ProxoolException e ) { - String msg = LOG.unableToLoadJaxpConfiguratorFile(jaxpFile); - LOG.error(msg, e); + catch (ProxoolException e) { + final String msg = LOG.unableToLoadJaxpConfiguratorFile( jaxpFile ); + LOG.error( msg, e ); throw new HibernateException( msg, e ); } // Append the stem to the proxool pool alias proxoolAlias = PROXOOL_JDBC_STEM + proxoolAlias; - LOG.configuringProxoolProviderToUsePoolAlias(proxoolAlias); + LOG.configuringProxoolProviderToUsePoolAlias( proxoolAlias ); // Configured using the Properties File Configurator } else if ( StringHelper.isNotEmpty( propFile ) ) { - - LOG.configuringProxoolProviderUsingPropertiesFile(propFile); + LOG.configuringProxoolProviderUsingPropertiesFile( propFile ); // Validate that an alias name was provided to determine which pool to use if ( !StringHelper.isNotEmpty( proxoolAlias ) ) { - String msg = LOG.unableToConfigureProxoolProviderToUsePropertiesFile(Environment.PROXOOL_POOL_ALIAS); - LOG.error(msg); + final String msg = LOG.unableToConfigureProxoolProviderToUsePropertiesFile( Environment.PROXOOL_POOL_ALIAS ); + LOG.error( msg ); throw new HibernateException( msg ); } try { PropertyConfigurator.configure( ConfigHelper.getConfigProperties( propFile ) ); } - catch ( ProxoolException e ) { - String msg = LOG.unableToLoadPropertyConfiguratorFile(propFile); - LOG.error(msg, e); + catch (ProxoolException e) { + final String msg = LOG.unableToLoadPropertyConfiguratorFile( propFile ); + LOG.error( msg, e ); throw new HibernateException( msg, e ); } // Append the stem to the proxool pool alias proxoolAlias = PROXOOL_JDBC_STEM + proxoolAlias; - LOG.configuringProxoolProviderToUsePoolAlias(proxoolAlias); + LOG.configuringProxoolProviderToUsePoolAlias( proxoolAlias ); } // Remember Isolation level - isolation = ConfigurationHelper.getInteger(Environment.ISOLATION, props); - if (isolation != null) LOG.jdbcIsolationLevel(Environment.isolationLevelToString(isolation.intValue())); + isolation = ConfigurationHelper.getInteger( Environment.ISOLATION, props ); + if ( isolation != null ) { + LOG.jdbcIsolationLevel( Environment.isolationLevelToString( isolation.intValue() ) ); + } - autocommit = ConfigurationHelper.getBoolean(Environment.AUTOCOMMIT, props); - LOG.autoCommmitMode(autocommit); + autocommit = ConfigurationHelper.getBoolean( Environment.AUTOCOMMIT, props ); + LOG.autoCommmitMode( autocommit ); } - /** - * Release all resources held by this provider. JavaDoc requires a second sentence. - * @throws HibernateException - */ - public void close() throws HibernateException { + @Override + public boolean supportsAggressiveRelease() { + return false; + } + + @Override + public void stop() { // If the provider was leeching off an existing pool don't close it - if (existingPool) { + if ( existingPool ) { return; } @@ -226,29 +219,28 @@ public class ProxoolConnectionProvider implements ConnectionProvider, Configurab ProxoolFacade.shutdown( 0 ); } else { - ProxoolFacade.removeConnectionPool(proxoolAlias.substring(PROXOOL_JDBC_STEM.length())); + ProxoolFacade.removeConnectionPool( proxoolAlias.substring( PROXOOL_JDBC_STEM.length() ) ); } } catch (Exception e) { // If you're closing down the ConnectionProvider chances are an // is not a real big deal, just warn - String msg = LOG.exceptionClosingProxoolPool(); - LOG.warn(msg, e); - throw new HibernateException(msg, e); + final String msg = LOG.exceptionClosingProxoolPool(); + LOG.warn( msg, e ); + throw new HibernateException( msg, e ); } } /** - * @see ConnectionProvider#supportsAggressiveRelease() + * Release all resources held by this provider. + * + * @throws HibernateException Indicates a problem closing the underlying pool or releasing resources + * + * @deprecated Use {@link #stop} instead */ - @Override - public boolean supportsAggressiveRelease() { - return false; + @Deprecated + public void close() throws HibernateException { + stop(); } - - @Override - public void stop() { - close(); - } } diff --git a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java index 568f4c98e9..5229bf66d2 100644 --- a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java +++ b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java @@ -37,44 +37,109 @@ import static org.jboss.logging.Logger.Level.INFO; *

* New messages must be added after the last message defined to ensure message codes are unique. */ -@MessageLogger( projectCode = "HHH" ) +@MessageLogger(projectCode = "HHH") public interface ProxoolMessageLogger extends CoreMessageLogger { - @LogMessage( level = INFO ) - @Message( value = "Autocommit mode: %s", id = 30001 ) - void autoCommmitMode( boolean autocommit ); + /** + * Logs the autocommit mode to be used for pooled connections + * + * @param autocommit The autocommit mode + */ + @LogMessage(level = INFO) + @Message(value = "Autocommit mode: %s", id = 30001) + void autoCommmitMode(boolean autocommit); - @LogMessage( level = INFO ) - @Message( value = "Configuring Proxool Provider to use pool alias: %s", id = 30002 ) - void configuringProxoolProviderToUsePoolAlias( String proxoolAlias ); + /** + * Logs the name of a named pool to be used for configuration information + * + * @param proxoolAlias The name (alias) of the proxool pool + */ + @LogMessage(level = INFO) + @Message(value = "Configuring Proxool Provider to use pool alias: %s", id = 30002) + void configuringProxoolProviderToUsePoolAlias(String proxoolAlias); - @LogMessage( level = INFO ) - @Message( value = "Configuring Proxool Provider using existing pool in memory: %s", id = 30003 ) - void configuringProxoolProviderUsingExistingPool( String proxoolAlias ); + /** + * Logs the name of a named existing pool in memory to be used + * + * @param proxoolAlias The name (alias) of the proxool pool + */ + @LogMessage(level = INFO) + @Message(value = "Configuring Proxool Provider using existing pool in memory: %s", id = 30003) + void configuringProxoolProviderUsingExistingPool(String proxoolAlias); - @LogMessage( level = INFO ) - @Message( value = "Configuring Proxool Provider using JAXPConfigurator: %s", id = 30004 ) - void configuringProxoolProviderUsingJaxpConfigurator( String jaxpFile ); + /** + * Logs a message that the proxool pool will be built using its JAXP (XML) configuration mechanism + * + * @param jaxpFile The XML configuration file to use + */ + @LogMessage(level = INFO) + @Message(value = "Configuring Proxool Provider using JAXPConfigurator: %s", id = 30004) + void configuringProxoolProviderUsingJaxpConfigurator(String jaxpFile); - @LogMessage( level = INFO ) - @Message( value = "Configuring Proxool Provider using Properties File: %s", id = 30005 ) - void configuringProxoolProviderUsingPropertiesFile( String proxoolAlias ); + /** + * Logs a message that the proxool pool will be built using a properties file + * + * @param propFile The properties file to use + */ + @LogMessage(level = INFO) + @Message(value = "Configuring Proxool Provider using Properties File: %s", id = 30005) + void configuringProxoolProviderUsingPropertiesFile(String propFile); - @Message( value = "Exception occured when closing the Proxool pool", id = 30006 ) - String exceptionClosingProxoolPool(); + /** + * Builds a message about not being able to close the underlying proxool pool. + * + * @return The message + */ + @Message(value = "Exception occured when closing the Proxool pool", id = 30006) + String exceptionClosingProxoolPool(); - @Message( value = "Cannot configure Proxool Provider to use an existing in memory pool without the %s property set.", id = 30007 ) - String unableToConfigureProxoolProviderToUseExistingInMemoryPool( String proxoolPoolAlias ); + /** + * Builds a message about invalid configuration + * + * @param proxoolPoolAlias The name (alias) of the proxool pool + * + * @return The message + */ + @Message(value = "Cannot configure Proxool Provider to use an existing in memory pool without the %s property set.", id = 30007) + String unableToConfigureProxoolProviderToUseExistingInMemoryPool(String proxoolPoolAlias); - @Message( value = "Cannot configure Proxool Provider to use JAXP without the %s property set.", id = 30008 ) - String unableToConfigureProxoolProviderToUseJaxp( String proxoolPoolAlias ); + /** + * Builds a message about invalid configuration + * + * @param proxoolPoolAlias The name (alias) of the proxool pool + * + * @return The message + */ + @Message(value = "Cannot configure Proxool Provider to use JAXP without the %s property set.", id = 30008) + String unableToConfigureProxoolProviderToUseJaxp(String proxoolPoolAlias); - @Message( value = "Cannot configure Proxool Provider to use Properties File without the %s property set.", id = 30009 ) - String unableToConfigureProxoolProviderToUsePropertiesFile( String proxoolPoolAlias ); + /** + * Builds a message about invalid configuration + * + * @param proxoolPoolAlias The name (alias) of the proxool pool + * + * @return The message + */ + @Message(value = "Cannot configure Proxool Provider to use Properties File without the %s property set.", id = 30009) + String unableToConfigureProxoolProviderToUsePropertiesFile(String proxoolPoolAlias); - @Message( value = "Proxool Provider unable to load JAXP configurator file: %s", id = 30010 ) - String unableToLoadJaxpConfiguratorFile( String jaxpFile ); + /** + * Builds a message about not being able to find or load the XML configuration file + * + * @param jaxpFile The XML file + * + * @return The message + */ + @Message(value = "Proxool Provider unable to load JAXP configurator file: %s", id = 30010) + String unableToLoadJaxpConfiguratorFile(String jaxpFile); - @Message( value = "Proxool Provider unable to load Property configurator file: %s", id = 30011 ) - String unableToLoadPropertyConfiguratorFile( String propFile ); + /** + * Builds a message about not being able to find or load the properties configuration file + * + * @param propFile The properties file + * + * @return The message + */ + @Message(value = "Proxool Provider unable to load Property configurator file: %s", id = 30011) + String unableToLoadPropertyConfiguratorFile(String propFile); } diff --git a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/StrategyRegistrationProviderImpl.java b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/StrategyRegistrationProviderImpl.java index 7104d50399..c5c5c720cf 100644 --- a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/StrategyRegistrationProviderImpl.java +++ b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/StrategyRegistrationProviderImpl.java @@ -38,15 +38,16 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; * @author Brett Meyer */ public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { - private static final List REGISTRATIONS = Collections.singletonList( - (StrategyRegistration) new SimpleStrategyRegistrationImpl( + (StrategyRegistration) new SimpleStrategyRegistrationImpl( ConnectionProvider.class, ProxoolConnectionProvider.class, "proxool", ProxoolConnectionProvider.class.getSimpleName(), - "org.hibernate.connection.ProxoolConnectionProvider", // legacy - "org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider" // legacy + // legacy + "org.hibernate.connection.ProxoolConnectionProvider", + // legacy + "org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider" ) ); @Override diff --git a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/package-info.java b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/package-info.java new file mode 100644 index 0000000000..bc3b68bf9e --- /dev/null +++ b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementation of ConnectionProvider using the proxool Connection pool. + */ +package org.hibernate.proxool.internal;