Skip to content

Commit 808f2d9

Browse files
committed
Add validation query and testonborrow to ensure we do not attempt to use invalid connections
1 parent a8dbe2e commit 808f2d9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: service/src/main/java/bio/terra/profile/app/configuration/BaseDatabaseConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.apache.commons.dbcp2.PoolingDataSource;
99
import org.apache.commons.lang3.builder.ToStringBuilder;
1010
import org.apache.commons.lang3.builder.ToStringStyle;
11-
import org.apache.commons.pool2.ObjectPool;
1211
import org.apache.commons.pool2.impl.GenericObjectPool;
1312

1413
/** Base class for accessing database connection configuration properties. */
@@ -64,10 +63,11 @@ private void configureDataSource() {
6463

6564
PoolableConnectionFactory poolableConnectionFactory =
6665
new PoolableConnectionFactory(connectionFactory, null);
66+
poolableConnectionFactory.setValidationQuery("SELECT 1");
6767

68-
ObjectPool<PoolableConnection> connectionPool =
68+
GenericObjectPool<PoolableConnection> connectionPool =
6969
new GenericObjectPool<>(poolableConnectionFactory);
70-
70+
connectionPool.setTestOnBorrow(true);
7171
poolableConnectionFactory.setPool(connectionPool);
7272

7373
dataSource = new PoolingDataSource<>(connectionPool);

0 commit comments

Comments
 (0)