You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2015/05/03 11:07:55 UTC

[3/4] cayenne git commit: CAY-2008 Connection pool refactoring and validation query support in Cayenne DataSource

CAY-2008 Connection pool refactoring and validation query support in Cayenne DataSource

* fixing API omissions - ServerRuntimeBuilder support for validation query


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/e8f62a68
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/e8f62a68
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/e8f62a68

Branch: refs/heads/master
Commit: e8f62a686f43e2c0b034d736c9419f930aeb3d81
Parents: 4e9352e
Author: aadamchik <aa...@apache.org>
Authored: Sat May 2 14:51:25 2015 +0200
Committer: aadamchik <aa...@apache.org>
Committed: Sat May 2 17:44:14 2015 -0400

----------------------------------------------------------------------
 .../apache/cayenne/configuration/Constants.java    |  5 +++++
 .../server/PropertyDataSourceFactory.java          |  3 ++-
 .../configuration/server/ServerRuntimeBuilder.java | 17 +++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/e8f62a68/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
index 1b0f887..a94f19b 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/Constants.java
@@ -92,6 +92,11 @@ public interface Constants {
 	public static final String JDBC_MAX_CONNECTIONS_PROPERTY = "cayenne.jdbc.max_connections";
 
 	/**
+	 * @since 4.0
+	 */
+	public static final String JDBC_VALIDATION_QUERY_PROPERTY = "cayenne.jdbc.validation_query";
+
+	/**
 	 * An integer property defining the maximum number of entries in the query
 	 * cache. Note that not all QueryCache providers may respect this property.
 	 * MapQueryCache uses it, but the rest would use alternative configuration

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e8f62a68/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/PropertyDataSourceFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/PropertyDataSourceFactory.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/PropertyDataSourceFactory.java
index 87d18de..60bf717 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/PropertyDataSourceFactory.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/PropertyDataSourceFactory.java
@@ -71,10 +71,11 @@ public class PropertyDataSourceFactory implements DataSourceFactory {
 		int maxConnections = getIntProperty(Constants.JDBC_MAX_CONNECTIONS_PROPERTY, suffix, 1);
 		long maxQueueWaitTime = properties.getLong(Constants.SERVER_MAX_QUEUE_WAIT_TIME,
 				PoolingDataSource.MAX_QUEUE_WAIT_DEFAULT);
+		String validationQuery = properties.get(Constants.JDBC_VALIDATION_QUERY_PROPERTY);
 
 		return DataSourceBuilder.builder(objectFactory, jdbcEventLogger).driver(driverClass).url(url)
 				.userName(username).password(password).minConnections(minConnections).maxConnections(maxConnections)
-				.maxQueueWaitTime(maxQueueWaitTime).build();
+				.maxQueueWaitTime(maxQueueWaitTime).validationQuery(validationQuery).build();
 	}
 
 	protected int getIntProperty(String propertyName, String suffix, int defaultValue) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e8f62a68/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
index 33dc60e..55bb852 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
@@ -56,6 +56,7 @@ public class ServerRuntimeBuilder {
 	private String jdbcPassword;
 	private int jdbcMinConnections;
 	private int jdbcMaxConnections;
+	private String validationQuery;
 
 	/**
 	 * Creates an empty builder.
@@ -112,6 +113,18 @@ public class ServerRuntimeBuilder {
 	}
 
 	/**
+	 * Sets a validation query for the default DataSource.
+	 * 
+	 * @param validationQuery
+	 *            a SQL string that returns some result. It will be used to
+	 *            validate connections in the pool.
+	 */
+	public ServerRuntimeBuilder validationQuery(String validationQuery) {
+		this.validationQuery = validationQuery;
+		return this;
+	}
+
+	/**
 	 * Sets a user name for the default DataSource.
 	 */
 	public ServerRuntimeBuilder user(String user) {
@@ -234,6 +247,10 @@ public class ServerRuntimeBuilder {
 						props.put(Constants.JDBC_MAX_CONNECTIONS_PROPERTY, Integer.toString(jdbcMaxConnections));
 					}
 
+					if (validationQuery != null) {
+						props.put(Constants.JDBC_VALIDATION_QUERY_PROPERTY, validationQuery);
+					}
+
 				}
 			});
 		}