Package org.apache.commons.dbcp2
Class DelegatingStatement
java.lang.Object
org.apache.commons.dbcp2.AbandonedTrace
org.apache.commons.dbcp2.DelegatingStatement
- All Implemented Interfaces:
AutoCloseable
,Statement
,Wrapper
,TrackedUse
- Direct Known Subclasses:
DelegatingPreparedStatement
A base delegating implementation of
Statement
.
All of the methods from the Statement
interface simply check to see that the 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.
- Since:
- 2.0
-
Field Summary
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
ConstructorDescriptionDelegatingStatement
(DelegatingConnection<?> connection, Statement statement) Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code which created it. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
void
void
cancel()
protected void
void
void
void
close()
Close this DelegatingStatement, and close any ResultSets that were not explicitly closed.void
boolean
boolean
boolean
boolean
int[]
long[]
long
executeLargeUpdate
(String sql) long
executeLargeUpdate
(String sql, int autoGeneratedKeys) long
executeLargeUpdate
(String sql, int[] columnIndexes) long
executeLargeUpdate
(String sql, String[] columnNames) executeQuery
(String sql) int
executeUpdate
(String sql) int
executeUpdate
(String sql, int autoGeneratedKeys) int
executeUpdate
(String sql, int[] columnIndexes) int
executeUpdate
(String sql, String[] columnNames) protected void
finalize()
protected DelegatingConnection
<?> Returns my underlyingStatement
.int
int
If my underlyingStatement
is not aDelegatingStatement
, returns it, otherwise recursively invokes this method on my delegate.long
long
int
int
boolean
boolean
getMoreResults
(int current) int
int
int
int
int
protected void
boolean
isClosed()
protected boolean
boolean
boolean
boolean
isWrapperFor
(Class<?> iface) void
protected void
setClosedInternal
(boolean closed) void
setCursorName
(String name) void
setDelegate
(Statement statement) Sets my delegate.void
setEscapeProcessing
(boolean enable) void
setFetchDirection
(int direction) void
setFetchSize
(int rows) void
setLargeMaxRows
(long max) void
setMaxFieldSize
(int max) void
setMaxRows
(int max) void
setPoolable
(boolean poolable) void
setQueryTimeout
(int seconds) toString()
Returns a String representation of this object.<T> T
Methods inherited from class org.apache.commons.dbcp2.AbandonedTrace
addTrace, clearTrace, close, getLastUsed, getLastUsedInstant, getTrace, removeThisTrace, removeTrace, setLastUsed, setLastUsed, setLastUsed
-
Constructor Details
-
DelegatingStatement
Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code which created it.- Parameters:
connection
- theDelegatingConnection
that created this statement.statement
- theStatement
to delegate all calls to.
-
-
Method Details
-
activate
- Throws:
SQLException
- thrown by the delegating statement.- Since:
- 2.4.0 made public, was protected in 2.3.0.
-
addBatch
- Specified by:
addBatch
in interfaceStatement
- Throws:
SQLException
-
cancel
- Specified by:
cancel
in interfaceStatement
- Throws:
SQLException
-
checkOpen
- Throws:
SQLException
-
clearBatch
- Specified by:
clearBatch
in interfaceStatement
- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarnings
in interfaceStatement
- Throws:
SQLException
-
close
Close this DelegatingStatement, and close any ResultSets that were not explicitly closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceStatement
- Overrides:
close
in classAbandonedTrace
- Throws:
SQLException
- Ignored here, for subclasses.
-
closeOnCompletion
- Specified by:
closeOnCompletion
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Throws:
SQLException
-
executeBatch
- Specified by:
executeBatch
in interfaceStatement
- Throws:
SQLException
-
executeLargeBatch
- Specified by:
executeLargeBatch
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
executeQuery
- Specified by:
executeQuery
in interfaceStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
finalize
-
getConnection
- Specified by:
getConnection
in interfaceStatement
- Throws:
SQLException
-
getConnectionInternal
-
getDelegate
Returns my underlyingStatement
.- Returns:
- my underlying
Statement
. - See Also:
-
getFetchDirection
- Specified by:
getFetchDirection
in interfaceStatement
- Throws:
SQLException
-
getFetchSize
- Specified by:
getFetchSize
in interfaceStatement
- Throws:
SQLException
-
getGeneratedKeys
- Specified by:
getGeneratedKeys
in interfaceStatement
- Throws:
SQLException
-
getInnermostDelegate
If my underlyingStatement
is not aDelegatingStatement
, returns it, otherwise recursively invokes this method on my delegate.Hence this method will return the first delegate that is not a
DelegatingStatement
ornull
when no non-DelegatingStatement
delegate can be found by traversing this chain.This method is useful when you may have nested
DelegatingStatement
s, and you want to make sure to obtain a "genuine"Statement
.- Returns:
- The innermost delegate, may return null.
- See Also:
-
getLargeMaxRows
- Specified by:
getLargeMaxRows
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
getLargeUpdateCount
- Specified by:
getLargeUpdateCount
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
getMaxFieldSize
- Specified by:
getMaxFieldSize
in interfaceStatement
- Throws:
SQLException
-
getMaxRows
- Specified by:
getMaxRows
in interfaceStatement
- Throws:
SQLException
-
getMoreResults
- Specified by:
getMoreResults
in interfaceStatement
- Throws:
SQLException
-
getMoreResults
- Specified by:
getMoreResults
in interfaceStatement
- Throws:
SQLException
-
getQueryTimeout
- Specified by:
getQueryTimeout
in interfaceStatement
- Throws:
SQLException
-
getResultSet
- Specified by:
getResultSet
in interfaceStatement
- Throws:
SQLException
-
getResultSetConcurrency
- Specified by:
getResultSetConcurrency
in interfaceStatement
- Throws:
SQLException
-
getResultSetHoldability
- Specified by:
getResultSetHoldability
in interfaceStatement
- Throws:
SQLException
-
getResultSetType
- Specified by:
getResultSetType
in interfaceStatement
- Throws:
SQLException
-
getUpdateCount
- Specified by:
getUpdateCount
in interfaceStatement
- Throws:
SQLException
-
getWarnings
- Specified by:
getWarnings
in interfaceStatement
- Throws:
SQLException
-
handleException
- Throws:
SQLException
-
isClosed
- Specified by:
isClosed
in interfaceStatement
- Throws:
SQLException
-
isClosedInternal
-
isCloseOnCompletion
- Specified by:
isCloseOnCompletion
in interfaceStatement
- Throws:
SQLException
-
isPoolable
- Specified by:
isPoolable
in interfaceStatement
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
passivate
- Throws:
SQLException
- thrown by the delegating statement.- Since:
- 2.4.0 made public, was protected in 2.3.0.
-
setClosedInternal
-
setCursorName
- Specified by:
setCursorName
in interfaceStatement
- Throws:
SQLException
-
setDelegate
Sets my delegate.- Parameters:
statement
- my delegate.
-
setEscapeProcessing
- Specified by:
setEscapeProcessing
in interfaceStatement
- Throws:
SQLException
-
setFetchDirection
- Specified by:
setFetchDirection
in interfaceStatement
- Throws:
SQLException
-
setFetchSize
- Specified by:
setFetchSize
in interfaceStatement
- Throws:
SQLException
-
setLargeMaxRows
- Specified by:
setLargeMaxRows
in interfaceStatement
- Throws:
SQLException
- Since:
- 2.5.0
-
setMaxFieldSize
- Specified by:
setMaxFieldSize
in interfaceStatement
- Throws:
SQLException
-
setMaxRows
- Specified by:
setMaxRows
in interfaceStatement
- Throws:
SQLException
-
setPoolable
- Specified by:
setPoolable
in interfaceStatement
- Throws:
SQLException
-
setQueryTimeout
- Specified by:
setQueryTimeout
in interfaceStatement
- Throws:
SQLException
-
toString
Returns a String representation of this object. -
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-