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/12/03 23:25:58 UTC
svn commit: r1547615 - in
/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2:
DelegatingConnection.java managed/ManagedConnection.java
Author: markt
Date: Tue Dec 3 22:25:58 2013
New Revision: 1547615
URL: http://svn.apache.org/r1547615
Log:
Fix the generics warnings in ManagedConnection
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java?rev=1547615&r1=1547614&r2=1547615&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java Tue Dec 3 22:25:58 2013
@@ -142,7 +142,7 @@ public class DelegatingConnection<C exte
return getDelegateInternal();
}
- protected final Connection getDelegateInternal() {
+ protected final C getDelegateInternal() {
return _conn;
}
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/managed/ManagedConnection.java?rev=1547615&r1=1547614&r2=1547615&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/managed/ManagedConnection.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/managed/ManagedConnection.java Tue Dec 3 22:25:58 2013
@@ -40,14 +40,14 @@ import java.sql.SQLException;
* @author Dain Sundstrom
* @version $Revision$
*/
-public class ManagedConnection<C extends Connection> extends DelegatingConnection {
- private final ObjectPool<Connection> pool;
+public class ManagedConnection<C extends Connection> extends DelegatingConnection<C> {
+ private final ObjectPool<C> pool;
private final TransactionRegistry transactionRegistry;
private final boolean accessToUnderlyingConnectionAllowed;
private TransactionContext transactionContext;
private boolean isSharedConnection;
- public ManagedConnection(ObjectPool<Connection> pool,
+ public ManagedConnection(ObjectPool<C> pool,
TransactionRegistry transactionRegistry,
boolean accessToUnderlyingConnectionAllowed) throws SQLException {
super(null);
@@ -88,7 +88,7 @@ public class ManagedConnection<C extends
// in the transaction, replace our delegate with the enrolled connection
// return current connection to the pool
- Connection connection = getDelegateInternal();
+ C connection = getDelegateInternal();
setDelegate(null);
if (connection != null) {
try {
@@ -106,8 +106,12 @@ public class ManagedConnection<C extends
// add a listener to the transaction context
transactionContext.addTransactionContextListener(new CompletionListener());
- // set our delegate to the shared connection
- setDelegate(transactionContext.getSharedConnection());
+ // Set our delegate to the shared connection. Note that this will
+ // always be of type C since it has been shared by another
+ // connection from the same pool.
+ @SuppressWarnings("unchecked")
+ C shared = (C) transactionContext.getSharedConnection();
+ setDelegate(shared);
// remember that we are using a shared connection so it can be cleared after the
// transaction completes
@@ -117,7 +121,7 @@ public class ManagedConnection<C extends
if (getDelegateInternal() == null) {
try {
// borrow a new connection from the pool
- Connection connection = pool.borrowObject();
+ C connection = pool.borrowObject();
setDelegate(connection);
} catch (Exception e) {
throw (SQLException) new SQLException("Unable to acquire a new connection from the pool").initCause(e);