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)
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() |
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 |
setQueryTimeout(int seconds) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcloseOnCompletion, isClosed, isCloseOnCompletion, isPoolable, setPoolableisWrapperFor, unwrapprotected final SpyLogDelegator log
protected ConnectionSpy connectionSpy
protected Statement realStatement
protected String sql
public StatementSpy(ConnectionSpy connectionSpy, Statement realStatement)
connectionSpy - Connection that created this Statement.realStatement - real underlying Statement that this StatementSpy wraps.public Statement getRealStatement()
public String getClassType()
SpygetClassType in interface Spypublic Integer getConnectionNumber()
SpygetConnectionNumber in interface Spyprotected 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 StatementSQLExceptionpublic int executeUpdate(String sql, String[] columnNames) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic boolean execute(String sql, String[] columnNames) throws SQLException
execute in interface StatementSQLExceptionpublic void setMaxRows(int max)
throws SQLException
setMaxRows in interface StatementSQLExceptionpublic boolean getMoreResults()
throws SQLException
getMoreResults in interface StatementSQLExceptionpublic void clearWarnings()
throws SQLException
clearWarnings in interface StatementSQLExceptionpublic void addBatch(String sql) throws SQLException
addBatch in interface StatementSQLExceptionpublic int getResultSetType()
throws SQLException
getResultSetType in interface StatementSQLExceptionpublic void clearBatch()
throws SQLException
clearBatch in interface StatementSQLExceptionpublic void setFetchDirection(int direction)
throws SQLException
setFetchDirection in interface StatementSQLExceptionpublic int[] executeBatch()
throws SQLException
executeBatch in interface StatementSQLExceptionpublic void setFetchSize(int rows)
throws SQLException
setFetchSize in interface StatementSQLExceptionpublic int getQueryTimeout()
throws SQLException
getQueryTimeout in interface StatementSQLExceptionpublic Connection getConnection() throws SQLException
getConnection in interface StatementSQLExceptionpublic ResultSet getGeneratedKeys() throws SQLException
getGeneratedKeys in interface StatementSQLExceptionprotected ResultSet getGeneratedKeys(String sql) throws SQLException
sql - the SQL querySQLExceptionpublic void setEscapeProcessing(boolean enable)
throws SQLException
setEscapeProcessing in interface StatementSQLExceptionpublic int getFetchDirection()
throws SQLException
getFetchDirection in interface StatementSQLExceptionpublic void setQueryTimeout(int seconds)
throws SQLException
setQueryTimeout in interface StatementSQLExceptionpublic boolean getMoreResults(int current)
throws SQLException
getMoreResults in interface StatementSQLExceptionpublic ResultSet executeQuery(String sql) throws SQLException
executeQuery in interface StatementSQLExceptionpublic int getMaxFieldSize()
throws SQLException
getMaxFieldSize in interface StatementSQLExceptionpublic int executeUpdate(String sql) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic void cancel()
throws SQLException
cancel in interface StatementSQLExceptionpublic void setCursorName(String name) throws SQLException
setCursorName in interface StatementSQLExceptionpublic int getFetchSize()
throws SQLException
getFetchSize in interface StatementSQLExceptionpublic int getResultSetConcurrency()
throws SQLException
getResultSetConcurrency in interface StatementSQLExceptionpublic int getResultSetHoldability()
throws SQLException
getResultSetHoldability in interface StatementSQLExceptionpublic void setMaxFieldSize(int max)
throws SQLException
setMaxFieldSize in interface StatementSQLExceptionpublic boolean execute(String sql) throws SQLException
execute in interface StatementSQLExceptionpublic int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic boolean execute(String sql, int autoGeneratedKeys) throws SQLException
execute in interface StatementSQLExceptionpublic int executeUpdate(String sql, int[] columnIndexes) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic boolean execute(String sql, int[] columnIndexes) throws SQLException
execute in interface StatementSQLExceptionpublic ResultSet getResultSet() throws SQLException
getResultSet in interface StatementSQLExceptionpublic int getMaxRows()
throws SQLException
getMaxRows in interface StatementSQLExceptionpublic void close()
throws SQLException
close in interface AutoCloseableclose in interface StatementSQLExceptionpublic int getUpdateCount()
throws SQLException
getUpdateCount in interface StatementSQLExceptionCopyright © 2013 Bgee - Swiss Institute of Bioinformatics. All Rights Reserved.