From 0937ca96dcdaa0096b12b8cb0d300434fc21c7ac Mon Sep 17 00:00:00 2001 From: tpylak <tpylak> Date: Tue, 13 Jul 2010 13:21:49 +0000 Subject: [PATCH] DatabaseConfigurationContext: allow to set a timeout when trying to get a connection from a pool SVN: 17008 --- .../cisd/dbmigration/BasicDataSourceFactory.java | 8 ++++++++ .../cisd/dbmigration/DatabaseConfigurationContext.java | 10 ++++++++++ .../systemsx/cisd/dbmigration/IDataSourceFactory.java | 6 ++++++ .../server/dataaccess/db/SqlUnitMigrationTest.java | 4 ++++ 4 files changed, 28 insertions(+) diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/BasicDataSourceFactory.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/BasicDataSourceFactory.java index 0f5a8db5694..a70b7c4e4fb 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/BasicDataSourceFactory.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/BasicDataSourceFactory.java @@ -33,6 +33,8 @@ public class BasicDataSourceFactory implements IDataSourceFactory /** @see GenericObjectPool#DEFAULT_MAX_IDLE */ private final int DEFAULT_MAX_IDLE = DEFAULT_MAX_ACTIVE; + private long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT; + private int maxIdle = DEFAULT_MAX_IDLE; private int maxActive = DEFAULT_MAX_ACTIVE; @@ -51,9 +53,15 @@ public class BasicDataSourceFactory implements IDataSourceFactory dataSource.setPassword(password); dataSource.setMaxIdle(maxIdle); dataSource.setMaxActive(maxActive); + dataSource.setMaxWait(maxWait); return dataSource; } + public void setMaxWait(long maxWait) + { + this.maxWait = maxWait; + } + public void setMaxIdle(int maxIdle) { this.maxIdle = maxIdle; diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java index 02bc4af51c4..5231c63f57b 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java @@ -391,6 +391,16 @@ public class DatabaseConfigurationContext implements DisposableBean } } + /** + * The maximum number of milliseconds that the pool will wait (when there are no available + * connections) for a connection to be returned before throwing an exception, or -1 (by default) + * to wait indefinitely. + */ + public void setMaxWait(long maxWait) + { + this.dataSourceFactory.setMaxWait(maxWait); + } + /** * Sets the maximum number of idle connections in the pool (default is 20). */ diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/IDataSourceFactory.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/IDataSourceFactory.java index 39d73c62e4e..b97d14ad809 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/IDataSourceFactory.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/IDataSourceFactory.java @@ -44,4 +44,10 @@ public interface IDataSourceFactory * @see GenericObjectPool#DEFAULT_MAX_ACTIVE */ public void setMaxActive(int maxActive); + + /** + * @see BasicDataSource#setMaxWait(long) + * @see GenericObjectPool#DEFAULT_MAX_WAIT + */ + public void setMaxWait(long maxWait); } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SqlUnitMigrationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SqlUnitMigrationTest.java index 9244725886d..dfe55683fe7 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SqlUnitMigrationTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SqlUnitMigrationTest.java @@ -174,6 +174,10 @@ public final class SqlUnitMigrationTest public void setMaxIdle(int maxIdle) { } + + public void setMaxWait(long maxWait) + { + } }; @BeforeClass(alwaysRun = true) -- GitLab