Repository: commons-dbcp Updated Branches: refs/heads/master 15a5cf886 -> e7ee9481e
Line length 120 and standard formatting. Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/e7ee9481 Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/e7ee9481 Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/e7ee9481 Branch: refs/heads/master Commit: e7ee9481ed978b1571fab43fde8da46439e9d503 Parents: 15a5cf8 Author: Gary Gregory <garydgreg...@gmail.com> Authored: Mon Jun 11 17:22:46 2018 -0600 Committer: Gary Gregory <garydgreg...@gmail.com> Committed: Mon Jun 11 17:22:46 2018 -0600 ---------------------------------------------------------------------- .../datasources/CPDSConnectionFactory.java | 99 ++++++------- .../datasources/InstanceKeyDataSource.java | 15 +- .../datasources/KeyedCPDSConnectionFactory.java | 17 +-- .../datasources/PerUserPoolDataSource.java | 138 +++++++++---------- .../datasources/PooledConnectionAndInfo.java | 2 +- .../datasources/PooledConnectionManager.java | 32 +++-- .../dbcp2/datasources/SharedPoolDataSource.java | 42 +++--- .../SharedPoolDataSourceFactory.java | 12 +- 8 files changed, 162 insertions(+), 195 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java index e3c0d2e..08f75e5 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java @@ -37,17 +37,14 @@ import org.apache.commons.pool2.PooledObjectFactory; import org.apache.commons.pool2.impl.DefaultPooledObject; /** - * A {@link PooledObjectFactory} that creates - * {@link org.apache.commons.dbcp2.PoolableConnection PoolableConnection}s. + * A {@link PooledObjectFactory} that creates {@link org.apache.commons.dbcp2.PoolableConnection PoolableConnection}s. * * @since 2.0 */ class CPDSConnectionFactory implements PooledObjectFactory<PooledConnectionAndInfo>, ConnectionEventListener, PooledConnectionManager { - private static final String NO_KEY_MESSAGE - = "close() was called on a Connection, but " - + "I have no record of the underlying PooledConnection."; + private static final String NO_KEY_MESSAGE = "close() was called on a Connection, but I have no record of the underlying PooledConnection."; private final ConnectionPoolDataSource cpds; private final String validationQuery; @@ -59,17 +56,15 @@ class CPDSConnectionFactory private long maxConnLifetimeMillis = -1; /** - * Map of PooledConnections for which close events are ignored. - * Connections are muted when they are being validated. + * Map of PooledConnections for which close events are ignored. Connections are muted when they are being validated. */ - private final Set<PooledConnection> validatingSet = - Collections.newSetFromMap(new ConcurrentHashMap<PooledConnection,Boolean>()); + private final Set<PooledConnection> validatingSet = Collections + .newSetFromMap(new ConcurrentHashMap<PooledConnection, Boolean>()); /** * Map of PooledConnectionAndInfo instances */ - private final Map<PooledConnection, PooledConnectionAndInfo> pcMap = - new ConcurrentHashMap<>(); + private final Map<PooledConnection, PooledConnectionAndInfo> pcMap = new ConcurrentHashMap<>(); /** * Creates a new {@code PoolableConnectionFactory}. @@ -90,12 +85,9 @@ class CPDSConnectionFactory * The password to use to create connections * @since 2.4.0 */ - public CPDSConnectionFactory(final ConnectionPoolDataSource cpds, - final String validationQuery, - final int validationQueryTimeoutSeconds, - final boolean rollbackAfterValidation, - final String userName, - final char[] userPassword) { + public CPDSConnectionFactory(final ConnectionPoolDataSource cpds, final String validationQuery, + final int validationQueryTimeoutSeconds, final boolean rollbackAfterValidation, final String userName, + final char[] userPassword) { this.cpds = cpds; this.validationQuery = validationQuery; this.validationQueryTimeoutSeconds = validationQueryTimeoutSeconds; @@ -122,12 +114,9 @@ class CPDSConnectionFactory * @param userPassword * The password to use to create connections */ - public CPDSConnectionFactory(final ConnectionPoolDataSource cpds, - final String validationQuery, - final int validationQueryTimeoutSeconds, - final boolean rollbackAfterValidation, - final String userName, - final String userPassword) { + public CPDSConnectionFactory(final ConnectionPoolDataSource cpds, final String validationQuery, + final int validationQueryTimeoutSeconds, final boolean rollbackAfterValidation, final String userName, + final String userPassword) { this(cpds, validationQuery, validationQueryTimeoutSeconds, rollbackAfterValidation, userName, Utils.toCharArray(userPassword)); } @@ -143,8 +132,8 @@ class CPDSConnectionFactory /** * - * @param pool the {@link ObjectPool} in which to pool those {@link - * Connection}s + * @param pool + * the {@link ObjectPool} in which to pool those {@link Connection}s */ public void setPool(final ObjectPool<PooledConnectionAndInfo> pool) { this.pool = pool; @@ -184,7 +173,7 @@ class CPDSConnectionFactory doDestroyObject(p.getObject()); } - private void doDestroyObject(final PooledConnectionAndInfo pci) throws Exception{ + private void doDestroyObject(final PooledConnectionAndInfo pci) throws Exception { final PooledConnection pc = pci.getPooledConnection(); pc.removeConnectionEventListener(this); pcMap.remove(pc); @@ -263,10 +252,9 @@ class CPDSConnectionFactory // *********************************************************************** /** - * This will be called if the Connection returned by the getConnection - * method came from a PooledConnection, and the user calls the close() - * method of this connection object. What we need to do here is to - * release this PooledConnection from our pool... + * This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the + * user calls the close() method of this connection object. What we need to do here is to release this + * PooledConnection from our pool... */ @Override public void connectionClosed(final ConnectionEvent event) { @@ -282,14 +270,12 @@ class CPDSConnectionFactory try { pool.returnObject(pci); } catch (final Exception e) { - System.err.println("CLOSING DOWN CONNECTION AS IT COULD " - + "NOT BE RETURNED TO THE POOL"); + System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL"); pc.removeConnectionEventListener(this); try { doDestroyObject(pci); } catch (final Exception e2) { - System.err.println("EXCEPTION WHILE DESTROYING OBJECT " - + pci); + System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci); e2.printStackTrace(); } } @@ -297,16 +283,13 @@ class CPDSConnectionFactory } /** - * If a fatal error occurs, close the underlying physical connection so as - * not to be returned in the future + * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future */ @Override public void connectionErrorOccurred(final ConnectionEvent event) { - final PooledConnection pc = (PooledConnection)event.getSource(); + final PooledConnection pc = (PooledConnection) event.getSource(); if (null != event.getSQLException()) { - System.err.println( - "CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" - + event.getSQLException() + ")"); + System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")"); } pc.removeConnectionEventListener(this); @@ -327,10 +310,9 @@ class CPDSConnectionFactory // *********************************************************************** /** - * Invalidates the PooledConnection in the pool. The CPDSConnectionFactory - * closes the connection and pool counters are updated appropriately. - * Also closes the pool. This ensures that all idle connections are closed - * and connections that are checked out are closed on return. + * Invalidates the PooledConnection in the pool. The CPDSConnectionFactory closes the connection and pool counters + * are updated appropriately. Also closes the pool. This ensures that all idle connections are closed and + * connections that are checked out are closed on return. */ @Override public void invalidate(final PooledConnection pc) throws SQLException { @@ -339,8 +321,8 @@ class CPDSConnectionFactory throw new IllegalStateException(NO_KEY_MESSAGE); } try { - pool.invalidateObject(pci); // Destroy instance and update pool counters - pool.close(); // Clear any other instances in this pool and kill others as they come back + pool.invalidateObject(pci); // Destroy instance and update pool counters + pool.close(); // Clear any other instances in this pool and kill others as they come back } catch (final Exception ex) { throw new SQLException("Error invalidating connection", ex); } @@ -349,7 +331,8 @@ class CPDSConnectionFactory /** * Sets the database password used when creating new connections. * - * @param userPassword new password + * @param userPassword + * new password */ public synchronized void setPassword(final char[] userPassword) { this.userPassword = userPassword; @@ -358,7 +341,8 @@ class CPDSConnectionFactory /** * Sets the database password used when creating new connections. * - * @param userPassword new password + * @param userPassword + * new password */ @Override public synchronized void setPassword(final String userPassword) { @@ -366,19 +350,19 @@ class CPDSConnectionFactory } /** - * Sets the maximum lifetime in milliseconds of a connection after which the - * connection will always fail activation, passivation and validation. + * Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation, + * passivation and validation. * - * @param maxConnLifetimeMillis A value of zero or less indicates an - * infinite lifetime. The default value is -1. + * @param maxConnLifetimeMillis + * A value of zero or less indicates an infinite lifetime. The default value is -1. */ public void setMaxConnLifetimeMillis(final long maxConnLifetimeMillis) { this.maxConnLifetimeMillis = maxConnLifetimeMillis; } /** - * Verifies that the user name matches the user whose connections are being managed by this - * factory and closes the pool if this is the case; otherwise does nothing. + * Verifies that the user name matches the user whose connections are being managed by this factory and closes the + * pool if this is the case; otherwise does nothing. */ @Override public void closePool(final String userName) throws SQLException { @@ -394,14 +378,11 @@ class CPDSConnectionFactory } } - private void validateLifetime(final PooledObject<PooledConnectionAndInfo> p) - throws Exception { + private void validateLifetime(final PooledObject<PooledConnectionAndInfo> p) throws Exception { if (maxConnLifetimeMillis > 0) { final long lifetime = System.currentTimeMillis() - p.getCreateTime(); if (lifetime > maxConnLifetimeMillis) { - throw new Exception(Utils.getMessage( - "connectionFactory.lifetimeExceeded", - Long.valueOf(lifetime), + throw new Exception(Utils.getMessage("connectionFactory.lifetimeExceeded", Long.valueOf(lifetime), Long.valueOf(maxConnLifetimeMillis))); } } http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java index f7e6af9..b72a03c 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java @@ -530,7 +530,8 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable } /** - * Sets the backend ConnectionPoolDataSource. This property should not be set if using jndi to access the datasource. + * Sets the backend ConnectionPoolDataSource. This property should not be set if using jndi to access the + * datasource. * * @param v * Value to assign to connectionPoolDataSource. @@ -602,9 +603,9 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable } /** - * Gets the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can - * be changed on the Connection using Connection.setReadOnly(boolean). The default is <code>null</code> which will - * use the default value for the drive. + * Gets the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value + * can be changed on the Connection using Connection.setReadOnly(boolean). The default is <code>null</code> which + * will use the default value for the drive. * * @return value of defaultReadOnly. */ @@ -613,9 +614,9 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable } /** - * Sets the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can - * be changed on the Connection using Connection.setReadOnly(boolean). The default is <code>null</code> which will - * use the default value for the drive. + * Sets the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value + * can be changed on the Connection using Connection.setReadOnly(boolean). The default is <code>null</code> which + * will use the default value for the drive. * * @param v * Value to assign to defaultReadOnly. http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java index baac0c9..a755ebf 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java @@ -53,7 +53,7 @@ class KeyedCPDSConnectionFactory implements KeyedPooledObjectFactory<UserPassKey private final String validationQuery; private final int validationQueryTimeoutSeconds; private final boolean rollbackAfterValidation; - private KeyedObjectPool<UserPassKey,PooledConnectionAndInfo> pool; + private KeyedObjectPool<UserPassKey, PooledConnectionAndInfo> pool; private long maxConnLifetimeMillis = -1; /** @@ -81,17 +81,15 @@ class KeyedCPDSConnectionFactory implements KeyedPooledObjectFactory<UserPassKey * @param rollbackAfterValidation * whether a rollback should be issued after {@link #validateObject validating} {@link Connection}s. */ - public KeyedCPDSConnectionFactory(final ConnectionPoolDataSource cpds, - final String validationQuery, - final int validationQueryTimeoutSeconds, - final boolean rollbackAfterValidation) { + public KeyedCPDSConnectionFactory(final ConnectionPoolDataSource cpds, final String validationQuery, + final int validationQueryTimeoutSeconds, final boolean rollbackAfterValidation) { this.cpds = cpds; this.validationQuery = validationQuery; this.validationQueryTimeoutSeconds = validationQueryTimeoutSeconds; this.rollbackAfterValidation = rollbackAfterValidation; } - public void setPool(final KeyedObjectPool<UserPassKey,PooledConnectionAndInfo> pool) { + public void setPool(final KeyedObjectPool<UserPassKey, PooledConnectionAndInfo> pool) { this.pool = pool; } @@ -341,14 +339,11 @@ class KeyedCPDSConnectionFactory implements KeyedPooledObjectFactory<UserPassKey } } - private void validateLifetime(final PooledObject<PooledConnectionAndInfo> p) - throws Exception { + private void validateLifetime(final PooledObject<PooledConnectionAndInfo> p) throws Exception { if (maxConnLifetimeMillis > 0) { final long lifetime = System.currentTimeMillis() - p.getCreateTime(); if (lifetime > maxConnLifetimeMillis) { - throw new Exception(Utils.getMessage( - "connectionFactory.lifetimeExceeded", - Long.valueOf(lifetime), + throw new Exception(Utils.getMessage("connectionFactory.lifetimeExceeded", Long.valueOf(lifetime), Long.valueOf(maxConnLifetimeMillis))); } } http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index afabcd1..1087b37 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -36,22 +36,21 @@ import org.apache.commons.pool2.ObjectPool; import org.apache.commons.pool2.impl.GenericObjectPool; /** - * <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 - * 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> + * 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 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 - * 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> + * <p> + * User passwords can be changed without re-initializing the datasource. 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> * * @since 2.0 */ @@ -154,7 +153,8 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { /** * Gets the number of active connections in the pool for a given user. * - * @param userName The user name key. + * @param userName + * The user name key. * @return The user specific value. */ @SuppressWarnings("resource") @@ -172,11 +172,11 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { return getNumIdle(null); } - /** * Gets the number of idle connections in the pool for a given user. * - * @param userName The user name key. + * @param userName + * The user name key. * @return The user specific value. */ @SuppressWarnings("resource") @@ -219,7 +219,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { return value; } - /** * Gets the user specific default value for {@link Connection#setReadOnly(boolean)} for the specified user's pool. * @@ -270,7 +269,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { return value; } - /** * Gets the user specific value for {@link GenericObjectPool#getLifo()} for the specified user's pool or the default * if no user specific value is defined. @@ -328,7 +326,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { return value.intValue(); } - /** * Gets the user specific value for {@link GenericObjectPool#getMaxWaitMillis()} for the specified user's pool or * the default if no user specific value is defined. @@ -386,7 +383,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { return value.intValue(); } - /** * Gets the user specific value for {@link GenericObjectPool#getNumTestsPerEvictionRun()} for the specified user's * pool or the default if no user specific value is defined. @@ -444,7 +440,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { return value.booleanValue(); } - /** * Gets the user specific value for {@link GenericObjectPool#getTestOnCreate()} for the specified user's pool or the * default if no user specific value is defined. @@ -534,9 +529,8 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { } @Override - protected PooledConnectionAndInfo - getPooledConnectionAndInfo(final String userName, final String password) - throws SQLException { + protected PooledConnectionAndInfo getPooledConnectionAndInfo(final String userName, final String password) + throws SQLException { final PoolKey key = getPoolKey(userName); ObjectPool<PooledConnectionAndInfo> pool; @@ -589,14 +583,14 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { /** * Creates a pool key from the provided parameters. * - * @param userName User name - * @return The pool key + * @param userName + * User name + * @return The pool key */ private PoolKey getPoolKey(final String userName) { return new PoolKey(getDataSourceName(), userName); } - /** * Returns a <code>PerUserPoolDataSource</code> {@link Reference}. */ @@ -610,9 +604,12 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { /** * Supports Serialization interface. * - * @param in a <code>java.io.ObjectInputStream</code> value - * @throws IOException if an error occurs - * @throws ClassNotFoundException if an error occurs + * @param in + * a <code>java.io.ObjectInputStream</code> value + * @throws IOException + * if an error occurs + * @throws ClassNotFoundException + * if an error occurs */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { try { @@ -677,8 +674,10 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { /** * Sets a user specific value for {@link GenericObjectPool#getBlockWhenExhausted()} for the specified user's pool. * - * @param userName The user name key. - * @param value The user specific value. + * @param userName + * The user name key. + * @param value + * The user specific value. */ public void setPerUserBlockWhenExhausted(final String userName, final Boolean value) { assertInitializationAllowed(); @@ -688,7 +687,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserBlockWhenExhausted.put(userName, value); } - void setPerUserDefaultAutoCommit(final Map<String,Boolean> userDefaultAutoCommit) { + void setPerUserDefaultAutoCommit(final Map<String, Boolean> userDefaultAutoCommit) { assertInitializationAllowed(); if (perUserDefaultAutoCommit == null) { perUserDefaultAutoCommit = createMap(); @@ -714,7 +713,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserDefaultAutoCommit.put(userName, value); } - void setPerUserDefaultReadOnly(final Map<String, Boolean> userDefaultReadOnly) { assertInitializationAllowed(); if (perUserDefaultReadOnly == null) { @@ -741,8 +739,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserDefaultReadOnly.put(userName, value); } - void setPerUserDefaultTransactionIsolation( - final Map<String, Integer> userDefaultTransactionIsolation) { + void setPerUserDefaultTransactionIsolation(final Map<String, Integer> userDefaultTransactionIsolation) { assertInitializationAllowed(); if (perUserDefaultTransactionIsolation == null) { perUserDefaultTransactionIsolation = new HashMap<>(); @@ -752,7 +749,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserDefaultTransactionIsolation.putAll(userDefaultTransactionIsolation); } - /** * Sets a user specific default value for {@link Connection#setTransactionIsolation(int)} for the specified user's * pool. @@ -770,8 +766,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserDefaultTransactionIsolation.put(userName, value); } - void setPerUserEvictionPolicyClassName( - final Map<String,String> userDefaultEvictionPolicyClassName) { + void setPerUserEvictionPolicyClassName(final Map<String, String> userDefaultEvictionPolicyClassName) { assertInitializationAllowed(); if (perUserEvictionPolicyClassName == null) { perUserEvictionPolicyClassName = new HashMap<>(); @@ -834,7 +829,6 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserMaxIdle.putAll(userDefaultMaxIdle); } - /** * Sets a user specific value for {@link GenericObjectPool#getMaxIdle()} for the specified user's pool. * @@ -877,9 +871,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserMaxTotal.put(userName, value); } - - void setPerUserMaxWaitMillis( - final Map<String,Long> userDefaultMaxWaitMillis) { + void setPerUserMaxWaitMillis(final Map<String, Long> userDefaultMaxWaitMillis) { assertInitializationAllowed(); if (perUserMaxWaitMillis == null) { perUserMaxWaitMillis = new HashMap<>(); @@ -905,19 +897,16 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserMaxWaitMillis.put(userName, value); } - void setPerUserMinEvictableIdleTimeMillis( - final Map<String,Long> userDefaultMinEvictableIdleTimeMillis) { + void setPerUserMinEvictableIdleTimeMillis(final Map<String, Long> userDefaultMinEvictableIdleTimeMillis) { assertInitializationAllowed(); if (perUserMinEvictableIdleTimeMillis == null) { perUserMinEvictableIdleTimeMillis = new HashMap<>(); } else { perUserMinEvictableIdleTimeMillis.clear(); } - perUserMinEvictableIdleTimeMillis.putAll( - userDefaultMinEvictableIdleTimeMillis); + perUserMinEvictableIdleTimeMillis.putAll(userDefaultMinEvictableIdleTimeMillis); } - /** * Sets a user specific value for {@link GenericObjectPool#getMinEvictableIdleTimeMillis()} for the specified user's * pool. @@ -961,9 +950,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserMinIdle.put(userName, value); } - - void setPerUserNumTestsPerEvictionRun( - final Map<String, Integer> userDefaultNumTestsPerEvictionRun) { + void setPerUserNumTestsPerEvictionRun(final Map<String, Integer> userDefaultNumTestsPerEvictionRun) { assertInitializationAllowed(); if (perUserNumTestsPerEvictionRun == null) { perUserNumTestsPerEvictionRun = new HashMap<>(); @@ -990,8 +977,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserNumTestsPerEvictionRun.put(userName, value); } - void setPerUserSoftMinEvictableIdleTimeMillis( - final Map<String,Long> userDefaultSoftMinEvictableIdleTimeMillis) { + void setPerUserSoftMinEvictableIdleTimeMillis(final Map<String, Long> userDefaultSoftMinEvictableIdleTimeMillis) { assertInitializationAllowed(); if (perUserSoftMinEvictableIdleTimeMillis == null) { perUserSoftMinEvictableIdleTimeMillis = new HashMap<>(); @@ -1044,7 +1030,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserTestOnBorrow.put(userName, value); } - void setPerUserTestOnCreate(final Map<String,Boolean> userDefaultTestOnCreate) { + void setPerUserTestOnCreate(final Map<String, Boolean> userDefaultTestOnCreate) { assertInitializationAllowed(); if (perUserTestOnCreate == null) { perUserTestOnCreate = createMap(); @@ -1054,12 +1040,13 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserTestOnCreate.putAll(userDefaultTestOnCreate); } - /** * Sets a user specific value for {@link GenericObjectPool#getTestOnCreate()} for the specified user's pool. * - * @param userName The user name key. - * @param value The user specific value. + * @param userName + * The user name key. + * @param value + * The user specific value. */ public void setPerUserTestOnCreate(final String userName, final Boolean value) { assertInitializationAllowed(); @@ -1069,8 +1056,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserTestOnCreate.put(userName, value); } - void setPerUserTestOnReturn( - final Map<String,Boolean> userDefaultTestOnReturn) { + void setPerUserTestOnReturn(final Map<String, Boolean> userDefaultTestOnReturn) { assertInitializationAllowed(); if (perUserTestOnReturn == null) { perUserTestOnReturn = createMap(); @@ -1083,8 +1069,10 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { /** * Sets a user specific value for {@link GenericObjectPool#getTestOnReturn()} for the specified user's pool. * - * @param userName The user name key. - * @param value The user specific value. + * @param userName + * The user name key. + * @param value + * The user specific value. */ public void setPerUserTestOnReturn(final String userName, final Boolean value) { assertInitializationAllowed(); @@ -1094,8 +1082,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { perUserTestOnReturn.put(userName, value); } - void setPerUserTestWhileIdle( - final Map<String,Boolean> userDefaultTestWhileIdle) { + void setPerUserTestWhileIdle(final Map<String, Boolean> userDefaultTestWhileIdle) { assertInitializationAllowed(); if (perUserTestWhileIdle == null) { perUserTestWhileIdle = createMap(); @@ -1108,8 +1095,10 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { /** * Sets a user specific value for {@link GenericObjectPool#getTestWhileIdle()} for the specified user's pool. * - * @param userName The user name key. - * @param value The user specific value. + * @param userName + * The user name key. + * @param value + * The user specific value. */ public void setPerUserTestWhileIdle(final String userName, final Boolean value) { assertInitializationAllowed(); @@ -1133,8 +1122,10 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { * Sets a user specific value for {@link GenericObjectPool#getTimeBetweenEvictionRunsMillis ()} for the specified * user's pool. * - * @param userName The user name key. - * @param value The user specific value. + * @param userName + * The user name key. + * @param value + * The user specific value. */ public void setPerUserTimeBetweenEvictionRunsMillis(final String userName, final Long value) { assertInitializationAllowed(); @@ -1145,8 +1136,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { } @Override - protected void setupDefaults(final Connection con, final String userName) - throws SQLException { + protected void setupDefaults(final Connection con, final String userName) throws SQLException { Boolean defaultAutoCommit = isDefaultAutoCommit(); if (userName != null) { final Boolean userMax = getPerUserDefaultAutoCommit(userName); @@ -1171,8 +1161,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { } } - if (defaultAutoCommit != null && - con.getAutoCommit() != defaultAutoCommit.booleanValue()) { + if (defaultAutoCommit != null && con.getAutoCommit() != defaultAutoCommit.booleanValue()) { con.setAutoCommit(defaultAutoCommit.booleanValue()); } @@ -1180,8 +1169,7 @@ public class PerUserPoolDataSource extends InstanceKeyDataSource { con.setTransactionIsolation(defaultTransactionIsolation); } - if (defaultReadOnly != null && - con.isReadOnly() != defaultReadOnly.booleanValue()) { + if (defaultReadOnly != null && con.isReadOnly() != defaultReadOnly.booleanValue()) { con.setReadOnly(defaultReadOnly.booleanValue()); } } http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java b/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java index 68b0ff4..bd1a35e 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java @@ -48,7 +48,7 @@ final class PooledConnectionAndInfo { */ @Deprecated PooledConnectionAndInfo(final PooledConnection pc, final String userName, final String userPassword) { - this(pc, userName, Utils.toCharArray(userPassword)); + this(pc, userName, Utils.toCharArray(userPassword)); } PooledConnection getPooledConnection() { http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionManager.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionManager.java b/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionManager.java index dfb0080..2959f06 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionManager.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionManager.java @@ -29,34 +29,38 @@ import javax.sql.PooledConnection; interface PooledConnectionManager { /** - * Closes the PooledConnection and remove it from the connection pool - * to which it belongs, adjusting pool counters. + * Closes the PooledConnection and remove it from the connection pool to which it belongs, adjusting pool counters. * - * @param pc PooledConnection to be invalidated - * @throws SQLException if an SQL error occurs closing the connection + * @param pc + * PooledConnection to be invalidated + * @throws SQLException + * if an SQL error occurs closing the connection */ void invalidate(PooledConnection pc) throws SQLException; -// /** -// * Sets the database password used when creating connections. -// * -// * @param password password used when authenticating to the database -// * @since 3.0.0 -// */ -// void setPassword(char[] password); + // /** + // * Sets the database password used when creating connections. + // * + // * @param password password used when authenticating to the database + // * @since 3.0.0 + // */ + // void setPassword(char[] password); /** * Sets the database password used when creating connections. * - * @param password password used when authenticating to the database + * @param password + * password used when authenticating to the database */ void setPassword(String password); /** * Closes the connection pool associated with the given user. * - * @param userName user name - * @throws SQLException if an error occurs closing idle connections in the pool + * @param userName + * user name + * @throws SQLException + * if an error occurs closing idle connections in the pool */ void closePool(String userName) throws SQLException; http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java index f7b7c3e..cf3e556 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java @@ -32,18 +32,19 @@ import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; /** - * <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. All users (based on user name) share a single - * maximum number of Connections in this data source.</p> + * <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. All users (based on user name) share a single maximum number + * of Connections in this data source. + * </p> * - * <p>User passwords can be changed without re-initializing the data source. - * When a <code>getConnection(user name, password)</code> request is processed - * with a password that is different from those used to create connections in the - * pool associated with <code>user name</code>, an attempt is made to create a - * new connection using the supplied password and if this succeeds, idle connections - * created using the old password are destroyed and new connections are created - * using the new password.</p> + * <p> + * User passwords can be changed without re-initializing the data source. When a + * <code>getConnection(user name, password)</code> request is processed with a password that is different from those + * used to create connections in the pool associated with <code>user name</code>, an attempt is made to create a new + * connection using the supplied password and if this succeeds, idle connections created using the old password are + * destroyed and new connections are created using the new password. + * </p> * * @since 2.0 */ @@ -54,7 +55,7 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { // Pool properties private int maxTotal = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL; - private transient KeyedObjectPool<UserPassKey,PooledConnectionAndInfo> pool; + private transient KeyedObjectPool<UserPassKey, PooledConnectionAndInfo> pool; private transient KeyedCPDSConnectionFactory factory; /** @@ -75,7 +76,6 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { InstanceKeyDataSourceFactory.removeInstance(getInstanceKey()); } - // ------------------------------------------------------------------- // Properties @@ -91,14 +91,14 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { /** * Sets {@link GenericKeyedObjectPool#getMaxTotal()} for this pool. * - * @param maxTotal {@link GenericKeyedObjectPool#getMaxTotal()} for this pool. + * @param maxTotal + * {@link GenericKeyedObjectPool#getMaxTotal()} for this pool. */ public void setMaxTotal(final int maxTotal) { assertInitializationAllowed(); this.maxTotal = maxTotal; } - // ---------------------------------------------------------------------- // Instrumentation Methods @@ -150,7 +150,7 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { } @Override - protected PooledConnectionManager getConnectionManager(final UserPassKey upkey) { + protected PooledConnectionManager getConnectionManager(final UserPassKey upkey) { return factory; } @@ -218,9 +218,12 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { /** * Supports Serialization interface. * - * @param in a <code>java.io.ObjectInputStream</code> value - * @throws IOException if an error occurs - * @throws ClassNotFoundException if an error occurs + * @param in + * a <code>java.io.ObjectInputStream</code> value + * @throws IOException + * if an error occurs + * @throws ClassNotFoundException + * if an error occurs */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { try { @@ -233,4 +236,3 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { } } } - http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/e7ee9481/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java index 84a87b1..8a75287 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java @@ -22,13 +22,11 @@ import javax.naming.Reference; /** * A JNDI ObjectFactory which creates <code>SharedPoolDataSource</code>s + * * @since 2.0 */ -public class SharedPoolDataSourceFactory - extends InstanceKeyDataSourceFactory -{ - private static final String SHARED_POOL_CLASSNAME = - SharedPoolDataSource.class.getName(); +public class SharedPoolDataSourceFactory extends InstanceKeyDataSourceFactory { + private static final String SHARED_POOL_CLASSNAME = SharedPoolDataSource.class.getName(); @Override protected boolean isCorrectClass(final String className) { @@ -40,10 +38,8 @@ public class SharedPoolDataSourceFactory final SharedPoolDataSource spds = new SharedPoolDataSource(); final RefAddr ra = ref.get("maxTotal"); if (ra != null && ra.getContent() != null) { - spds.setMaxTotal( - Integer.parseInt(ra.getContent().toString())); + spds.setMaxTotal(Integer.parseInt(ra.getContent().toString())); } return spds; } } -