Skip to content

Commit 188dfc9

Browse files
authored
JCR-4521: Update commons-dbcp dependency to 2.14.0 (#328) - ack oleosterhagen
Copied from #320 - thanks @oleosterhagen
1 parent 057bbf9 commit 188dfc9

4 files changed

Lines changed: 20 additions & 17 deletions

File tree

jackrabbit-core/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ org.apache.jackrabbit.core.version.RemoveAndAddVersionLabelXATest#testVersionLab
233233
<artifactId>commons-io</artifactId>
234234
</dependency>
235235
<dependency>
236-
<groupId>commons-dbcp</groupId>
237-
<artifactId>commons-dbcp</artifactId>
238-
<version>1.4</version>
236+
<groupId>org.apache.commons</groupId>
237+
<artifactId>commons-dbcp2</artifactId>
238+
<version>2.14.0</version>
239239
</dependency>
240240
<dependency>
241241
<groupId>javax.jcr</groupId>

jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/db/ConnectionFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import junit.framework.TestCase;
2626

27-
import org.apache.commons.dbcp.BasicDataSource;
27+
import org.apache.commons.dbcp2.BasicDataSource;
2828
import org.apache.derby.iapi.jdbc.EngineConnection;
2929
import org.apache.jackrabbit.core.config.ConfigurationException;
3030
import org.apache.jackrabbit.core.config.DataSourceConfig;
@@ -146,7 +146,7 @@ public void testClose() throws Exception {
146146
}
147147

148148
private void assertPoolDefaults(BasicDataSource ds, String validationQuery, int maxCons) {
149-
assertEquals(maxCons, ds.getMaxActive());
149+
assertEquals(maxCons, ds.getMaxTotal());
150150
assertEquals(validationQuery, ds.getValidationQuery());
151151
assertTrue(ds.getDefaultAutoCommit());
152152
assertFalse(ds.getTestOnBorrow());

jackrabbit-data/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@
8686
<artifactId>commons-io</artifactId>
8787
</dependency>
8888
<dependency>
89-
<groupId>commons-dbcp</groupId>
90-
<artifactId>commons-dbcp</artifactId>
91-
<version>1.4</version>
89+
<groupId>org.apache.commons</groupId>
90+
<artifactId>commons-dbcp2</artifactId>
91+
<version>2.14.0</version>
9292
<optional>true</optional>
9393
</dependency>
9494
<dependency>

jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.sql.Connection;
2121
import java.sql.Driver;
2222
import java.sql.SQLException;
23+
import java.time.Duration;
2324
import java.util.ArrayList;
2425
import java.util.HashMap;
2526
import java.util.List;
@@ -30,9 +31,9 @@
3031
import javax.naming.NamingException;
3132
import 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;
3637
import org.apache.jackrabbit.core.config.DataSourceConfig;
3738
import org.apache.jackrabbit.core.config.DataSourceConfig.DataSourceDefinition;
3839
import 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

Comments
 (0)