commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp DelegatingCallableStatement.java DelegatingPreparedStatement.java DelegatingStatement.java
Date Fri, 26 Dec 2003 15:16:28 GMT
dirkv       2003/12/26 07:16:28

  Modified:    dbcp/src/java/org/apache/commons/dbcp
                        DelegatingCallableStatement.java
                        DelegatingPreparedStatement.java
                        DelegatingStatement.java
  Log:
  DelegatingPreparedStatement extends DelegatingStatement
  DelegatingCallableStatement extends DelegatingPreparedStatement
  => refactoring to remove duplicate code & other general cleanup
  => getDelegate methods changed signature (return always "Statement")
  
  Revision  Changes    Path
  1.13      +11 -52    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java
  
  Index: DelegatingCallableStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DelegatingCallableStatement.java	9 Oct 2003 21:04:44 -0000	1.12
  +++ DelegatingCallableStatement.java	26 Dec 2003 15:16:28 -0000	1.13
  @@ -78,7 +78,6 @@
   import java.io.Reader;
   import java.sql.ResultSetMetaData;
   import java.sql.SQLWarning;
  -import java.sql.Connection;
   import java.sql.SQLException;
   
   import java.util.List;
  @@ -97,15 +96,14 @@
    *
    * @author Glenn L. Nielsen
    * @author James House (<a href="mailto:james@interobjective.com">james@interobjective.com</a>)
  + * @author Dirk Verbeeck
    * @version $Revision$ $Date$
    */
  -public class DelegatingCallableStatement extends AbandonedTrace
  +public class DelegatingCallableStatement extends DelegatingPreparedStatement
           implements CallableStatement {
   
       /** My delegate. */
       protected CallableStatement _stmt = null;
  -    /** The connection that created me. **/
  -    protected DelegatingConnection _conn = null;
   
       /**
        * Create a wrapper for the Statement which traces this
  @@ -116,18 +114,12 @@
        */
       public DelegatingCallableStatement(DelegatingConnection c,
                                          CallableStatement s) {
  -        super(c);
  -        _conn = c;
  +        super(c, s);
           _stmt = s;
       }
   
  -    /** Return the {@link CallableStatement} I'm wrapping. */
  -    public CallableStatement getDelegate() {
  -        return _stmt;
  -    }
  -
       public boolean equals(Object obj) {
  -        CallableStatement delegate = getInnermostDelegate();
  +        CallableStatement delegate = (CallableStatement) getInnermostDelegate();
           if (delegate == null) {
               return false;
           }
  @@ -140,41 +132,13 @@
           }
       }
   
  -    public int hashCode() {
  -        Object obj = getInnermostDelegate();
  -        if (obj == null) {
  -            return 0;
  -        }
  -        return obj.hashCode();
  +    /** Sets my delegate. */
  +    public void setDelegate(CallableStatement s) {
  +        super.setDelegate(s);
  +        _stmt = s;
       }
   
       /**
  -     * If my underlying {@link CallableStatement} is not a
  -     * <tt>DelegatingCallableStatement</tt>, returns it,
  -     * otherwise recursively invokes this method on
  -     * my delegate.
  -     * <p>
  -     * Hence this method will return the first
  -     * delegate that is not a <tt>DelegatingCallableStatement</tt>,
  -     * or <tt>null</tt> when no non-<tt>DelegatingCallableStatement</tt>
  -     * delegate can be found by transversing this chain.
  -     * <p>
  -     * This method is useful when you may have nested
  -     * <tt>DelegatingCallableStatement</tt>s, and you want to make
  -     * sure to obtain a "genuine" {@link CallableStatement}.
  -     */
  -    public CallableStatement getInnermostDelegate() {
  -        CallableStatement s = _stmt;
  -        while(s != null && s instanceof DelegatingPreparedStatement) {
  -            s = ((DelegatingCallableStatement)s).getDelegate();
  -            if(this == s) {
  -                return null;
  -            }
  -        }
  -        return s;
  -    }
  -    
  -    /**
        * Close this DelegatingCallableStatement, and close
        * any ResultSets that were not explicitly closed.
        */
  @@ -199,10 +163,6 @@
           _stmt.close();
       }
   
  -    public Connection getConnection() throws SQLException {
  -      return _conn;
  -    }
  -
       public ResultSet executeQuery() throws SQLException {
           return DelegatingResultSet.wrapResultSet(this,_stmt.executeQuery());
       }
  @@ -292,7 +252,6 @@
       public void clearWarnings() throws SQLException { _stmt.clearWarnings();  }
       public void setCursorName(String name) throws SQLException { _stmt.setCursorName( name);
 }
       public boolean execute(String sql) throws SQLException { return _stmt.execute( sql);
 }
  -
   
       public int getUpdateCount() throws SQLException { return _stmt.getUpdateCount();  }
       public boolean getMoreResults() throws SQLException { return _stmt.getMoreResults();
 }
  
  
  
  1.16      +9 -69     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java
  
  Index: DelegatingPreparedStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DelegatingPreparedStatement.java	9 Oct 2003 21:04:44 -0000	1.15
  +++ DelegatingPreparedStatement.java	26 Dec 2003 15:16:28 -0000	1.16
  @@ -65,7 +65,6 @@
   import java.sql.Array;
   import java.sql.Blob;
   import java.sql.Clob;
  -import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.Ref;
   import java.sql.ResultSet;
  @@ -91,14 +90,14 @@
    * @author Rodney Waldhoff
    * @author Glenn L. Nielsen
    * @author James House (<a href="mailto:james@interobjective.com">james@interobjective.com</a>)
  + * @author Dirk Verbeeck
    * @version $Revision$ $Date$
    */
  -public class DelegatingPreparedStatement extends AbandonedTrace
  +public class DelegatingPreparedStatement extends DelegatingStatement
           implements PreparedStatement {
  +
       /** My delegate. */
       protected PreparedStatement _stmt = null;
  -    /** The connection that created me. **/
  -    protected DelegatingConnection _conn = null;
   
       /**
        * Create a wrapper for the Statement which traces this
  @@ -110,21 +109,12 @@
        */
       public DelegatingPreparedStatement(DelegatingConnection c,
                                          PreparedStatement s) {
  -        super(c);
  +        super(c, s);
           _stmt = s;
  -        _conn = c;
  -    }
  -
  -    /**
  -     * Returns my underlying {@link PreparedStatement}.
  -     * @return my underlying {@link PreparedStatement}.
  -     */
  -    public PreparedStatement getDelegate() {
  -        return _stmt;
       }
   
       public boolean equals(Object obj) {
  -        PreparedStatement delegate = getInnermostDelegate();
  +        PreparedStatement delegate = (PreparedStatement) getInnermostDelegate();
           if (delegate == null) {
               return false;
           }
  @@ -137,42 +127,9 @@
           }
       }
   
  -    public int hashCode() {
  -        Object obj = getInnermostDelegate();
  -        if (obj == null) {
  -            return 0;
  -        }
  -        return obj.hashCode();
  -    }
  -
  -    /**
  -     * If my underlying {@link PreparedStatement} is not a
  -     * <tt>DelegatingPreparedStatement</tt>, returns it,
  -     * otherwise recursively invokes this method on
  -     * my delegate.
  -     * <p>
  -     * Hence this method will return the first
  -     * delegate that is not a <tt>DelegatingPreparedStatement</tt>,
  -     * or <tt>null</tt> when no non-<tt>DelegatingPreparedStatement</tt>
  -     * delegate can be found by transversing this chain.
  -     * <p>
  -     * This method is useful when you may have nested
  -     * <tt>DelegatingPreparedStatement</tt>s, and you want to make
  -     * sure to obtain a "genuine" {@link PreparedStatement}.
  -     */
  -    public PreparedStatement getInnermostDelegate() {
  -        PreparedStatement s = _stmt;
  -        while(s != null && s instanceof DelegatingPreparedStatement) {
  -            s = ((DelegatingPreparedStatement)s).getDelegate();
  -            if(this == s) {
  -                return null;
  -            }
  -        }
  -        return s;
  -    }
  -
       /** Sets my delegate. */
       public void setDelegate(PreparedStatement s) {
  +        super.setDelegate(s);
           _stmt = s;
       }
   
  @@ -185,11 +142,6 @@
           passivate();
       }
   
  -    public Connection getConnection() throws SQLException {
  -        checkOpen();
  -        return _conn; // return the delegating connection that created this
  -    }
  -
       public ResultSet executeQuery(String sql) throws SQLException {
           checkOpen();
           return DelegatingResultSet.wrapResultSet(this,_stmt.executeQuery(sql));
  @@ -266,12 +218,6 @@
       public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal) throws
SQLException { checkOpen(); _stmt.setTimestamp(parameterIndex,x,cal);}
       public void setNull (int paramIndex, int sqlType, String typeName) throws SQLException
{ checkOpen(); _stmt.setNull(paramIndex,sqlType,typeName);}
   
  -    protected void checkOpen() throws SQLException {
  -        if (_closed) {
  -            throw new SQLException("PreparedStatement is closed.");
  -        }
  -    }
  -
       protected void activate() {
           _closed = false;
           if(_stmt instanceof DelegatingPreparedStatement) {
  @@ -303,12 +249,6 @@
               ((DelegatingPreparedStatement)_stmt).passivate();
           }
       }
  -
  -    protected boolean isClosed() {
  -        return _closed;
  -    }
  -
  -    protected boolean _closed = false;
   
       // ------------------- JDBC 3.0 -----------------------------------------
       // Will be commented by the build process on a JDBC 2.0 system
  
  
  
  1.13      +10 -5     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingStatement.java
  
  Index: DelegatingStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingStatement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DelegatingStatement.java	9 Oct 2003 21:04:44 -0000	1.12
  +++ DelegatingStatement.java	26 Dec 2003 15:16:28 -0000	1.13
  @@ -84,6 +84,7 @@
    * @author Rodney Waldhoff (<a href="mailto:rwaldhof@us.britannica.com">rwaldhof@us.britannica.com</a>)
    * @author Glenn L. Nielsen
    * @author James House (<a href="mailto:james@interobjective.com">james@interobjective.com</a>)
  + * @author Dirk Verbeeck
    * @version $Revision$ $Date$
    */
   public class DelegatingStatement extends AbandonedTrace implements Statement {
  @@ -219,8 +220,8 @@
       public int[] executeBatch() throws SQLException { checkOpen(); return _stmt.executeBatch();}
   
       protected void checkOpen() throws SQLException {
  -        if(_closed) {
  -            throw new SQLException("Connection is closed.");
  +        if(isClosed()) {
  +            throw new SQLException(this.getClass().getName() + " is closed.");
           }
       }
   
  @@ -254,6 +255,10 @@
           }
       }
       
  +    protected boolean isClosed() {
  +        return _closed;
  +    }
  +
       protected boolean _closed = false;
   
       // ------------------- JDBC 3.0 -----------------------------------------
  
  
  

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


Mime
View raw message