HHH-8159 - Apply fixups indicated by analysis tools
This commit is contained in:
parent
d2ec514894
commit
9b37f2a297
|
@ -31,6 +31,7 @@ import java.util.Properties;
|
|||
import javax.sql.DataSource;
|
||||
|
||||
import com.mchange.v2.c3p0.DataSources;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
@ -56,22 +57,25 @@ import org.hibernate.service.spi.Stoppable;
|
|||
public class C3P0ConnectionProvider
|
||||
implements ConnectionProvider, Configurable, Stoppable, ServiceRegistryAwareService {
|
||||
|
||||
private static final C3P0MessageLogger LOG = Logger.getMessageLogger(C3P0MessageLogger.class, C3P0ConnectionProvider.class.getName());
|
||||
private static final C3P0MessageLogger LOG = Logger.getMessageLogger(
|
||||
C3P0MessageLogger.class,
|
||||
C3P0ConnectionProvider.class.getName()
|
||||
);
|
||||
|
||||
//swaldman 2006-08-28: define c3p0-style configuration parameters for properties with
|
||||
// hibernate-specific overrides to detect and warn about conflicting
|
||||
// declarations
|
||||
private final static String C3P0_STYLE_MIN_POOL_SIZE = "c3p0.minPoolSize";
|
||||
private final static String C3P0_STYLE_MAX_POOL_SIZE = "c3p0.maxPoolSize";
|
||||
private final static String C3P0_STYLE_MAX_IDLE_TIME = "c3p0.maxIdleTime";
|
||||
private final static String C3P0_STYLE_MAX_STATEMENTS = "c3p0.maxStatements";
|
||||
private final static String C3P0_STYLE_ACQUIRE_INCREMENT = "c3p0.acquireIncrement";
|
||||
private final static String C3P0_STYLE_IDLE_CONNECTION_TEST_PERIOD = "c3p0.idleConnectionTestPeriod";
|
||||
private static final String C3P0_STYLE_MIN_POOL_SIZE = "c3p0.minPoolSize";
|
||||
private static final String C3P0_STYLE_MAX_POOL_SIZE = "c3p0.maxPoolSize";
|
||||
private static final String C3P0_STYLE_MAX_IDLE_TIME = "c3p0.maxIdleTime";
|
||||
private static final String C3P0_STYLE_MAX_STATEMENTS = "c3p0.maxStatements";
|
||||
private static final String C3P0_STYLE_ACQUIRE_INCREMENT = "c3p0.acquireIncrement";
|
||||
private static final String C3P0_STYLE_IDLE_CONNECTION_TEST_PERIOD = "c3p0.idleConnectionTestPeriod";
|
||||
|
||||
//swaldman 2006-08-28: define c3p0-style configuration parameters for initialPoolSize, which
|
||||
// hibernate sensibly lets default to minPoolSize, but we'll let users
|
||||
// override it with the c3p0-style property if they want.
|
||||
private final static String C3P0_STYLE_INITIAL_POOL_SIZE = "c3p0.initialPoolSize";
|
||||
private static final String C3P0_STYLE_INITIAL_POOL_SIZE = "c3p0.initialPoolSize";
|
||||
|
||||
private DataSource ds;
|
||||
private Integer isolation;
|
||||
|
@ -122,9 +126,9 @@ public class C3P0ConnectionProvider
|
|||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public void configure(Map props) {
|
||||
String jdbcDriverClass = (String) props.get( Environment.DRIVER );
|
||||
String jdbcUrl = (String) props.get( Environment.URL );
|
||||
Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( props );
|
||||
final String jdbcDriverClass = (String) props.get( Environment.DRIVER );
|
||||
final String jdbcUrl = (String) props.get( Environment.URL );
|
||||
final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( props );
|
||||
|
||||
LOG.c3p0UsingDriver( jdbcDriverClass, jdbcUrl );
|
||||
LOG.connectionProperties( ConfigurationHelper.maskOut( connectionProps, "password" ) );
|
||||
|
@ -147,14 +151,14 @@ public class C3P0ConnectionProvider
|
|||
try {
|
||||
|
||||
//swaldman 2004-02-07: modify to allow null values to signify fall through to c3p0 PoolConfig defaults
|
||||
Integer minPoolSize = ConfigurationHelper.getInteger( Environment.C3P0_MIN_SIZE, props );
|
||||
Integer maxPoolSize = ConfigurationHelper.getInteger( Environment.C3P0_MAX_SIZE, props );
|
||||
Integer maxIdleTime = ConfigurationHelper.getInteger( Environment.C3P0_TIMEOUT, props );
|
||||
Integer maxStatements = ConfigurationHelper.getInteger( Environment.C3P0_MAX_STATEMENTS, props );
|
||||
Integer acquireIncrement = ConfigurationHelper.getInteger( Environment.C3P0_ACQUIRE_INCREMENT, props );
|
||||
Integer idleTestPeriod = ConfigurationHelper.getInteger( Environment.C3P0_IDLE_TEST_PERIOD, props );
|
||||
final Integer minPoolSize = ConfigurationHelper.getInteger( Environment.C3P0_MIN_SIZE, props );
|
||||
final Integer maxPoolSize = ConfigurationHelper.getInteger( Environment.C3P0_MAX_SIZE, props );
|
||||
final Integer maxIdleTime = ConfigurationHelper.getInteger( Environment.C3P0_TIMEOUT, props );
|
||||
final Integer maxStatements = ConfigurationHelper.getInteger( Environment.C3P0_MAX_STATEMENTS, props );
|
||||
final Integer acquireIncrement = ConfigurationHelper.getInteger( Environment.C3P0_ACQUIRE_INCREMENT, props );
|
||||
final Integer idleTestPeriod = ConfigurationHelper.getInteger( Environment.C3P0_IDLE_TEST_PERIOD, props );
|
||||
|
||||
Properties c3props = new Properties();
|
||||
final Properties c3props = new Properties();
|
||||
|
||||
// turn hibernate.c3p0.* into c3p0.*, so c3p0
|
||||
// gets a chance to see all hibernate.c3p0.*
|
||||
|
@ -182,22 +186,23 @@ public class C3P0ConnectionProvider
|
|||
Environment.C3P0_ACQUIRE_INCREMENT, C3P0_STYLE_ACQUIRE_INCREMENT, props, c3props, acquireIncrement
|
||||
);
|
||||
setOverwriteProperty(
|
||||
Environment.C3P0_IDLE_TEST_PERIOD, C3P0_STYLE_IDLE_CONNECTION_TEST_PERIOD, props, c3props, idleTestPeriod
|
||||
Environment.C3P0_IDLE_TEST_PERIOD,
|
||||
C3P0_STYLE_IDLE_CONNECTION_TEST_PERIOD,
|
||||
props,
|
||||
c3props,
|
||||
idleTestPeriod
|
||||
);
|
||||
|
||||
// revert to traditional hibernate behavior of setting initialPoolSize to minPoolSize
|
||||
// unless otherwise specified with a c3p0.*-style parameter.
|
||||
Integer initialPoolSize = ConfigurationHelper.getInteger( C3P0_STYLE_INITIAL_POOL_SIZE, props );
|
||||
final Integer initialPoolSize = ConfigurationHelper.getInteger( C3P0_STYLE_INITIAL_POOL_SIZE, props );
|
||||
if ( initialPoolSize == null && minPoolSize != null ) {
|
||||
c3props.put( C3P0_STYLE_INITIAL_POOL_SIZE, String.valueOf( minPoolSize ).trim() );
|
||||
}
|
||||
|
||||
/*DataSource unpooled = DataSources.unpooledDataSource(
|
||||
jdbcUrl, props.getProperty(Environment.USER), props.getProperty(Environment.PASS)
|
||||
);*/
|
||||
DataSource unpooled = DataSources.unpooledDataSource( jdbcUrl, connectionProps );
|
||||
final DataSource unpooled = DataSources.unpooledDataSource( jdbcUrl, connectionProps );
|
||||
|
||||
Map allProps = new HashMap();
|
||||
final Map allProps = new HashMap();
|
||||
allProps.putAll( props );
|
||||
allProps.putAll( c3props );
|
||||
|
||||
|
@ -208,8 +213,10 @@ public class C3P0ConnectionProvider
|
|||
throw new HibernateException( LOG.unableToInstantiateC3p0ConnectionPool(), e );
|
||||
}
|
||||
|
||||
String i = (String) props.get( Environment.ISOLATION );
|
||||
if (i == null) isolation = null;
|
||||
final String i = (String) props.get( Environment.ISOLATION );
|
||||
if ( i == null ) {
|
||||
isolation = null;
|
||||
}
|
||||
else {
|
||||
isolation = Integer.valueOf( i );
|
||||
LOG.jdbcIsolationLevel( Environment.isolationLevelToString( isolation ) );
|
||||
|
@ -217,28 +224,24 @@ public class C3P0ConnectionProvider
|
|||
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
DataSources.destroy( ds );
|
||||
}
|
||||
catch ( SQLException sqle ) {
|
||||
LOG.unableToDestroyC3p0ConnectionPool(sqle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setOverwriteProperty(String hibernateStyleKey, String c3p0StyleKey, Map hibp, Properties c3p, Integer value) {
|
||||
private void setOverwriteProperty(
|
||||
String hibernateStyleKey,
|
||||
String c3p0StyleKey,
|
||||
Map hibp,
|
||||
Properties c3p,
|
||||
Integer value) {
|
||||
if ( value != null ) {
|
||||
String peeledC3p0Key = c3p0StyleKey.substring(5);
|
||||
final String peeledC3p0Key = c3p0StyleKey.substring( 5 );
|
||||
c3p.put( peeledC3p0Key, String.valueOf( value ).trim() );
|
||||
if ( hibp.containsKey( c3p0StyleKey ) ) {
|
||||
warnPropertyConflict( hibernateStyleKey, c3p0StyleKey );
|
||||
}
|
||||
String longC3p0StyleKey = "hibernate." + c3p0StyleKey;
|
||||
final String longC3p0StyleKey = "hibernate." + c3p0StyleKey;
|
||||
if ( hibp.containsKey( longC3p0StyleKey ) ) {
|
||||
warnPropertyConflict( hibernateStyleKey, longC3p0StyleKey );
|
||||
}
|
||||
|
@ -251,7 +254,22 @@ public class C3P0ConnectionProvider
|
|||
|
||||
@Override
|
||||
public void stop() {
|
||||
close();
|
||||
try {
|
||||
DataSources.destroy( ds );
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
LOG.unableToDestroyC3p0ConnectionPool( sqle );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the provider.
|
||||
*
|
||||
* @deprecated Use {@link #stop} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void close() {
|
||||
stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -44,26 +44,51 @@ import static org.jboss.logging.Logger.Level.WARN;
|
|||
@MessageLogger(projectCode = "HHH")
|
||||
public interface C3P0MessageLogger extends CoreMessageLogger {
|
||||
|
||||
/**
|
||||
* Log a message (WARN) about conflicting {@code hibernate.c3p0.XYZ} and {@code c3p0.XYZ} settings
|
||||
*
|
||||
* @param hibernateStyle The {@code hibernate.c3p0} prefixed setting
|
||||
* @param c3p0Style The {@code c3p0.} prefixed setting
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message( value = "Both hibernate-style property '%s' and c3p0-style property '%s' have been set in hibernate.properties. "
|
||||
+ "Hibernate-style property '%s' will be used and c3p0-style property '%s' will be ignored!", id = 10001 )
|
||||
void bothHibernateAndC3p0StylesSet( String hibernateStyle,
|
||||
String c3p0Style,
|
||||
String hibernateStyle2,
|
||||
String c3p0Style2 );
|
||||
@Message(value = "Both hibernate-style property '%1$s' and c3p0-style property '%2$s' have been set in Hibernate "
|
||||
+ "properties. Hibernate-style property '%1$s' will be used and c3p0-style property '2$%s' will be ignored!", id = 10001)
|
||||
void bothHibernateAndC3p0StylesSet(String hibernateStyle,String c3p0Style);
|
||||
|
||||
/**
|
||||
* Log a message (INFO) about which Driver class is being used.
|
||||
*
|
||||
* @param jdbcDriverClass The JDBC Driver class
|
||||
* @param jdbcUrl The JDBC URL
|
||||
*/
|
||||
@LogMessage(level = INFO)
|
||||
@Message(value = "C3P0 using driver: %s at URL: %s", id = 10002)
|
||||
void c3p0UsingDriver( String jdbcDriverClass,
|
||||
String jdbcUrl );
|
||||
void c3p0UsingDriver(String jdbcDriverClass, String jdbcUrl);
|
||||
|
||||
/**
|
||||
* Build a message about not being able to find the JDBC driver class
|
||||
*
|
||||
* @param jdbcDriverClass The JDBC driver class we could not find
|
||||
*
|
||||
* @return The message
|
||||
*/
|
||||
@Message(value = "JDBC Driver class not found: %s", id = 10003)
|
||||
String jdbcDriverNotFound(String jdbcDriverClass);
|
||||
|
||||
/**
|
||||
* Log a message (WARN) about not being able to stop the underlying c3p0 pool.
|
||||
*
|
||||
* @param e The exception when we tried to stop pool
|
||||
*/
|
||||
@LogMessage(level = WARN)
|
||||
@Message(value = "Could not destroy C3P0 connection pool", id = 10004)
|
||||
void unableToDestroyC3p0ConnectionPool(@Cause SQLException e);
|
||||
|
||||
/**
|
||||
* Build a message about not being able to start the underlying c3p0 pool.
|
||||
*
|
||||
* @return The message
|
||||
*/
|
||||
@Message(value = "Could not instantiate C3P0 connection pool", id = 10005)
|
||||
String unableToInstantiateC3p0ConnectionPool();
|
||||
}
|
||||
|
|
|
@ -38,16 +38,18 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
|||
* @author Brett Meyer
|
||||
*/
|
||||
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider {
|
||||
|
||||
private static final List<StrategyRegistration> REGISTRATIONS = Collections.singletonList(
|
||||
(StrategyRegistration) new SimpleStrategyRegistrationImpl(
|
||||
(StrategyRegistration) new SimpleStrategyRegistrationImpl<ConnectionProvider>(
|
||||
ConnectionProvider.class,
|
||||
C3P0ConnectionProvider.class,
|
||||
"c3p0",
|
||||
C3P0ConnectionProvider.class.getSimpleName(),
|
||||
"org.hibernate.connection.C3P0ConnectionProvider", // legacy
|
||||
"org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" // legacy
|
||||
) );
|
||||
// legacy
|
||||
"org.hibernate.connection.C3P0ConnectionProvider",
|
||||
// legacy
|
||||
"org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"
|
||||
)
|
||||
);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
/**
|
||||
* Implementation of ConnectionProvider using the c3p0 Connection pool.
|
||||
*/
|
||||
package org.hibernate.c3p0.internal;
|
Loading…
Reference in New Issue