commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1563707 - in /commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2: PoolableConnection.java PoolablePreparedStatement.java PoolingConnection.java PoolingDataSource.java managed/ManagedDataSource.java
Date Sun, 02 Feb 2014 20:31:44 GMT
Author: markt
Date: Sun Feb  2 20:31:43 2014
New Revision: 1563707

URL: http://svn.apache.org/r1563707
Log:
Partial fix for DBCP-404
Make mutable fields private

Modified:
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java?rev=1563707&r1=1563706&r2=1563707&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
Sun Feb  2 20:31:43 2014
@@ -32,7 +32,7 @@ import org.apache.commons.pool2.ObjectPo
  */
 public class PoolableConnection extends DelegatingConnection<Connection> {
     /** The pool to which I should return. */
-    protected ObjectPool<PoolableConnection> _pool = null;
+    private ObjectPool<PoolableConnection> _pool = null;
 
     /**
      *

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java?rev=1563707&r1=1563706&r2=1563707&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
Sun Feb  2 20:31:43 2014
@@ -43,12 +43,12 @@ public class PoolablePreparedStatement<K
     /**
      * The {@link KeyedObjectPool} from which I was obtained.
      */
-    protected KeyedObjectPool<K, PoolablePreparedStatement<K,S>> _pool = null;
+    private final KeyedObjectPool<K, PoolablePreparedStatement<K,S>> _pool;
 
     /**
      * My "key" as used by {@link KeyedObjectPool}.
      */
-    protected K _key = null;
+    private final K _key;
 
     private volatile boolean batchAdded = false;
 

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java?rev=1563707&r1=1563706&r2=1563707&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
Sun Feb  2 20:31:43 2014
@@ -49,7 +49,7 @@ public class PoolingConnection extends D
         implements KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement> {
 
     /** Pool of {@link PreparedStatement}s. and {@link CallableStatement}s */
-    protected KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> _pstmtPool = null;
+    private KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> _pstmtPool = null;
 
     /** Prepared Statement type */
     protected static final byte STATEMENT_PREPAREDSTMT = 0;

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java?rev=1563707&r1=1563706&r2=1563707&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java
Sun Feb  2 20:31:43 2014
@@ -43,23 +43,11 @@ public class PoolingDataSource<C extends
     /** Controls access to the underlying connection */
     private boolean accessToUnderlyingConnectionAllowed = false;
 
-    public PoolingDataSource() {
-        this(null);
-    }
-
     public PoolingDataSource(ObjectPool<C> pool) {
-        _pool = pool;
-    }
-
-    public void setPool(ObjectPool<C> pool)
-            throws IllegalStateException, NullPointerException {
-        if(null != _pool) {
-            throw new IllegalStateException("Pool already set");
-        } else if(null == pool) {
+        if (null == pool) {
             throw new NullPointerException("Pool must not be null.");
-        } else {
-            _pool = pool;
         }
+        _pool = pool;
     }
 
     /**
@@ -173,9 +161,13 @@ public class PoolingDataSource<C extends
     }
 
     /** My log writer. */
-    protected PrintWriter _logWriter = null;
+    private PrintWriter _logWriter = null;
 
-    protected ObjectPool<C> _pool = null;
+    private final ObjectPool<C> _pool;
+
+    protected ObjectPool<C> getPool() {
+        return _pool;
+    }
 
     /**
      * PoolGuardConnectionWrapper is a Connection wrapper that makes sure a

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java?rev=1563707&r1=1563706&r2=1563707&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java
Sun Feb  2 20:31:43 2014
@@ -33,13 +33,6 @@ public class ManagedDataSource<C extends
     private TransactionRegistry transactionRegistry;
 
     /**
-     * Creates an uninitialized datasource.  Before this data source can be used a pool and
-     * transaction registry must be set.
-     */
-    public ManagedDataSource() {
-    }
-
-    /**
      * Creates a ManagedDataSource which obtains connections from the specified pool and
      * manages them using the specified transaction registry.  The TransactionRegistry must
      * be the transaction registry obtained from the XAConnectionFactory used to create
@@ -73,10 +66,10 @@ public class ManagedDataSource<C extends
 
     @Override
     public Connection getConnection() throws SQLException {
-        if (_pool == null) throw new IllegalStateException("Pool has not been set");
+        if (getPool() == null) throw new IllegalStateException("Pool has not been set");
         if (transactionRegistry == null) throw new IllegalStateException("TransactionRegistry
has not been set");
 
-        Connection connection = new ManagedConnection<>(_pool, transactionRegistry,
isAccessToUnderlyingConnectionAllowed());
+        Connection connection = new ManagedConnection<>(getPool(), transactionRegistry,
isAccessToUnderlyingConnectionAllowed());
         return connection;
     }
 }



Mime
View raw message