You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/07/24 23:22:13 UTC
svn commit: r1506725 -
/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
Author: markt
Date: Wed Jul 24 21:22:13 2013
New Revision: 1506725
URL: http://svn.apache.org/r1506725
Log:
Java 7 <>
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java?rev=1506725&r1=1506724&r2=1506725&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java Wed Jul 24 21:22:13 2013
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,26 +37,25 @@ import org.apache.commons.pool2.impl.Gen
/**
* <p>A pooling <code>DataSource</code> appropriate for deployment within
* J2EE environment. There are many configuration options, most of which are
- * defined in the parent class. This datasource uses individual pools per
- * user, and some properties can be set specifically for a given user, if the
+ * defined in the parent class. This datasource uses individual pools per
+ * user, and some properties can be set specifically for a given user, if the
* deployment environment can support initialization of mapped properties.
* So for example, a pool of admin or write-access Connections can be
* guaranteed a certain number of connections, separate from a maximum
* set for users with read-only connections.</p>
- *
+ *
* <p>User passwords can be changed without re-initializing the datasource.
- * When a <code>getConnection(username, password)</code> request is processed
+ * When a <code>getConnection(username, password)</code> request is processed
* with a password that is different from those used to create connections in the
* pool associated with <code>username</code>, an attempt is made to create a
* new connection using the supplied password and if this succeeds, the existing
* pool is cleared and a new pool is created for connections using the new password.</p>
- *
+ *
*
* @author John D. McNally
* @version $Revision$ $Date$
*/
-public class PerUserPoolDataSource
- extends InstanceKeyDataSource {
+public class PerUserPoolDataSource extends InstanceKeyDataSource {
private static final long serialVersionUID = -3104731034410444060L;
@@ -64,18 +63,18 @@ public class PerUserPoolDataSource
private int defaultMaxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;
private int defaultMaxWaitMillis = (int)Math.min(Integer.MAX_VALUE,
GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS);
- Map<String,Boolean> perUserDefaultAutoCommit = null;
+ Map<String,Boolean> perUserDefaultAutoCommit = null;
Map<String,Integer> perUserDefaultTransactionIsolation = null;
- Map<String,Integer> perUserMaxTotal = null;
- Map<String,Integer> perUserMaxIdle = null;
+ Map<String,Integer> perUserMaxTotal = null;
+ Map<String,Integer> perUserMaxIdle = null;
Map<String,Integer> perUserMaxWaitMillis = null;
- Map<String,Boolean> perUserDefaultReadOnly = null;
+ Map<String,Boolean> perUserDefaultReadOnly = null;
/**
* Map to keep track of Pools for a given user
*/
private transient Map<PoolKey, PooledConnectionManager> managers =
- new HashMap<PoolKey, PooledConnectionManager>();
+ new HashMap<>();
/**
* Default no-arg constructor for Serialization
@@ -146,7 +145,7 @@ public class PerUserPoolDataSource
/**
* 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 to wait indefinitely. Will fail
+ * throwing an exception, or -1 to wait indefinitely. Will fail
* immediately if value is 0.
* This value is used for any username which is not specified
* in perUserMaxWaitMillis. The default is -1.
@@ -158,7 +157,7 @@ public class PerUserPoolDataSource
/**
* 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 to wait indefinitely. Will fail
+ * throwing an exception, or -1 to wait indefinitely. Will fail
* immediately if value is 0.
* This value is used for any username which is not specified
* in perUserMaxWaitMillis. The default is -1.
@@ -170,7 +169,7 @@ public class PerUserPoolDataSource
}
/**
- * The keys are usernames and the value is the --. Any
+ * The keys are usernames and the value is the --. Any
* username specified here will override the value of defaultAutoCommit.
*/
public Boolean getPerUserDefaultAutoCommit(String key) {
@@ -180,21 +179,21 @@ public class PerUserPoolDataSource
}
return value;
}
-
+
/**
- * The keys are usernames and the value is the --. Any
+ * The keys are usernames and the value is the --. Any
* username specified here will override the value of defaultAutoCommit.
*/
public void setPerUserDefaultAutoCommit(String username, Boolean value) {
assertInitializationAllowed();
if (perUserDefaultAutoCommit == null) {
- perUserDefaultAutoCommit = new HashMap<String,Boolean>();
+ perUserDefaultAutoCommit = new HashMap<>();
}
perUserDefaultAutoCommit.put(username, value);
}
/**
- * The isolation level of connections when returned from getConnection.
+ * The isolation level of connections when returned from getConnection.
* If null, the username will use the value of defaultTransactionIsolation.
*/
public Integer getPerUserDefaultTransactionIsolation(String username) {
@@ -206,14 +205,14 @@ public class PerUserPoolDataSource
}
/**
- * The isolation level of connections when returned from getConnection.
+ * The isolation level of connections when returned from getConnection.
* Valid values are the constants defined in Connection.
*/
- public void setPerUserDefaultTransactionIsolation(String username,
+ public void setPerUserDefaultTransactionIsolation(String username,
Integer value) {
assertInitializationAllowed();
if (perUserDefaultTransactionIsolation == null) {
- perUserDefaultTransactionIsolation = new HashMap<String,Integer>();
+ perUserDefaultTransactionIsolation = new HashMap<>();
}
perUserDefaultTransactionIsolation.put(username, value);
}
@@ -221,7 +220,7 @@ public class PerUserPoolDataSource
/**
* The maximum number of active connections that can be allocated from
* this pool at the same time, or non-positive for no limit.
- * The keys are usernames and the value is the maximum connections. Any
+ * The keys are usernames and the value is the maximum connections. Any
* username specified here will override the value of defaultMaxTotal.
*/
public Integer getPerUserMaxTotal(String username) {
@@ -231,17 +230,17 @@ public class PerUserPoolDataSource
}
return value;
}
-
+
/**
* The maximum number of active connections that can be allocated from
* this pool at the same time, or non-positive for no limit.
- * The keys are usernames and the value is the maximum connections. Any
+ * The keys are usernames and the value is the maximum connections. Any
* username specified here will override the value of defaultMaxTotal.
*/
public void setPerUserMaxTotal(String username, Integer value) {
assertInitializationAllowed();
if (perUserMaxTotal == null) {
- perUserMaxTotal = new HashMap<String,Integer>();
+ perUserMaxTotal = new HashMap<>();
}
perUserMaxTotal.put(username, value);
}
@@ -250,7 +249,7 @@ public class PerUserPoolDataSource
/**
* The maximum number of active connections that can remain idle in the
* pool, without extra ones being released, or negative for no limit.
- * The keys are usernames and the value is the maximum connections. Any
+ * The keys are usernames and the value is the maximum connections. Any
* username specified here will override the value of defaultMaxIdle.
*/
public Integer getPerUserMaxIdle(String username) {
@@ -260,27 +259,27 @@ public class PerUserPoolDataSource
}
return value;
}
-
+
/**
* The maximum number of active connections that can remain idle in the
* pool, without extra ones being released, or negative for no limit.
- * The keys are usernames and the value is the maximum connections. Any
+ * The keys are usernames and the value is the maximum connections. Any
* username specified here will override the value of defaultMaxIdle.
*/
public void setPerUserMaxIdle(String username, Integer value) {
assertInitializationAllowed();
if (perUserMaxIdle == null) {
- perUserMaxIdle = new HashMap<String,Integer>();
+ perUserMaxIdle = new HashMap<>();
}
perUserMaxIdle.put(username, value);
}
-
+
/**
* 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 to wait indefinitely. Will fail
+ * throwing an exception, or -1 to wait indefinitely. Will fail
* immediately if value is 0.
- * The keys are usernames and the value is the maximum connections. Any
+ * The keys are usernames and the value is the maximum connections. Any
* username specified here will override the value of defaultMaxWaitMillis.
*/
public Integer getPerUserMaxWaitMillis(String username) {
@@ -290,25 +289,25 @@ public class PerUserPoolDataSource
}
return value;
}
-
+
/**
* 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 to wait indefinitely. Will fail
+ * throwing an exception, or -1 to wait indefinitely. Will fail
* immediately if value is 0.
- * The keys are usernames and the value is the maximum connections. Any
+ * The keys are usernames and the value is the maximum connections. Any
* username specified here will override the value of defaultMaxWaitMillis.
*/
public void setPerUserMaxWaitMillis(String username, Integer value) {
assertInitializationAllowed();
if (perUserMaxWaitMillis == null) {
- perUserMaxWaitMillis = new HashMap<String,Integer>();
+ perUserMaxWaitMillis = new HashMap<>();
}
perUserMaxWaitMillis.put(username, value);
}
/**
- * The keys are usernames and the value is the --. Any
+ * The keys are usernames and the value is the --. Any
* username specified here will override the value of defaultReadOnly.
*/
public Boolean getPerUserDefaultReadOnly(String username) {
@@ -318,15 +317,15 @@ public class PerUserPoolDataSource
}
return value;
}
-
+
/**
- * The keys are usernames and the value is the --. Any
+ * The keys are usernames and the value is the --. Any
* username specified here will override the value of defaultReadOnly.
*/
public void setPerUserDefaultReadOnly(String username, Boolean value) {
assertInitializationAllowed();
if (perUserDefaultReadOnly == null) {
- perUserDefaultReadOnly = new HashMap<String,Boolean>();
+ perUserDefaultReadOnly = new HashMap<>();
}
perUserDefaultReadOnly.put(username, value);
}
@@ -371,7 +370,7 @@ public class PerUserPoolDataSource
// Inherited abstract methods
@Override
- protected PooledConnectionAndInfo
+ protected PooledConnectionAndInfo
getPooledConnectionAndInfo(String username, String password)
throws SQLException {
@@ -429,7 +428,7 @@ public class PerUserPoolDataSource
}
@Override
- protected void setupDefaults(Connection con, String username)
+ protected void setupDefaults(Connection con, String username)
throws SQLException {
boolean defaultAutoCommit = isDefaultAutoCommit();
if (username != null) {
@@ -437,7 +436,7 @@ public class PerUserPoolDataSource
if (userMax != null) {
defaultAutoCommit = userMax.booleanValue();
}
- }
+ }
boolean defaultReadOnly = isDefaultReadOnly();
if (username != null) {
@@ -445,7 +444,7 @@ public class PerUserPoolDataSource
if (userMax != null) {
defaultReadOnly = userMax.booleanValue();
}
- }
+ }
int defaultTransactionIsolation = getDefaultTransactionIsolation();
if (username != null) {
@@ -467,7 +466,7 @@ public class PerUserPoolDataSource
con.setReadOnly(defaultReadOnly);
}
}
-
+
@Override
protected PooledConnectionManager getConnectionManager(UserPassKey upkey) {
return managers.get(
@@ -476,7 +475,7 @@ public class PerUserPoolDataSource
/**
* Returns a <code>PerUserPoolDataSource</code> {@link Reference}.
- *
+ *
* @since 1.2.2
*/
@Override
@@ -486,26 +485,26 @@ public class PerUserPoolDataSource
ref.add(new StringRefAddr("instanceKey", instanceKey));
return ref;
}
-
+
/**
* Create a pool key from the provided parameters.
- *
+ *
* @param username User name
* @param password Not currently used
* @return The pool key
*/
- private PoolKey getPoolKey(String username, String password) {
- return new PoolKey(getDataSourceName(), username);
+ private PoolKey getPoolKey(String username, String password) {
+ return new PoolKey(getDataSourceName(), username);
}
private synchronized void registerPool(
- String username, String password)
+ String username, String password)
throws javax.naming.NamingException, SQLException {
ConnectionPoolDataSource cpds = testCPDS(username, password);
Integer userMax = getPerUserMaxTotal(username);
- int maxTotal = (userMax == null) ?
+ int maxTotal = (userMax == null) ?
getDefaultMaxTotal() : userMax.intValue();
userMax = getPerUserMaxIdle(username);
int maxIdle = (userMax == null) ?
@@ -520,10 +519,10 @@ public class PerUserPoolDataSource
CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds,
getValidationQuery(), isRollbackAfterValidation(), username,
password);
-
+
// Create an object pool to contain our PooledConnections
GenericObjectPool<PooledConnectionAndInfo> pool =
- new GenericObjectPool<PooledConnectionAndInfo>(factory);
+ new GenericObjectPool<>(factory);
factory.setPool(pool);
pool.setMaxTotal(maxTotal);
pool.setMaxIdle(maxIdle);
@@ -543,7 +542,7 @@ public class PerUserPoolDataSource
pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
pool.setTestWhileIdle(getTestWhileIdle());
-
+
Object old = managers.put(getPoolKey(username,password), factory);
if (old != null) {
throw new IllegalStateException("Pool already contains an entry for this user/password: "+username);
@@ -559,7 +558,7 @@ public class PerUserPoolDataSource
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
- try
+ try
{
in.defaultReadObject();
PerUserPoolDataSource oldDS = (PerUserPoolDataSource)
@@ -572,11 +571,11 @@ public class PerUserPoolDataSource
throw new IOException("NamingException: " + e);
}
}
-
+
/**
* Returns the object pool associated with the given PoolKey.
- *
- * @param key PoolKey identifying the pool
+ *
+ * @param key PoolKey identifying the pool
* @return the GenericObjectPool pooling connections for the username and datasource
* specified by the PoolKey
*/