2020import java .sql .Connection ;
2121import java .sql .Driver ;
2222import java .sql .SQLException ;
23+ import java .time .Duration ;
2324import java .util .ArrayList ;
2425import java .util .HashMap ;
2526import java .util .List ;
3031import javax .naming .NamingException ;
3132import javax .sql .DataSource ;
3233
33- import org .apache .commons .dbcp .BasicDataSource ;
34- import org .apache .commons .dbcp .DelegatingConnection ;
35- import org .apache .commons .pool .impl .GenericObjectPool ;
34+ import org .apache .commons .dbcp2 .BasicDataSource ;
35+ import org .apache .commons .dbcp2 .DelegatingConnection ;
36+ import org .apache .commons .pool2 .impl .GenericObjectPoolConfig ;
3637import org .apache .jackrabbit .core .config .DataSourceConfig ;
3738import org .apache .jackrabbit .core .config .DataSourceConfig .DataSourceDefinition ;
3839import org .apache .jackrabbit .util .Base64 ;
@@ -102,7 +103,7 @@ public void registerDataSources(DataSourceConfig dsc) throws RepositoryException
102103 BasicDataSource bds =
103104 getDriverDataSource (driverClass , def .getUrl (), def .getUser (), def .getPassword ());
104105 if (def .getMaxPoolSize () > 0 ) {
105- bds .setMaxActive (def .getMaxPoolSize ());
106+ bds .setMaxTotal (def .getMaxPoolSize ());
106107 }
107108 if (def .getValidationQuery () != null && !"" .equals (def .getValidationQuery ().trim ())) {
108109 bds .setValidationQuery (def .getValidationQuery ());
@@ -334,7 +335,7 @@ private BasicDataSource getDriverDataSource(
334335 if (instance != null ) {
335336 if (instance .jdbcCompliant ()) {
336337 // JCR-3445 At the moment the PostgreSQL isn't compliant because it doesn't implement this method...
337- ds .setValidationQueryTimeout (3 );
338+ ds .setValidationQueryTimeout (Duration . ofSeconds ( 3 ) );
338339 }
339340 }
340341 ds .setDriverClassName (driverClass .getName ());
@@ -346,14 +347,16 @@ private BasicDataSource getDriverDataSource(
346347 ds .setDefaultAutoCommit (true );
347348 ds .setTestOnBorrow (false );
348349 ds .setTestWhileIdle (true );
349- ds .setTimeBetweenEvictionRunsMillis ( 600000 ); // 10 Minutes
350- ds .setMinEvictableIdleTimeMillis ( 60000 ); // 1 Minute
351- ds .setMaxActive (-1 ); // unlimited
352- ds .setMaxIdle (GenericObjectPool .DEFAULT_MAX_IDLE + 10 );
350+ ds .setDurationBetweenEvictionRuns ( Duration . ofMinutes ( 10 ));
351+ ds .setMinEvictableIdle ( Duration . ofMinutes ( 1 ));
352+ ds .setMaxTotal (-1 ); // unlimited
353+ ds .setMaxIdle (GenericObjectPoolConfig .DEFAULT_MAX_IDLE + 10 );
353354 ds .setValidationQuery (guessValidationQuery (url ));
354355 ds .setAccessToUnderlyingConnectionAllowed (true );
355356 ds .setPoolPreparedStatements (Boolean .valueOf (System .getProperty (SYSTEM_PROPERTY_POOL_PREPARED_STATEMENTS , "true" )));
356357 ds .setMaxOpenPreparedStatements (-1 ); // unlimited
358+ // this helps to discover unusable connections of a shut-down database without executing a validation query
359+ ds .setCacheState (false );
357360 return ds ;
358361 }
359362
0 commit comments