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 2011/05/11 01:27:13 UTC

svn commit: r1101678 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java

Author: markt
Date: Tue May 10 23:27:13 2011
New Revision: 1101678

URL: http://svn.apache.org/viewvc?rev=1101678&view=rev
Log:
Cache current values of autoCommit and readOnly so DB queries are not required for every call to the getter

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.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=1101678&r1=1101677&r2=1101678&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 May 10 23:27:13 2011
@@ -75,6 +75,10 @@ public class DelegatingConnection extend
 
     protected boolean _closed = false;
     
+    
+    private Boolean _autoCommitCached = null;
+    private Boolean _readOnlyCached = null;
+
     /**
      * Create a wrapper for the Connection which traces this
      * Connection in the AbandonedObjectPool.
@@ -344,9 +348,20 @@ public class DelegatingConnection extend
     { checkOpen(); try { _conn.commit(); } catch (SQLException e) { handleException(e); } }
     
     @Override
-    public boolean getAutoCommit() throws SQLException
-    { checkOpen(); try { return _conn.getAutoCommit(); } catch (SQLException e) { handleException(e); return false; } 
+    public boolean getAutoCommit() throws SQLException {
+        checkOpen();
+        if (_autoCommitCached != null) {
+            return _autoCommitCached.booleanValue();
+        }
+        try {
+            _autoCommitCached = Boolean.valueOf(_conn.getAutoCommit());
+            return _autoCommitCached.booleanValue();
+        } catch (SQLException e) {
+            handleException(e);
+            return false;
+        } 
     }
+
     @Override
     public String getCatalog() throws SQLException
     { checkOpen(); try { return _conn.getCatalog(); } catch (SQLException e) { handleException(e); return null; } }
@@ -375,9 +390,20 @@ public class DelegatingConnection extend
     { checkOpen(); try { return _conn.getWarnings(); } catch (SQLException e) { handleException(e); return null; } }
     
     @Override
-    public boolean isReadOnly() throws SQLException
-    { checkOpen(); try { return _conn.isReadOnly(); } catch (SQLException e) { handleException(e); return false; } }
-    
+    public boolean isReadOnly() throws SQLException {
+        checkOpen();
+        if (_readOnlyCached != null) {
+            return _readOnlyCached.booleanValue();
+        }
+        try {
+            _readOnlyCached = Boolean.valueOf(_conn.isReadOnly());
+            return _readOnlyCached.booleanValue();
+        } catch (SQLException e) {
+            handleException(e);
+            return false;
+        }
+    }
+
     @Override
     public String nativeSQL(String sql) throws SQLException
     { checkOpen(); try { return _conn.nativeSQL(sql); } catch (SQLException e) { handleException(e); return null; } }
@@ -387,16 +413,32 @@ public class DelegatingConnection extend
     { checkOpen(); try {  _conn.rollback(); } catch (SQLException e) { handleException(e); } }
     
     @Override
-    public void setAutoCommit(boolean autoCommit) throws SQLException
-    { checkOpen(); try { _conn.setAutoCommit(autoCommit); } catch (SQLException e) { handleException(e); } }
+    public void setAutoCommit(boolean autoCommit) throws SQLException {
+        checkOpen();
+        try {
+            _conn.setAutoCommit(autoCommit);
+            _autoCommitCached = Boolean.valueOf(autoCommit);
+        } catch (SQLException e) {
+            _autoCommitCached = null;
+            handleException(e);
+        }
+    }
 
     @Override
     public void setCatalog(String catalog) throws SQLException
     { checkOpen(); try { _conn.setCatalog(catalog); } catch (SQLException e) { handleException(e); } }
 
     @Override
-    public void setReadOnly(boolean readOnly) throws SQLException
-    { checkOpen(); try { _conn.setReadOnly(readOnly); } catch (SQLException e) { handleException(e); } }
+    public void setReadOnly(boolean readOnly) throws SQLException {
+        checkOpen();
+        try {
+            _conn.setReadOnly(readOnly);
+            _readOnlyCached = Boolean.valueOf(readOnly);
+        } catch (SQLException e) {
+            _readOnlyCached = null;
+            handleException(e);
+        }
+    }
 
     @Override
     public void setTransactionIsolation(int level) throws SQLException



Re: svn commit: r1101678 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java

Posted by Mark Thomas <ma...@apache.org>.
On 11/05/2011 01:18, Phil Steitz wrote:
> Please raise issues and/or update changes.xml to keep track of these
> changes.

Will do. My focus so far has been on seeing if it is possible to get
DBCP to a point where it is on a par with jdbc-pool performance-wise. I
purposely skipped a lot of house-keeping along the way in case it didn't
work. Now it has (DBCP is a lot closer but still not quite as fast as
jdbc-pool) I'll go back and do the house-keeping.

> I guess in this case, we might want to doc the fact that we are just
> tracking what dbcp thinks the state of the connection is.  If access
> to the underlying connection is allowed and it gets modified, all
> bets are off.

Absolutely. Better still, I think the caching should be configurable
(one attribute controls all state caching). Note that currently setting
state always updates the cache.

> One more little nit - can we agree to stop adding / get rid of the
> _'s in front of variable names?

Happy to. I was just following the existing coding conventions.

Mark

> 
> Phil
> 
> On 5/10/11 4:27 PM, markt@apache.org wrote:
>> Author: markt
>> Date: Tue May 10 23:27:13 2011
>> New Revision: 1101678
>>
>> URL: http://svn.apache.org/viewvc?rev=1101678&view=rev
>> Log:
>> Cache current values of autoCommit and readOnly so DB queries are not required for every call to the getter
>>
>> Modified:
>>     commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.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=1101678&r1=1101677&r2=1101678&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 May 10 23:27:13 2011
>> @@ -75,6 +75,10 @@ public class DelegatingConnection extend
>>  
>>      protected boolean _closed = false;
>>      
>> +    
>> +    private Boolean _autoCommitCached = null;
>> +    private Boolean _readOnlyCached = null;
>> +
>>      /**
>>       * Create a wrapper for the Connection which traces this
>>       * Connection in the AbandonedObjectPool.
>> @@ -344,9 +348,20 @@ public class DelegatingConnection extend
>>      { checkOpen(); try { _conn.commit(); } catch (SQLException e) { handleException(e); } }
>>      
>>      @Override
>> -    public boolean getAutoCommit() throws SQLException
>> -    { checkOpen(); try { return _conn.getAutoCommit(); } catch (SQLException e) { handleException(e); return false; } 
>> +    public boolean getAutoCommit() throws SQLException {
>> +        checkOpen();
>> +        if (_autoCommitCached != null) {
>> +            return _autoCommitCached.booleanValue();
>> +        }
>> +        try {
>> +            _autoCommitCached = Boolean.valueOf(_conn.getAutoCommit());
>> +            return _autoCommitCached.booleanValue();
>> +        } catch (SQLException e) {
>> +            handleException(e);
>> +            return false;
>> +        } 
>>      }
>> +
>>      @Override
>>      public String getCatalog() throws SQLException
>>      { checkOpen(); try { return _conn.getCatalog(); } catch (SQLException e) { handleException(e); return null; } }
>> @@ -375,9 +390,20 @@ public class DelegatingConnection extend
>>      { checkOpen(); try { return _conn.getWarnings(); } catch (SQLException e) { handleException(e); return null; } }
>>      
>>      @Override
>> -    public boolean isReadOnly() throws SQLException
>> -    { checkOpen(); try { return _conn.isReadOnly(); } catch (SQLException e) { handleException(e); return false; } }
>> -    
>> +    public boolean isReadOnly() throws SQLException {
>> +        checkOpen();
>> +        if (_readOnlyCached != null) {
>> +            return _readOnlyCached.booleanValue();
>> +        }
>> +        try {
>> +            _readOnlyCached = Boolean.valueOf(_conn.isReadOnly());
>> +            return _readOnlyCached.booleanValue();
>> +        } catch (SQLException e) {
>> +            handleException(e);
>> +            return false;
>> +        }
>> +    }
>> +
>>      @Override
>>      public String nativeSQL(String sql) throws SQLException
>>      { checkOpen(); try { return _conn.nativeSQL(sql); } catch (SQLException e) { handleException(e); return null; } }
>> @@ -387,16 +413,32 @@ public class DelegatingConnection extend
>>      { checkOpen(); try {  _conn.rollback(); } catch (SQLException e) { handleException(e); } }
>>      
>>      @Override
>> -    public void setAutoCommit(boolean autoCommit) throws SQLException
>> -    { checkOpen(); try { _conn.setAutoCommit(autoCommit); } catch (SQLException e) { handleException(e); } }
>> +    public void setAutoCommit(boolean autoCommit) throws SQLException {
>> +        checkOpen();
>> +        try {
>> +            _conn.setAutoCommit(autoCommit);
>> +            _autoCommitCached = Boolean.valueOf(autoCommit);
>> +        } catch (SQLException e) {
>> +            _autoCommitCached = null;
>> +            handleException(e);
>> +        }
>> +    }
>>  
>>      @Override
>>      public void setCatalog(String catalog) throws SQLException
>>      { checkOpen(); try { _conn.setCatalog(catalog); } catch (SQLException e) { handleException(e); } }
>>  
>>      @Override
>> -    public void setReadOnly(boolean readOnly) throws SQLException
>> -    { checkOpen(); try { _conn.setReadOnly(readOnly); } catch (SQLException e) { handleException(e); } }
>> +    public void setReadOnly(boolean readOnly) throws SQLException {
>> +        checkOpen();
>> +        try {
>> +            _conn.setReadOnly(readOnly);
>> +            _readOnlyCached = Boolean.valueOf(readOnly);
>> +        } catch (SQLException e) {
>> +            _readOnlyCached = null;
>> +            handleException(e);
>> +        }
>> +    }
>>  
>>      @Override
>>      public void setTransactionIsolation(int level) throws SQLException
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1101678 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java

Posted by Simone Tripodi <si...@apache.org>.
+1!!!
that's what I would have done at the first attempt of pool2 :)

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, May 11, 2011 at 4:55 AM, Gary Gregory <ga...@gmail.com> wrote:
> On May 10, 2011, at 20:24, Phil Steitz <ph...@gmail.com> wrote:
>
>> Please raise issues and/or update changes.xml to keep track of these
>> changes.
>>
>> I guess in this case, we might want to doc the fact that we are just
>> tracking what dbcp thinks the state of the connection is.  If access
>> to the underlying connection is allowed and it gets modified, all
>> bets are off.
>>
>> One more little nit - can we agree to stop adding / get rid of the
>> _'s in front of variable names?
>
> +1
> Gary
>
>>
>> Phil
>>
>> On 5/10/11 4:27 PM, markt@apache.org wrote:
>>> Author: markt
>>> Date: Tue May 10 23:27:13 2011
>>> New Revision: 1101678
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1101678&view=rev
>>> Log:
>>> Cache current values of autoCommit and readOnly so DB queries are not required for every call to the getter
>>>
>>> Modified:
>>>    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.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=1101678&r1=1101677&r2=1101678&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 May 10 23:27:13 2011
>>> @@ -75,6 +75,10 @@ public class DelegatingConnection extend
>>>
>>>     protected boolean _closed = false;
>>>
>>> +
>>> +    private Boolean _autoCommitCached = null;
>>> +    private Boolean _readOnlyCached = null;
>>> +
>>>     /**
>>>      * Create a wrapper for the Connection which traces this
>>>      * Connection in the AbandonedObjectPool.
>>> @@ -344,9 +348,20 @@ public class DelegatingConnection extend
>>>     { checkOpen(); try { _conn.commit(); } catch (SQLException e) { handleException(e); } }
>>>
>>>     @Override
>>> -    public boolean getAutoCommit() throws SQLException
>>> -    { checkOpen(); try { return _conn.getAutoCommit(); } catch (SQLException e) { handleException(e); return false; }
>>> +    public boolean getAutoCommit() throws SQLException {
>>> +        checkOpen();
>>> +        if (_autoCommitCached != null) {
>>> +            return _autoCommitCached.booleanValue();
>>> +        }
>>> +        try {
>>> +            _autoCommitCached = Boolean.valueOf(_conn.getAutoCommit());
>>> +            return _autoCommitCached.booleanValue();
>>> +        } catch (SQLException e) {
>>> +            handleException(e);
>>> +            return false;
>>> +        }
>>>     }
>>> +
>>>     @Override
>>>     public String getCatalog() throws SQLException
>>>     { checkOpen(); try { return _conn.getCatalog(); } catch (SQLException e) { handleException(e); return null; } }
>>> @@ -375,9 +390,20 @@ public class DelegatingConnection extend
>>>     { checkOpen(); try { return _conn.getWarnings(); } catch (SQLException e) { handleException(e); return null; } }
>>>
>>>     @Override
>>> -    public boolean isReadOnly() throws SQLException
>>> -    { checkOpen(); try { return _conn.isReadOnly(); } catch (SQLException e) { handleException(e); return false; } }
>>> -
>>> +    public boolean isReadOnly() throws SQLException {
>>> +        checkOpen();
>>> +        if (_readOnlyCached != null) {
>>> +            return _readOnlyCached.booleanValue();
>>> +        }
>>> +        try {
>>> +            _readOnlyCached = Boolean.valueOf(_conn.isReadOnly());
>>> +            return _readOnlyCached.booleanValue();
>>> +        } catch (SQLException e) {
>>> +            handleException(e);
>>> +            return false;
>>> +        }
>>> +    }
>>> +
>>>     @Override
>>>     public String nativeSQL(String sql) throws SQLException
>>>     { checkOpen(); try { return _conn.nativeSQL(sql); } catch (SQLException e) { handleException(e); return null; } }
>>> @@ -387,16 +413,32 @@ public class DelegatingConnection extend
>>>     { checkOpen(); try {  _conn.rollback(); } catch (SQLException e) { handleException(e); } }
>>>
>>>     @Override
>>> -    public void setAutoCommit(boolean autoCommit) throws SQLException
>>> -    { checkOpen(); try { _conn.setAutoCommit(autoCommit); } catch (SQLException e) { handleException(e); } }
>>> +    public void setAutoCommit(boolean autoCommit) throws SQLException {
>>> +        checkOpen();
>>> +        try {
>>> +            _conn.setAutoCommit(autoCommit);
>>> +            _autoCommitCached = Boolean.valueOf(autoCommit);
>>> +        } catch (SQLException e) {
>>> +            _autoCommitCached = null;
>>> +            handleException(e);
>>> +        }
>>> +    }
>>>
>>>     @Override
>>>     public void setCatalog(String catalog) throws SQLException
>>>     { checkOpen(); try { _conn.setCatalog(catalog); } catch (SQLException e) { handleException(e); } }
>>>
>>>     @Override
>>> -    public void setReadOnly(boolean readOnly) throws SQLException
>>> -    { checkOpen(); try { _conn.setReadOnly(readOnly); } catch (SQLException e) { handleException(e); } }
>>> +    public void setReadOnly(boolean readOnly) throws SQLException {
>>> +        checkOpen();
>>> +        try {
>>> +            _conn.setReadOnly(readOnly);
>>> +            _readOnlyCached = Boolean.valueOf(readOnly);
>>> +        } catch (SQLException e) {
>>> +            _readOnlyCached = null;
>>> +            handleException(e);
>>> +        }
>>> +    }
>>>
>>>     @Override
>>>     public void setTransactionIsolation(int level) throws SQLException
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1101678 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java

Posted by Gary Gregory <ga...@gmail.com>.
On May 10, 2011, at 20:24, Phil Steitz <ph...@gmail.com> wrote:

> Please raise issues and/or update changes.xml to keep track of these
> changes.
>
> I guess in this case, we might want to doc the fact that we are just
> tracking what dbcp thinks the state of the connection is.  If access
> to the underlying connection is allowed and it gets modified, all
> bets are off.
>
> One more little nit - can we agree to stop adding / get rid of the
> _'s in front of variable names?

+1
Gary

>
> Phil
>
> On 5/10/11 4:27 PM, markt@apache.org wrote:
>> Author: markt
>> Date: Tue May 10 23:27:13 2011
>> New Revision: 1101678
>>
>> URL: http://svn.apache.org/viewvc?rev=1101678&view=rev
>> Log:
>> Cache current values of autoCommit and readOnly so DB queries are not required for every call to the getter
>>
>> Modified:
>>    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.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=1101678&r1=1101677&r2=1101678&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 May 10 23:27:13 2011
>> @@ -75,6 +75,10 @@ public class DelegatingConnection extend
>>
>>     protected boolean _closed = false;
>>
>> +
>> +    private Boolean _autoCommitCached = null;
>> +    private Boolean _readOnlyCached = null;
>> +
>>     /**
>>      * Create a wrapper for the Connection which traces this
>>      * Connection in the AbandonedObjectPool.
>> @@ -344,9 +348,20 @@ public class DelegatingConnection extend
>>     { checkOpen(); try { _conn.commit(); } catch (SQLException e) { handleException(e); } }
>>
>>     @Override
>> -    public boolean getAutoCommit() throws SQLException
>> -    { checkOpen(); try { return _conn.getAutoCommit(); } catch (SQLException e) { handleException(e); return false; }
>> +    public boolean getAutoCommit() throws SQLException {
>> +        checkOpen();
>> +        if (_autoCommitCached != null) {
>> +            return _autoCommitCached.booleanValue();
>> +        }
>> +        try {
>> +            _autoCommitCached = Boolean.valueOf(_conn.getAutoCommit());
>> +            return _autoCommitCached.booleanValue();
>> +        } catch (SQLException e) {
>> +            handleException(e);
>> +            return false;
>> +        }
>>     }
>> +
>>     @Override
>>     public String getCatalog() throws SQLException
>>     { checkOpen(); try { return _conn.getCatalog(); } catch (SQLException e) { handleException(e); return null; } }
>> @@ -375,9 +390,20 @@ public class DelegatingConnection extend
>>     { checkOpen(); try { return _conn.getWarnings(); } catch (SQLException e) { handleException(e); return null; } }
>>
>>     @Override
>> -    public boolean isReadOnly() throws SQLException
>> -    { checkOpen(); try { return _conn.isReadOnly(); } catch (SQLException e) { handleException(e); return false; } }
>> -
>> +    public boolean isReadOnly() throws SQLException {
>> +        checkOpen();
>> +        if (_readOnlyCached != null) {
>> +            return _readOnlyCached.booleanValue();
>> +        }
>> +        try {
>> +            _readOnlyCached = Boolean.valueOf(_conn.isReadOnly());
>> +            return _readOnlyCached.booleanValue();
>> +        } catch (SQLException e) {
>> +            handleException(e);
>> +            return false;
>> +        }
>> +    }
>> +
>>     @Override
>>     public String nativeSQL(String sql) throws SQLException
>>     { checkOpen(); try { return _conn.nativeSQL(sql); } catch (SQLException e) { handleException(e); return null; } }
>> @@ -387,16 +413,32 @@ public class DelegatingConnection extend
>>     { checkOpen(); try {  _conn.rollback(); } catch (SQLException e) { handleException(e); } }
>>
>>     @Override
>> -    public void setAutoCommit(boolean autoCommit) throws SQLException
>> -    { checkOpen(); try { _conn.setAutoCommit(autoCommit); } catch (SQLException e) { handleException(e); } }
>> +    public void setAutoCommit(boolean autoCommit) throws SQLException {
>> +        checkOpen();
>> +        try {
>> +            _conn.setAutoCommit(autoCommit);
>> +            _autoCommitCached = Boolean.valueOf(autoCommit);
>> +        } catch (SQLException e) {
>> +            _autoCommitCached = null;
>> +            handleException(e);
>> +        }
>> +    }
>>
>>     @Override
>>     public void setCatalog(String catalog) throws SQLException
>>     { checkOpen(); try { _conn.setCatalog(catalog); } catch (SQLException e) { handleException(e); } }
>>
>>     @Override
>> -    public void setReadOnly(boolean readOnly) throws SQLException
>> -    { checkOpen(); try { _conn.setReadOnly(readOnly); } catch (SQLException e) { handleException(e); } }
>> +    public void setReadOnly(boolean readOnly) throws SQLException {
>> +        checkOpen();
>> +        try {
>> +            _conn.setReadOnly(readOnly);
>> +            _readOnlyCached = Boolean.valueOf(readOnly);
>> +        } catch (SQLException e) {
>> +            _readOnlyCached = null;
>> +            handleException(e);
>> +        }
>> +    }
>>
>>     @Override
>>     public void setTransactionIsolation(int level) throws SQLException
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1101678 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.java

Posted by Phil Steitz <ph...@gmail.com>.
Please raise issues and/or update changes.xml to keep track of these
changes.

I guess in this case, we might want to doc the fact that we are just
tracking what dbcp thinks the state of the connection is.  If access
to the underlying connection is allowed and it gets modified, all
bets are off.

One more little nit - can we agree to stop adding / get rid of the
_'s in front of variable names?

Phil

On 5/10/11 4:27 PM, markt@apache.org wrote:
> Author: markt
> Date: Tue May 10 23:27:13 2011
> New Revision: 1101678
>
> URL: http://svn.apache.org/viewvc?rev=1101678&view=rev
> Log:
> Cache current values of autoCommit and readOnly so DB queries are not required for every call to the getter
>
> Modified:
>     commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/DelegatingConnection.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=1101678&r1=1101677&r2=1101678&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 May 10 23:27:13 2011
> @@ -75,6 +75,10 @@ public class DelegatingConnection extend
>  
>      protected boolean _closed = false;
>      
> +    
> +    private Boolean _autoCommitCached = null;
> +    private Boolean _readOnlyCached = null;
> +
>      /**
>       * Create a wrapper for the Connection which traces this
>       * Connection in the AbandonedObjectPool.
> @@ -344,9 +348,20 @@ public class DelegatingConnection extend
>      { checkOpen(); try { _conn.commit(); } catch (SQLException e) { handleException(e); } }
>      
>      @Override
> -    public boolean getAutoCommit() throws SQLException
> -    { checkOpen(); try { return _conn.getAutoCommit(); } catch (SQLException e) { handleException(e); return false; } 
> +    public boolean getAutoCommit() throws SQLException {
> +        checkOpen();
> +        if (_autoCommitCached != null) {
> +            return _autoCommitCached.booleanValue();
> +        }
> +        try {
> +            _autoCommitCached = Boolean.valueOf(_conn.getAutoCommit());
> +            return _autoCommitCached.booleanValue();
> +        } catch (SQLException e) {
> +            handleException(e);
> +            return false;
> +        } 
>      }
> +
>      @Override
>      public String getCatalog() throws SQLException
>      { checkOpen(); try { return _conn.getCatalog(); } catch (SQLException e) { handleException(e); return null; } }
> @@ -375,9 +390,20 @@ public class DelegatingConnection extend
>      { checkOpen(); try { return _conn.getWarnings(); } catch (SQLException e) { handleException(e); return null; } }
>      
>      @Override
> -    public boolean isReadOnly() throws SQLException
> -    { checkOpen(); try { return _conn.isReadOnly(); } catch (SQLException e) { handleException(e); return false; } }
> -    
> +    public boolean isReadOnly() throws SQLException {
> +        checkOpen();
> +        if (_readOnlyCached != null) {
> +            return _readOnlyCached.booleanValue();
> +        }
> +        try {
> +            _readOnlyCached = Boolean.valueOf(_conn.isReadOnly());
> +            return _readOnlyCached.booleanValue();
> +        } catch (SQLException e) {
> +            handleException(e);
> +            return false;
> +        }
> +    }
> +
>      @Override
>      public String nativeSQL(String sql) throws SQLException
>      { checkOpen(); try { return _conn.nativeSQL(sql); } catch (SQLException e) { handleException(e); return null; } }
> @@ -387,16 +413,32 @@ public class DelegatingConnection extend
>      { checkOpen(); try {  _conn.rollback(); } catch (SQLException e) { handleException(e); } }
>      
>      @Override
> -    public void setAutoCommit(boolean autoCommit) throws SQLException
> -    { checkOpen(); try { _conn.setAutoCommit(autoCommit); } catch (SQLException e) { handleException(e); } }
> +    public void setAutoCommit(boolean autoCommit) throws SQLException {
> +        checkOpen();
> +        try {
> +            _conn.setAutoCommit(autoCommit);
> +            _autoCommitCached = Boolean.valueOf(autoCommit);
> +        } catch (SQLException e) {
> +            _autoCommitCached = null;
> +            handleException(e);
> +        }
> +    }
>  
>      @Override
>      public void setCatalog(String catalog) throws SQLException
>      { checkOpen(); try { _conn.setCatalog(catalog); } catch (SQLException e) { handleException(e); } }
>  
>      @Override
> -    public void setReadOnly(boolean readOnly) throws SQLException
> -    { checkOpen(); try { _conn.setReadOnly(readOnly); } catch (SQLException e) { handleException(e); } }
> +    public void setReadOnly(boolean readOnly) throws SQLException {
> +        checkOpen();
> +        try {
> +            _conn.setReadOnly(readOnly);
> +            _readOnlyCached = Boolean.valueOf(readOnly);
> +        } catch (SQLException e) {
> +            _readOnlyCached = null;
> +            handleException(e);
> +        }
> +    }
>  
>      @Override
>      public void setTransactionIsolation(int level) throws SQLException
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org