25
25
26
26
import java .sql .Connection ;
27
27
import java .sql .SQLException ;
28
+ import java .util .HashMap ;
28
29
import java .util .Iterator ;
30
+ import java .util .Map ;
29
31
import java .util .Properties ;
30
32
import javax .sql .DataSource ;
31
33
import org .hibernate .HibernateException ;
34
36
import org .hibernate .internal .util .config .ConfigurationHelper ;
35
37
import org .hibernate .service .jdbc .connections .spi .ConnectionProvider ;
36
38
import org .hibernate .service .UnknownUnwrapTypeException ;
39
+ import org .hibernate .service .spi .Configurable ;
40
+ import org .hibernate .service .spi .Stoppable ;
41
+
37
42
import org .jboss .logging .Logger ;
38
43
import com .mchange .v2 .c3p0 .DataSources ;
39
44
44
49
* @author various people
45
50
* @see ConnectionProvider
46
51
*/
47
- public class C3P0ConnectionProvider implements ConnectionProvider {
52
+ public class C3P0ConnectionProvider implements ConnectionProvider , Configurable , Stoppable {
48
53
49
54
private static final C3P0MessageLogger LOG = Logger .getMessageLogger (C3P0MessageLogger .class , C3P0ConnectionProvider .class .getName ());
50
55
@@ -57,7 +62,6 @@ public class C3P0ConnectionProvider implements ConnectionProvider {
57
62
private final static String C3P0_STYLE_MAX_STATEMENTS = "c3p0.maxStatements" ;
58
63
private final static String C3P0_STYLE_ACQUIRE_INCREMENT = "c3p0.acquireIncrement" ;
59
64
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";
61
65
62
66
//swaldman 2006-08-28: define c3p0-style configuration parameters for initialPoolSize, which
63
67
// hibernate sensibly lets default to minPoolSize, but we'll let users
@@ -114,9 +118,10 @@ else if ( DataSource.class.isAssignableFrom( unwrapType ) ) {
114
118
/**
115
119
* {@inheritDoc}
116
120
*/
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 );
120
125
Properties connectionProps = ConnectionProviderInitiator .getConnectionProperties ( props );
121
126
122
127
LOG .c3p0UsingDriver (jdbcDriverClass , jdbcUrl );
@@ -192,7 +197,8 @@ public void configure(Properties props) throws HibernateException {
192
197
);*/
193
198
DataSource unpooled = DataSources .unpooledDataSource ( jdbcUrl , connectionProps );
194
199
195
- Properties allProps = ( Properties ) props .clone ();
200
+ Map allProps = new HashMap ();
201
+ allProps .putAll ( props );
196
202
allProps .putAll ( c3props );
197
203
198
204
ds = DataSources .pooledDataSource ( unpooled , allProps );
@@ -202,7 +208,7 @@ public void configure(Properties props) throws HibernateException {
202
208
throw new HibernateException (LOG .unableToInstantiateC3p0ConnectionPool (), e );
203
209
}
204
210
205
- String i = props .getProperty ( Environment .ISOLATION );
211
+ String i = ( String ) props .get ( Environment .ISOLATION );
206
212
if (i == null ) isolation = null ;
207
213
else {
208
214
isolation = new Integer ( i );
@@ -230,14 +236,14 @@ public boolean supportsAggressiveRelease() {
230
236
return false ;
231
237
}
232
238
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 ) {
234
240
if ( value != null ) {
235
241
c3p .put ( c3p0StyleKey , String .valueOf ( value ).trim () );
236
- if ( hibp .getProperty ( c3p0StyleKey ) != null ) {
242
+ if ( hibp .containsKey ( c3p0StyleKey ) ) {
237
243
warnPropertyConflict ( hibernateStyleKey , c3p0StyleKey );
238
244
}
239
245
String longC3p0StyleKey = "hibernate." + c3p0StyleKey ;
240
- if ( hibp .getProperty ( longC3p0StyleKey ) != null ) {
246
+ if ( hibp .containsKey ( longC3p0StyleKey ) ) {
241
247
warnPropertyConflict ( hibernateStyleKey , longC3p0StyleKey );
242
248
}
243
249
}
@@ -246,4 +252,9 @@ private void setOverwriteProperty(String hibernateStyleKey, String c3p0StyleKey,
246
252
private void warnPropertyConflict (String hibernateStyle , String c3p0Style ) {
247
253
LOG .bothHibernateAndC3p0StylesSet (hibernateStyle , c3p0Style , hibernateStyle , c3p0Style );
248
254
}
255
+
256
+ @ Override
257
+ public void stop () {
258
+ close ();
259
+ }
249
260
}
0 commit comments