Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.commons.dbcp
Class DelegatingStatement  view DelegatingStatement download DelegatingStatement.java

java.lang.Object
  extended byorg.apache.commons.dbcp.AbandonedTrace
      extended byorg.apache.commons.dbcp.DelegatingStatement
All Implemented Interfaces:
java.sql.Statement
Direct Known Subclasses:
DelegatingPreparedStatement

public class DelegatingStatement
extends AbandonedTrace
implements java.sql.Statement

A base delegating implementation of java.sql.Statement.

All of the methods from the java.sql.Statement interface simply check to see that the java.sql.Statement is active, and call the corresponding method on the "delegate" provided in my constructor.

Extends AbandonedTrace to implement Statement tracking and logging of code which created the Statement. Tracking the Statement ensures that the Connection which created it can close any open Statement's on Connection close.

Version:
$Revision: 1.17 $ $Date: 2004/03/06 13:35:31 $

Field Summary
protected  boolean _closed
           
protected  DelegatingConnection _conn
          The connection that created me.
protected  java.sql.Statement _stmt
          My delegate.
 
Fields inherited from class org.apache.commons.dbcp.AbandonedTrace
 
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
 
Constructor Summary
DelegatingStatement(DelegatingConnection c, java.sql.Statement s)
          Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code which created it.
 
Method Summary
protected  void activate()
           
 void addBatch(java.lang.String sql)
          This method adds a SQL statement to a SQL batch.
 void cancel()
          This method cancels an outstanding statement, if the database supports that operation.
protected  void checkOpen()
           
 void clearBatch()
          This method clears out any SQL statements that have been populated in the current batch.
 void clearWarnings()
          This method clears any SQL warnings that have been attached to this statement.
 void close()
          Close this DelegatingStatement, and close any ResultSets that were not explicitly closed.
 boolean equals(java.lang.Object obj)
          Determine whether this Object is semantically equal to another Object.
 boolean execute(java.lang.String sql)
          This method executes an arbitrary SQL statement of any time.
 boolean execute(java.lang.String sql, int autoGeneratedKeys)
           
 boolean execute(java.lang.String sql, int[] columnIndexes)
           
 boolean execute(java.lang.String sql, java.lang.String[] columnNames)
           
 int[] executeBatch()
          This method executes the SQL batch and returns an array of update counts - one for each SQL statement in the batch - ordered in the same order the statements were added to the batch.
 java.sql.ResultSet executeQuery(java.lang.String sql)
          This method executes the specified SQL SELECT statement and returns a (possibly empty) ResultSet with the results of the query.
 int executeUpdate(java.lang.String sql)
          This method executes the specified SQL INSERT, UPDATE, or DELETE statement and returns the number of rows affected, which may be 0.
 int executeUpdate(java.lang.String sql, int autoGeneratedKeys)
           
 int executeUpdate(java.lang.String sql, int[] columnIndexes)
           
 int executeUpdate(java.lang.String sql, java.lang.String[] columnNames)
           
 java.sql.Connection getConnection()
          This method returns the Connection instance that was used to create this object.
 java.sql.Statement getDelegate()
          Returns my underlying java.sql.Statement.
 int getFetchDirection()
          This method returns the current direction that the driver thinks the result set will be accessed int.
 int getFetchSize()
          This method returns the number of rows the driver believes should be fetched from the database at a time.
 java.sql.ResultSet getGeneratedKeys()
           
 java.sql.Statement getInnermostDelegate()
          If my underlying java.sql.Statement is not a DelegatingStatement, returns it, otherwise recursively invokes this method on my delegate.
 int getMaxFieldSize()
          This method returns the maximum length of any column value in bytes.
 int getMaxRows()
          This method returns the maximum possible number of rows in a result set.
 boolean getMoreResults()
          This method advances the result set pointer to the next result set, which can then be retrieved using getResultSet
 boolean getMoreResults(int current)
           
 int getQueryTimeout()
          The method returns the number of seconds a statement may be in process before timing out.
 java.sql.ResultSet getResultSet()
          This method returns the result set of the SQL statement that was executed.
 int getResultSetConcurrency()
          This method returns the concurrency type of the result set for this statement.
 int getResultSetHoldability()
           
 int getResultSetType()
          This method returns the result set type for this statement.
 int getUpdateCount()
          This method returns the update count of the SQL statement that was executed.
 java.sql.SQLWarning getWarnings()
          This method returns the first SQL warning attached to this statement.
protected  void handleException(java.sql.SQLException e)
           
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
protected  boolean isClosed()
           
protected  void passivate()
           
 void setCursorName(java.lang.String name)
          This method sets the cursor name that will be used by the result set.
 void setDelegate(java.sql.Statement s)
          Sets my delegate.
 void setEscapeProcessing(boolean enable)
          This method sets the local escape processing mode on or off.
 void setFetchDirection(int direction)
          This method informs the driver which direction the result set will be accessed in.
 void setFetchSize(int rows)
          This method informs the driver how many rows it should fetch from the database at a time.
 void setMaxFieldSize(int max)
          This method sets the limit for the maximum length of any column in bytes.
 void setMaxRows(int max)
          This method sets the maximum number of rows that can be present in a result set.
 void setQueryTimeout(int seconds)
          This method sets the number of seconds a statement may be in process before timing out.
 
Methods inherited from class org.apache.commons.dbcp.AbandonedTrace
addTrace, clearTrace, getConfig, getLastUsed, getTrace, printStackTrace, removeTrace, setLastUsed, setLastUsed, setStackTrace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_stmt

protected java.sql.Statement _stmt
My delegate.


_conn

protected DelegatingConnection _conn
The connection that created me.


_closed

protected boolean _closed
Constructor Detail

DelegatingStatement

public DelegatingStatement(DelegatingConnection c,
                           java.sql.Statement s)
Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code which created it.

Method Detail

getDelegate

public java.sql.Statement getDelegate()
Returns my underlying java.sql.Statement.


equals

public boolean equals(java.lang.Object obj)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.


hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


getInnermostDelegate

public java.sql.Statement getInnermostDelegate()
If my underlying java.sql.Statement is not a DelegatingStatement, returns it, otherwise recursively invokes this method on my delegate.

Hence this method will return the first delegate that is not a DelegatingStatement or null when no non-DelegatingStatement delegate can be found by transversing this chain.

This method is useful when you may have nested DelegatingStatements, and you want to make sure to obtain a "genuine" java.sql.Statement.


setDelegate

public void setDelegate(java.sql.Statement s)
Sets my delegate.


isClosed

protected boolean isClosed()

checkOpen

protected void checkOpen()
                  throws java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Close this DelegatingStatement, and close any ResultSets that were not explicitly closed.

Specified by:
close in interface java.sql.Statement

handleException

protected void handleException(java.sql.SQLException e)
                        throws java.sql.SQLException

activate

protected void activate()
                 throws java.sql.SQLException

passivate

protected void passivate()
                  throws java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the Connection instance that was used to create this object.

Specified by:
getConnection in interface java.sql.Statement

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql)
                                throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method executes the specified SQL SELECT statement and returns a (possibly empty) ResultSet with the results of the query.

Specified by:
executeQuery in interface java.sql.Statement

getResultSet

public java.sql.ResultSet getResultSet()
                                throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the result set of the SQL statement that was executed. This should be called only once per result set returned.

Specified by:
getResultSet in interface java.sql.Statement

executeUpdate

public int executeUpdate(java.lang.String sql)
                  throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method executes the specified SQL INSERT, UPDATE, or DELETE statement and returns the number of rows affected, which may be 0.

Specified by:
executeUpdate in interface java.sql.Statement

getMaxFieldSize

public int getMaxFieldSize()
                    throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the maximum length of any column value in bytes.

Specified by:
getMaxFieldSize in interface java.sql.Statement

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method sets the limit for the maximum length of any column in bytes.

Specified by:
setMaxFieldSize in interface java.sql.Statement

getMaxRows

public int getMaxRows()
               throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the maximum possible number of rows in a result set.

Specified by:
getMaxRows in interface java.sql.Statement

setMaxRows

public void setMaxRows(int max)
                throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method sets the maximum number of rows that can be present in a result set.

Specified by:
setMaxRows in interface java.sql.Statement

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method sets the local escape processing mode on or off. The default value is on.

Specified by:
setEscapeProcessing in interface java.sql.Statement

getQueryTimeout

public int getQueryTimeout()
                    throws java.sql.SQLException
Description copied from interface: java.sql.Statement
The method returns the number of seconds a statement may be in process before timing out. A value of 0 means there is no timeout.

Specified by:
getQueryTimeout in interface java.sql.Statement

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method sets the number of seconds a statement may be in process before timing out. A value of 0 means there is no timeout.

Specified by:
setQueryTimeout in interface java.sql.Statement

cancel

public void cancel()
            throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method cancels an outstanding statement, if the database supports that operation.

Specified by:
cancel in interface java.sql.Statement

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the first SQL warning attached to this statement. Subsequent warnings will be chained to this one.

Specified by:
getWarnings in interface java.sql.Statement

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method clears any SQL warnings that have been attached to this statement.

Specified by:
clearWarnings in interface java.sql.Statement

setCursorName

public void setCursorName(java.lang.String name)
                   throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method sets the cursor name that will be used by the result set.

Specified by:
setCursorName in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql)
                throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method executes an arbitrary SQL statement of any time. The methods getResultSet, getMoreResults and getUpdateCount retrieve the results.

Specified by:
execute in interface java.sql.Statement

getUpdateCount

public int getUpdateCount()
                   throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the update count of the SQL statement that was executed. This should be called only once per executed SQL statement.

Specified by:
getUpdateCount in interface java.sql.Statement

getMoreResults

public boolean getMoreResults()
                       throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method advances the result set pointer to the next result set, which can then be retrieved using getResultSet

Specified by:
getMoreResults in interface java.sql.Statement

setFetchDirection

public void setFetchDirection(int direction)
                       throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method informs the driver which direction the result set will be accessed in.

Specified by:
setFetchDirection in interface java.sql.Statement

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the current direction that the driver thinks the result set will be accessed int.

Specified by:
getFetchDirection in interface java.sql.Statement

setFetchSize

public void setFetchSize(int rows)
                  throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method informs the driver how many rows it should fetch from the database at a time.

Specified by:
setFetchSize in interface java.sql.Statement

getFetchSize

public int getFetchSize()
                 throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the number of rows the driver believes should be fetched from the database at a time.

Specified by:
getFetchSize in interface java.sql.Statement

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the concurrency type of the result set for this statement. This will be one of the concurrency types defined in ResultSet.

Specified by:
getResultSetConcurrency in interface java.sql.Statement

getResultSetType

public int getResultSetType()
                     throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method returns the result set type for this statement. This will be one of the result set types defined in ResultSet.

Specified by:
getResultSetType in interface java.sql.Statement

addBatch

public void addBatch(java.lang.String sql)
              throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method adds a SQL statement to a SQL batch. A driver is not required to implement this method.

Specified by:
addBatch in interface java.sql.Statement

clearBatch

public void clearBatch()
                throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method clears out any SQL statements that have been populated in the current batch. A driver is not required to implement this method.

Specified by:
clearBatch in interface java.sql.Statement

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
Description copied from interface: java.sql.Statement
This method executes the SQL batch and returns an array of update counts - one for each SQL statement in the batch - ordered in the same order the statements were added to the batch. A driver is not required to implement this method.

Specified by:
executeBatch in interface java.sql.Statement

getMoreResults

public boolean getMoreResults(int current)
                       throws java.sql.SQLException
Specified by:
getMoreResults in interface java.sql.Statement

getGeneratedKeys

public java.sql.ResultSet getGeneratedKeys()
                                    throws java.sql.SQLException
Specified by:
getGeneratedKeys in interface java.sql.Statement

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int autoGeneratedKeys)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int[] columnIndexes)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement

executeUpdate

public int executeUpdate(java.lang.String sql,
                         java.lang.String[] columnNames)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql,
                       int autoGeneratedKeys)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql,
                       int[] columnIndexes)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement

execute

public boolean execute(java.lang.String sql,
                       java.lang.String[] columnNames)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement

getResultSetHoldability

public int getResultSetHoldability()
                            throws java.sql.SQLException
Specified by:
getResultSetHoldability in interface java.sql.Statement