You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/06/10 16:18:39 UTC

commons-dbcp git commit: Use line length 120 and format consistently.

Repository: commons-dbcp
Updated Branches:
  refs/heads/master 24c79b896 -> 10636cf7f


Use line length 120 and format consistently.

Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/10636cf7
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/10636cf7
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/10636cf7

Branch: refs/heads/master
Commit: 10636cf7f281864685b64efb6b013f57331c4615
Parents: 24c79b8
Author: Gary Gregory <ga...@gmail.com>
Authored: Sun Jun 10 10:18:35 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Sun Jun 10 10:18:35 2018 -0600

----------------------------------------------------------------------
 .../datasources/KeyedCPDSConnectionFactory.java | 124 ++++++++-----------
 1 file changed, 55 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/10636cf7/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 65b2ba5..6ab3c55 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java
@@ -38,18 +38,16 @@ import org.apache.commons.pool2.PooledObject;
 import org.apache.commons.pool2.impl.DefaultPooledObject;
 
 /**
- * A {@link KeyedPooledObjectFactory} that creates
- * {@link org.apache.commons.dbcp2.PoolableConnection PoolableConnection}s.
+ * A {@link KeyedPooledObjectFactory} that creates {@link org.apache.commons.dbcp2.PoolableConnection
+ * PoolableConnection}s.
  *
  * @author John D. McNally
  * @since 2.0
  */
-class KeyedCPDSConnectionFactory
-    implements KeyedPooledObjectFactory<UserPassKey,PooledConnectionAndInfo>,
-    ConnectionEventListener, PooledConnectionManager {
+class KeyedCPDSConnectionFactory implements KeyedPooledObjectFactory<UserPassKey, PooledConnectionAndInfo>,
+        ConnectionEventListener, PooledConnectionManager {
 
-    private static final String NO_KEY_MESSAGE
-            = "close() was called on a Connection, but "
+    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;
@@ -60,31 +58,29 @@ class KeyedCPDSConnectionFactory
     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<>();
 
     /**
      * Create a new {@code KeyedPoolableConnectionFactory}.
-     * @param cpds the ConnectionPoolDataSource from which to obtain
-     * PooledConnections
-     * @param validationQuery a query to use to {@link #validateObject validate}
-     * {@link Connection}s.  Should return at least one row. May be
-     * {@code null} in which case3 {@link Connection#isValid(int)} will be used
-     * to validate connections.
-     * @param validationQueryTimeout The time, in seconds, to allow for the
-     *        validation query to complete
-     * @param rollbackAfterValidation whether a rollback should be issued after
-     * {@link #validateObject validating} {@link Connection}s.
+     * 
+     * @param cpds
+     *            the ConnectionPoolDataSource from which to obtain PooledConnections
+     * @param validationQuery
+     *            a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one
+     *            row. May be {@code null} in which case3 {@link Connection#isValid(int)} will be used to validate
+     *            connections.
+     * @param validationQueryTimeout
+     *            The time, in seconds, to allow for the validation query to complete
+     * @param rollbackAfterValidation
+     *            whether a rollback should be issued after {@link #validateObject validating} {@link Connection}s.
      */
     public KeyedCPDSConnectionFactory(final ConnectionPoolDataSource cpds,
                                       final String validationQuery,
@@ -105,20 +101,21 @@ class KeyedCPDSConnectionFactory
      *
      * @return KeyedObjectPool managing pooled connections
      */
-    public KeyedObjectPool<UserPassKey,PooledConnectionAndInfo> getPool() {
+    public KeyedObjectPool<UserPassKey, PooledConnectionAndInfo> getPool() {
         return _pool;
     }
 
     /**
      * Creates a new {@link PooledConnectionAndInfo} from the given {@link UserPassKey}.
      *
-     * @param upkey {@link UserPassKey} containing user credentials
-     * @throws SQLException if the connection could not be created.
+     * @param upkey
+     *            {@link UserPassKey} containing user credentials
+     * @throws SQLException
+     *             if the connection could not be created.
      * @see org.apache.commons.pool2.KeyedPooledObjectFactory#makeObject(java.lang.Object)
      */
     @Override
-    public synchronized PooledObject<PooledConnectionAndInfo> makeObject(final UserPassKey upkey)
-            throws Exception {
+    public synchronized PooledObject<PooledConnectionAndInfo> makeObject(final UserPassKey upkey) throws Exception {
         PooledConnectionAndInfo pci = null;
 
         PooledConnection pc = null;
@@ -147,8 +144,7 @@ class KeyedCPDSConnectionFactory
      * Closes the PooledConnection and stops listening for events from it.
      */
     @Override
-    public void destroyObject(final UserPassKey key, final PooledObject<PooledConnectionAndInfo> p)
-            throws Exception {
+    public void destroyObject(final UserPassKey key, final PooledObject<PooledConnectionAndInfo> p) throws Exception {
         final PooledConnection pc = p.getObject().getPooledConnection();
         pc.removeConnectionEventListener(this);
         pcMap.remove(pc);
@@ -158,14 +154,14 @@ class KeyedCPDSConnectionFactory
     /**
      * Validates a pooled connection.
      *
-     * @param key ignored
-     * @param p wrapped {@link PooledConnectionAndInfo} containing the
-     *          connection to validate
+     * @param key
+     *            ignored
+     * @param p
+     *            wrapped {@link PooledConnectionAndInfo} containing the connection to validate
      * @return true if validation succeeds
      */
     @Override
-    public boolean validateObject(final UserPassKey key,
-            final PooledObject<PooledConnectionAndInfo> p) {
+    public boolean validateObject(final UserPassKey key, final PooledObject<PooledConnectionAndInfo> p) {
         try {
             validateLifetime(p);
         } catch (final Exception e) {
@@ -209,7 +205,7 @@ class KeyedCPDSConnectionFactory
                 if (_rollbackAfterValidation) {
                     conn.rollback();
                 }
-            } catch(final Exception e) {
+            } catch (final Exception e) {
                 valid = false;
             } finally {
                 Utils.closeQuietly(rset);
@@ -222,14 +218,12 @@ class KeyedCPDSConnectionFactory
     }
 
     @Override
-    public void passivateObject(final UserPassKey key,
-            final PooledObject<PooledConnectionAndInfo> p) throws Exception {
+    public void passivateObject(final UserPassKey key, final PooledObject<PooledConnectionAndInfo> p) throws Exception {
         validateLifetime(p);
     }
 
     @Override
-    public void activateObject(final UserPassKey key,
-            final PooledObject<PooledConnectionAndInfo> p) throws Exception {
+    public void activateObject(final UserPassKey key, final PooledObject<PooledConnectionAndInfo> p) throws Exception {
         validateLifetime(p);
     }
 
@@ -238,14 +232,13 @@ class KeyedCPDSConnectionFactory
     // ***********************************************************************
 
     /**
-     * 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) {
-        final PooledConnection pc = (PooledConnection)event.getSource();
+        final PooledConnection pc = (PooledConnection) event.getSource();
         // if this event occurred because we were validating, or if this
         // connection has been marked for removal, ignore it
         // otherwise return the connection to the pool.
@@ -257,14 +250,12 @@ class KeyedCPDSConnectionFactory
             try {
                 _pool.returnObject(pci.getUserPassKey(), 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 {
                     _pool.invalidateObject(pci.getUserPassKey(), pci);
                 } catch (final Exception e3) {
-                    System.err.println("EXCEPTION WHILE DESTROYING OBJECT " +
-                            pci);
+                    System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
                     e3.printStackTrace();
                 }
             }
@@ -272,16 +263,13 @@ class KeyedCPDSConnectionFactory
     }
 
     /**
-     * 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);
 
@@ -302,11 +290,10 @@ class KeyedCPDSConnectionFactory
     // ***********************************************************************
 
     /**
-     * Invalidates the PooledConnection in the pool.  The KeyedCPDSConnectionFactory
-     * closes the connection and pool counters are updated appropriately.
-     * Also clears any idle instances associated with the username that was used
-     * to create the PooledConnection.  Connections associated with this user
-     * are not affected and they will not be automatically closed on return to the pool.
+     * Invalidates the PooledConnection in the pool. The KeyedCPDSConnectionFactory closes the connection and pool
+     * counters are updated appropriately. Also clears any idle instances associated with the username that was used to
+     * create the PooledConnection. Connections associated with this user are not affected and they will not be
+     * automatically closed on return to the pool.
      */
     @Override
     public void invalidate(final PooledConnection pc) throws SQLException {
@@ -316,7 +303,7 @@ class KeyedCPDSConnectionFactory
         }
         final UserPassKey key = info.getUserPassKey();
         try {
-            _pool.invalidateObject(key, info);  // Destroy and update pool counters
+            _pool.invalidateObject(key, info); // Destroy and update pool counters
             _pool.clear(key); // Remove any idle instances with this key
         } catch (final Exception ex) {
             throw new SQLException("Error invalidating connection", ex);
@@ -332,20 +319,19 @@ class KeyedCPDSConnectionFactory
     }
 
     /**
-     * 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;
     }
 
     /**
-     * This implementation does not fully close the KeyedObjectPool, as
-     * this would affect all users.  Instead, it clears the pool associated
-     * with the given user.  This method is not currently used.
+     * This implementation does not fully close the KeyedObjectPool, as this would affect all users. Instead, it clears
+     * the pool associated with the given user. This method is not currently used.
      */
     @Override
     public void closePool(final String username) throws SQLException {