Skip to content

Commit a8ee266

Browse files
committed
HHH-6327 NPE when using JDBC connection pool C3pO
1 parent afc406a commit a8ee266

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

hibernate-c3p0/src/main/java/org/hibernate/service/jdbc/connections/internal/C3P0ConnectionProvider.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
import java.sql.Connection;
2727
import java.sql.SQLException;
28+
import java.util.HashMap;
2829
import java.util.Iterator;
30+
import java.util.Map;
2931
import java.util.Properties;
3032
import javax.sql.DataSource;
3133
import org.hibernate.HibernateException;
@@ -34,6 +36,9 @@
3436
import org.hibernate.internal.util.config.ConfigurationHelper;
3537
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
3638
import org.hibernate.service.UnknownUnwrapTypeException;
39+
import org.hibernate.service.spi.Configurable;
40+
import org.hibernate.service.spi.Stoppable;
41+
3742
import org.jboss.logging.Logger;
3843
import com.mchange.v2.c3p0.DataSources;
3944

@@ -44,7 +49,7 @@
4449
* @author various people
4550
* @see ConnectionProvider
4651
*/
47-
public class C3P0ConnectionProvider implements ConnectionProvider {
52+
public class C3P0ConnectionProvider implements ConnectionProvider, Configurable, Stoppable {
4853

4954
private static final C3P0MessageLogger LOG = Logger.getMessageLogger(C3P0MessageLogger.class, C3P0ConnectionProvider.class.getName());
5055

@@ -57,7 +62,6 @@ public class C3P0ConnectionProvider implements ConnectionProvider {
5762
private final static String C3P0_STYLE_MAX_STATEMENTS = "c3p0.maxStatements";
5863
private final static String C3P0_STYLE_ACQUIRE_INCREMENT = "c3p0.acquireIncrement";
5964
private final static String C3P0_STYLE_IDLE_CONNECTION_TEST_PERIOD = "c3p0.idleConnectionTestPeriod";
60-
// private final static String C3P0_STYLE_TEST_CONNECTION_ON_CHECKOUT = "c3p0.testConnectionOnCheckout";
6165

6266
//swaldman 2006-08-28: define c3p0-style configuration parameters for initialPoolSize, which
6367
// hibernate sensibly lets default to minPoolSize, but we'll let users
@@ -114,9 +118,10 @@ else if ( DataSource.class.isAssignableFrom( unwrapType ) ) {
114118
/**
115119
* {@inheritDoc}
116120
*/
117-
public void configure(Properties props) throws HibernateException {
118-
String jdbcDriverClass = props.getProperty( Environment.DRIVER );
119-
String jdbcUrl = props.getProperty( Environment.URL );
121+
@Override
122+
public void configure(Map props) {
123+
String jdbcDriverClass = (String) props.get( Environment.DRIVER );
124+
String jdbcUrl = (String) props.get( Environment.URL );
120125
Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( props );
121126

122127
LOG.c3p0UsingDriver(jdbcDriverClass, jdbcUrl);
@@ -192,7 +197,8 @@ public void configure(Properties props) throws HibernateException {
192197
);*/
193198
DataSource unpooled = DataSources.unpooledDataSource( jdbcUrl, connectionProps );
194199

195-
Properties allProps = ( Properties ) props.clone();
200+
Map allProps = new HashMap();
201+
allProps.putAll( props );
196202
allProps.putAll( c3props );
197203

198204
ds = DataSources.pooledDataSource( unpooled, allProps );
@@ -202,7 +208,7 @@ public void configure(Properties props) throws HibernateException {
202208
throw new HibernateException(LOG.unableToInstantiateC3p0ConnectionPool(), e);
203209
}
204210

205-
String i = props.getProperty( Environment.ISOLATION );
211+
String i = (String) props.get( Environment.ISOLATION );
206212
if (i == null) isolation = null;
207213
else {
208214
isolation = new Integer( i );
@@ -230,14 +236,14 @@ public boolean supportsAggressiveRelease() {
230236
return false;
231237
}
232238

233-
private void setOverwriteProperty(String hibernateStyleKey, String c3p0StyleKey, Properties hibp, Properties c3p, Integer value) {
239+
private void setOverwriteProperty(String hibernateStyleKey, String c3p0StyleKey, Map hibp, Properties c3p, Integer value) {
234240
if ( value != null ) {
235241
c3p.put( c3p0StyleKey, String.valueOf( value ).trim() );
236-
if ( hibp.getProperty( c3p0StyleKey ) != null ) {
242+
if ( hibp.containsKey( c3p0StyleKey ) ) {
237243
warnPropertyConflict( hibernateStyleKey, c3p0StyleKey );
238244
}
239245
String longC3p0StyleKey = "hibernate." + c3p0StyleKey;
240-
if ( hibp.getProperty( longC3p0StyleKey ) != null ) {
246+
if ( hibp.containsKey( longC3p0StyleKey ) ) {
241247
warnPropertyConflict( hibernateStyleKey, longC3p0StyleKey );
242248
}
243249
}
@@ -246,4 +252,9 @@ private void setOverwriteProperty(String hibernateStyleKey, String c3p0StyleKey,
246252
private void warnPropertyConflict(String hibernateStyle, String c3p0Style) {
247253
LOG.bothHibernateAndC3p0StylesSet(hibernateStyle, c3p0Style, hibernateStyle, c3p0Style);
248254
}
255+
256+
@Override
257+
public void stop() {
258+
close();
259+
}
249260
}

0 commit comments

Comments
 (0)