public class StatementSpy extends Object implements Statement, Spy
MODIFICATIONS FOR LOG4J2:
sql
attribute of the class PreparedStatementSpy
have been moved here, so that we can know on which query
a getGeneratedKeys()
is performed. It is useful in case of
interleaved queries using different connections.
execute...
methods now set this sql
attribute.
getGeneratedKeys(String)
,
which allows to launch a reportSqlTiming(long, String, String)
.
getGeneratedKeys()
now delegates to this method getGeneratedKeys(String)
,
by providing the sql
attribute.
Modifier and Type | Field and Description |
---|---|
protected ConnectionSpy |
connectionSpy
The Connection that created this Statement.
|
protected List<String> |
currentBatch
Tracking of current batch (see addBatch, clearBatch and executeBatch)
//todo: should access to this List be synchronized?
|
protected SpyLogDelegator |
log |
protected Statement |
realStatement
The real statement that this StatementSpy wraps.
|
protected String |
sql
The SQL query.
|
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
Constructor and Description |
---|
StatementSpy(ConnectionSpy connectionSpy,
Statement realStatement,
SpyLogDelegator logDelegator)
Create a StatementSpy that wraps another Statement
for the purpose of logging all method calls, sql, exceptions and return values.
|
Modifier and Type | Method and Description |
---|---|
void |
addBatch(String sql) |
void |
cancel() |
void |
clearBatch() |
void |
clearWarnings() |
void |
close() |
boolean |
execute(String sql) |
boolean |
execute(String sql,
int autoGeneratedKeys) |
boolean |
execute(String sql,
int[] columnIndexes) |
boolean |
execute(String sql,
String[] columnNames) |
int[] |
executeBatch() |
ResultSet |
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) |
String |
getClassType()
Get the type of class being spied upon.
|
Connection |
getConnection() |
Integer |
getConnectionNumber()
Get the connection number.
|
int |
getFetchDirection() |
int |
getFetchSize() |
ResultSet |
getGeneratedKeys() |
protected ResultSet |
getGeneratedKeys(String sql)
Convenient method to get generated keys and logging
the SQL query on which this operation is performed.
|
int |
getMaxFieldSize() |
int |
getMaxRows() |
boolean |
getMoreResults() |
boolean |
getMoreResults(int current) |
int |
getQueryTimeout() |
Statement |
getRealStatement()
Get the real Statement that this StatementSpy wraps.
|
ResultSet |
getResultSet() |
int |
getResultSetConcurrency() |
int |
getResultSetHoldability() |
int |
getResultSetType() |
int |
getUpdateCount() |
SQLWarning |
getWarnings() |
boolean |
isClosed() |
boolean |
isPoolable() |
boolean |
isWrapperFor(Class<?> iface) |
protected void |
reportAllReturns(String methodCall,
String msg)
Report (for logging) that a method returned.
|
protected void |
reportException(String methodCall,
SQLException exception)
Report an exception to be logged.
|
protected void |
reportException(String methodCall,
SQLException exception,
String sql)
Report an exception to be logged.
|
protected void |
reportException(String methodCall,
SQLException exception,
String sql,
long execTime)
Report an exception to be logged which includes timing data on a sql failure.
|
protected void |
reportReturn(String methodCall)
Conveniance method to report (for logging) that a method returned (void return type).
|
protected boolean |
reportReturn(String methodCall,
boolean value)
Conveniance method to report (for logging) that a method returned a boolean value.
|
protected byte |
reportReturn(String methodCall,
byte value)
Conveniance method to report (for logging) that a method returned a byte value.
|
protected double |
reportReturn(String methodCall,
double value)
Conveniance method to report (for logging) that a method returned a double value.
|
protected float |
reportReturn(String methodCall,
float value)
Conveniance method to report (for logging) that a method returned a float value.
|
protected int |
reportReturn(String methodCall,
int value)
Conveniance method to report (for logging) that a method returned a int value.
|
protected long |
reportReturn(String methodCall,
long value)
Conveniance method to report (for logging) that a method returned a long value.
|
protected Object |
reportReturn(String methodCall,
Object value)
Conveniance method to report (for logging) that a method returned an Object.
|
protected short |
reportReturn(String methodCall,
short value)
Conveniance method to report (for logging) that a method returned a short value.
|
protected void |
reportSql(String sql,
String methodCall)
Report SQL for logging.
|
protected void |
reportSqlTiming(long execTime,
String sql,
String methodCall)
Report SQL for logging.
|
protected void |
reportStatementSql(String sql,
String methodCall)
Report SQL for logging with a warning that it was generated from a statement.
|
protected void |
reportStatementSqlTiming(long execTime,
String sql,
String methodCall)
Report SQL for logging with a warning that it was generated from a statement.
|
void |
setCursorName(String name) |
void |
setEscapeProcessing(boolean enable) |
void |
setFetchDirection(int direction) |
void |
setFetchSize(int rows) |
void |
setMaxFieldSize(int max) |
void |
setMaxRows(int max) |
void |
setPoolable(boolean poolable) |
void |
setQueryTimeout(int seconds) |
<T> T |
unwrap(Class<T> iface) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
closeOnCompletion, isCloseOnCompletion
protected final SpyLogDelegator log
protected ConnectionSpy connectionSpy
protected Statement realStatement
protected String sql
public StatementSpy(ConnectionSpy connectionSpy, Statement realStatement, SpyLogDelegator logDelegator)
connectionSpy
- Connection that created this Statement.realStatement
- real underlying Statement that this StatementSpy wraps.logDelegator
- The SpyLogDelegator
used by
this StatementSpy
and all resources obtained from it
(ResultSet
s)public Statement getRealStatement()
public String getClassType()
Spy
getClassType
in interface Spy
public Integer getConnectionNumber()
Spy
getConnectionNumber
in interface Spy
protected void reportException(String methodCall, SQLException exception, String sql, long execTime)
methodCall
- description of method call and arguments passed to it that generated the exception.exception
- exception that was generatedsql
- SQL associated with the call.execTime
- amount of time that the jdbc driver was chugging on the SQL before it threw an exception.protected void reportException(String methodCall, SQLException exception, String sql)
methodCall
- description of method call and arguments passed to it that generated the exception.exception
- exception that was generatedsql
- SQL associated with the call.protected void reportException(String methodCall, SQLException exception)
methodCall
- description of method call and arguments passed to it that generated the exception.exception
- exception that was generatedprotected void reportAllReturns(String methodCall, String msg)
methodCall
- description of method call and arguments passed to it that returned.msg
- description of what the return value that was returned. may be an empty String for void return types.protected boolean reportReturn(String methodCall, boolean value)
methodCall
- description of method call and arguments passed to it that returned.value
- boolean return value.protected byte reportReturn(String methodCall, byte value)
methodCall
- description of method call and arguments passed to it that returned.value
- byte return value.protected int reportReturn(String methodCall, int value)
methodCall
- description of method call and arguments passed to it that returned.value
- int return value.protected double reportReturn(String methodCall, double value)
methodCall
- description of method call and arguments passed to it that returned.value
- double return value.protected short reportReturn(String methodCall, short value)
methodCall
- description of method call and arguments passed to it that returned.value
- short return value.protected long reportReturn(String methodCall, long value)
methodCall
- description of method call and arguments passed to it that returned.value
- long return value.protected float reportReturn(String methodCall, float value)
methodCall
- description of method call and arguments passed to it that returned.value
- float return value.protected Object reportReturn(String methodCall, Object value)
methodCall
- description of method call and arguments passed to it that returned.value
- return Object.protected void reportReturn(String methodCall)
methodCall
- description of method call and arguments passed to it that returned.protected void reportStatementSql(String sql, String methodCall)
sql
- the SQL being runmethodCall
- the name of the method that was running the SQLprotected void reportStatementSqlTiming(long execTime, String sql, String methodCall)
execTime
- execution time in msec.sql
- the SQL being runmethodCall
- the name of the method that was running the SQLprotected void reportSqlTiming(long execTime, String sql, String methodCall)
execTime
- execution time in msec.sql
- the SQL being runmethodCall
- the name of the method that was running the SQLprotected void reportSql(String sql, String methodCall)
sql
- the SQL being runmethodCall
- the name of the method that was running the SQLpublic SQLWarning getWarnings() throws SQLException
getWarnings
in interface Statement
SQLException
public int executeUpdate(String sql, String[] columnNames) throws SQLException
executeUpdate
in interface Statement
SQLException
public boolean execute(String sql, String[] columnNames) throws SQLException
execute
in interface Statement
SQLException
public void setMaxRows(int max) throws SQLException
setMaxRows
in interface Statement
SQLException
public boolean getMoreResults() throws SQLException
getMoreResults
in interface Statement
SQLException
public void clearWarnings() throws SQLException
clearWarnings
in interface Statement
SQLException
public void addBatch(String sql) throws SQLException
addBatch
in interface Statement
SQLException
public int getResultSetType() throws SQLException
getResultSetType
in interface Statement
SQLException
public void clearBatch() throws SQLException
clearBatch
in interface Statement
SQLException
public void setFetchDirection(int direction) throws SQLException
setFetchDirection
in interface Statement
SQLException
public int[] executeBatch() throws SQLException
executeBatch
in interface Statement
SQLException
public void setFetchSize(int rows) throws SQLException
setFetchSize
in interface Statement
SQLException
public int getQueryTimeout() throws SQLException
getQueryTimeout
in interface Statement
SQLException
public Connection getConnection() throws SQLException
getConnection
in interface Statement
SQLException
public ResultSet getGeneratedKeys() throws SQLException
getGeneratedKeys
in interface Statement
SQLException
protected ResultSet getGeneratedKeys(String sql) throws SQLException
sql
- the SQL querySQLException
public void setEscapeProcessing(boolean enable) throws SQLException
setEscapeProcessing
in interface Statement
SQLException
public int getFetchDirection() throws SQLException
getFetchDirection
in interface Statement
SQLException
public void setQueryTimeout(int seconds) throws SQLException
setQueryTimeout
in interface Statement
SQLException
public boolean getMoreResults(int current) throws SQLException
getMoreResults
in interface Statement
SQLException
public ResultSet executeQuery(String sql) throws SQLException
executeQuery
in interface Statement
SQLException
public int getMaxFieldSize() throws SQLException
getMaxFieldSize
in interface Statement
SQLException
public int executeUpdate(String sql) throws SQLException
executeUpdate
in interface Statement
SQLException
public void cancel() throws SQLException
cancel
in interface Statement
SQLException
public void setCursorName(String name) throws SQLException
setCursorName
in interface Statement
SQLException
public int getFetchSize() throws SQLException
getFetchSize
in interface Statement
SQLException
public int getResultSetConcurrency() throws SQLException
getResultSetConcurrency
in interface Statement
SQLException
public int getResultSetHoldability() throws SQLException
getResultSetHoldability
in interface Statement
SQLException
public boolean isClosed() throws SQLException
isClosed
in interface Statement
SQLException
public void setPoolable(boolean poolable) throws SQLException
setPoolable
in interface Statement
SQLException
public boolean isPoolable() throws SQLException
isPoolable
in interface Statement
SQLException
public void setMaxFieldSize(int max) throws SQLException
setMaxFieldSize
in interface Statement
SQLException
public boolean execute(String sql) throws SQLException
execute
in interface Statement
SQLException
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeUpdate
in interface Statement
SQLException
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
execute
in interface Statement
SQLException
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
executeUpdate
in interface Statement
SQLException
public boolean execute(String sql, int[] columnIndexes) throws SQLException
execute
in interface Statement
SQLException
public ResultSet getResultSet() throws SQLException
getResultSet
in interface Statement
SQLException
public int getMaxRows() throws SQLException
getMaxRows
in interface Statement
SQLException
public void close() throws SQLException
close
in interface AutoCloseable
close
in interface Statement
SQLException
public int getUpdateCount() throws SQLException
getUpdateCount
in interface Statement
SQLException
public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
SQLException
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
SQLException
Copyright © 2013 Bgee - Swiss Institute of Bioinformatics. All Rights Reserved.