Class StasiStatement
java.lang.Object
clazzfish.jdbc.internal.StasiStatement
- All Implemented Interfaces:
AutoCloseable
,Statement
,Wrapper
- Direct Known Subclasses:
StasiPreparedStatement
A simple wrapper for
Statement
to be able to find resource problems
while reading and writing to the database. It allows us also to measure times
of SQL statements.
Why the name "Stasi..."? The Stasi was the official state security service of
Eastern Germany which controls the people (like NSA in the U.S. or KGB in
Russia, see also Wikipedia).
The StasiStatement controls the embedded Statement
- therefore the
name.
- Since:
- 1.4.1 (16.03.2014)
- Version:
- $Revision: 1.13 $
- Author:
- oliver
-
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds the batch.final void
cancel()
Cancel.final void
Clear batch.final void
Clear warnings.void
close()
Close.final void
Close on completion.protected SQLException
enrichedSQLException
(ProfileMonitor mon, String sql, SQLException original) For better error analysis the originalSQLException
will be enriched with some additional infos.final boolean
Execute.final boolean
Execute.final boolean
Execute.final boolean
Execute.final int[]
Execute batch.final ResultSet
executeQuery
(String sql) Execute query.final int
executeUpdate
(String sql) Execute update.final int
executeUpdate
(String sql, int autoGeneratedKeys) Execute update.final int
executeUpdate
(String sql, int[] columnIndexes) Execute update.final int
executeUpdate
(String sql, String[] columnNames) Execute update.static StackTraceElement[]
getCallerStacktrace
(Class<?>... ignoredClasses) Gets the caller stacktrace.final Connection
Gets the connection.final int
Gets the fetch direction.final int
Gets the fetch size.final ResultSet
Gets the generated keys.long
Retrieves the current result as an update count; if the result is aResultSet
object or there are no more results, -1 is returned.final int
Gets the max field size.final int
Gets the max rows.final boolean
Gets the more results.final boolean
getMoreResults
(int current) Gets the more results.final int
Gets the query timeout.final ResultSet
Gets the result set.final int
Gets the result set concurrency.final int
Gets the result set holdability.final int
Gets the result set type.protected final Statement
Gets the statement.final int
Gets the update count.int
If an entry was updated with one of the executeUpdate methods this method returns the number of updated entries.final SQLWarning
Gets the warnings.final boolean
isClosed()
Checks if is closed.final boolean
Checks if is close on completion.final boolean
Checks if is poolable.final boolean
isWrapperFor
(Class<?> arg0) Checks if is wrapper for.protected int
saveUpdateStatistic
(ProfileMonitor mon, String sql, int rc) Save update statistic.final void
setCursorName
(String name) Sets the cursor name.final void
setEscapeProcessing
(boolean enable) Sets the escape processing.final void
setFetchDirection
(int direction) Sets the fetch direction.final void
setFetchSize
(int rows) Sets the fetch size.final void
setMaxFieldSize
(int max) Sets the max field size.final void
setMaxRows
(int max) Sets the max rows.final void
setPoolable
(boolean poolable) Sets the poolable.final void
setQueryTimeout
(int seconds) Sets the query timeout.toString()
To string.final <T> T
Unwrap.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.Statement
enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, getLargeMaxRows, isSimpleIdentifier, setLargeMaxRows
-
Constructor Details
-
StasiStatement
Instantiates a new proxy statement.- Parameters:
statement
- the statement
-
-
Method Details
-
getCallerStacktrace
Gets the caller stacktrace. To find the real caller we ignore the first 3 elements from the stacktrace because this is e.g. the methodThread.getStackTrace()
which is not relevant here.- Parameters:
ignoredClasses
- the ignored classes- Returns:
- the caller stacktrace
-
getUpdated
public int getUpdated()If an entry was updated with one of the executeUpdate methods this method returns the number of updated entries. Otherwise 0,- Returns:
- the number of updated entries (or 0)
- Since:
- 1.6.3
-
getStatement
-
addBatch
Adds the batch.- Specified by:
addBatch
in interfaceStatement
- Parameters:
sql
- the sql- Throws:
SQLException
- the SQL exception- See Also:
-
cancel
Cancel.- Specified by:
cancel
in interfaceStatement
- Throws:
SQLException
- the sQL exception- See Also:
-
clearBatch
Clear batch.- Specified by:
clearBatch
in interfaceStatement
- Throws:
SQLException
- the sQL exception- See Also:
-
clearWarnings
Clear warnings.- Specified by:
clearWarnings
in interfaceStatement
- Throws:
SQLException
- the sQL exception- See Also:
-
close
Close.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceStatement
- Throws:
SQLException
- the sQL exception- See Also:
-
execute
Execute.- Specified by:
execute
in interfaceStatement
- Parameters:
sql
- the sqlautoGeneratedKeys
- the auto generated keys- Returns:
- true, if successful
- Throws:
SQLException
- the sQL exception- See Also:
-
execute
Execute.- Specified by:
execute
in interfaceStatement
- Parameters:
sql
- the sqlcolumnIndexes
- the column indexes- Returns:
- true, if successful
- Throws:
SQLException
- the sQL exception- See Also:
-
execute
Execute.- Specified by:
execute
in interfaceStatement
- Parameters:
sql
- the sqlcolumnNames
- the column names- Returns:
- true, if successful
- Throws:
SQLException
- the sQL exception- See Also:
-
execute
Execute.- Specified by:
execute
in interfaceStatement
- Parameters:
sql
- the sql- Returns:
- true, if successful
- Throws:
SQLException
- the sQL exception- See Also:
-
executeBatch
Execute batch.- Specified by:
executeBatch
in interfaceStatement
- Returns:
- the int[]
- Throws:
SQLException
- the sQL exception- See Also:
-
executeQuery
Execute query.- Specified by:
executeQuery
in interfaceStatement
- Parameters:
sql
- the sql- Returns:
- the result set
- Throws:
SQLException
- the sQL exception- See Also:
-
executeUpdate
Execute update.- Specified by:
executeUpdate
in interfaceStatement
- Parameters:
sql
- the sqlautoGeneratedKeys
- the auto generated keys- Returns:
- the int
- Throws:
SQLException
- the sQL exception- See Also:
-
executeUpdate
Execute update.- Specified by:
executeUpdate
in interfaceStatement
- Parameters:
sql
- the sqlcolumnIndexes
- the column indexes- Returns:
- the int
- Throws:
SQLException
- the sQL exception- See Also:
-
executeUpdate
Execute update.- Specified by:
executeUpdate
in interfaceStatement
- Parameters:
sql
- the sqlcolumnNames
- the column names- Returns:
- the int
- Throws:
SQLException
- the sQL exception- See Also:
-
executeUpdate
Execute update.- Specified by:
executeUpdate
in interfaceStatement
- Parameters:
sql
- the sql- Returns:
- the int
- Throws:
SQLException
- the sQL exception- See Also:
-
saveUpdateStatistic
Save update statistic.- Parameters:
mon
- the monitor for the statisticsql
- the sqlrc
- the return code (= number of updated entries)- Returns:
- the same as rc
-
enrichedSQLException
For better error analysis the originalSQLException
will be enriched with some additional infos.- Parameters:
mon
- the monsql
- the sqloriginal
- the original- Returns:
- the sQL exception
-
getConnection
Gets the connection.- Specified by:
getConnection
in interfaceStatement
- Returns:
- the connection
- Throws:
SQLException
- the sQL exception- See Also:
-
getFetchDirection
Gets the fetch direction.- Specified by:
getFetchDirection
in interfaceStatement
- Returns:
- the fetch direction
- Throws:
SQLException
- the sQL exception- See Also:
-
getFetchSize
Gets the fetch size.- Specified by:
getFetchSize
in interfaceStatement
- Returns:
- the fetch size
- Throws:
SQLException
- the sQL exception- See Also:
-
getGeneratedKeys
Gets the generated keys.- Specified by:
getGeneratedKeys
in interfaceStatement
- Returns:
- the generated keys
- Throws:
SQLException
- the sQL exception- See Also:
-
getMaxFieldSize
Gets the max field size.- Specified by:
getMaxFieldSize
in interfaceStatement
- Returns:
- the max field size
- Throws:
SQLException
- the sQL exception- See Also:
-
getMaxRows
Gets the max rows.- Specified by:
getMaxRows
in interfaceStatement
- Returns:
- the max rows
- Throws:
SQLException
- the sQL exception- See Also:
-
getMoreResults
Gets the more results.- Specified by:
getMoreResults
in interfaceStatement
- Returns:
- the more results
- Throws:
SQLException
- the sQL exception- See Also:
-
getMoreResults
Gets the more results.- Specified by:
getMoreResults
in interfaceStatement
- Parameters:
current
- the current- Returns:
- the more results
- Throws:
SQLException
- the sQL exception- See Also:
-
getQueryTimeout
Gets the query timeout.- Specified by:
getQueryTimeout
in interfaceStatement
- Returns:
- the query timeout
- Throws:
SQLException
- the sQL exception- See Also:
-
getResultSet
Gets the result set.- Specified by:
getResultSet
in interfaceStatement
- Returns:
- the result set
- Throws:
SQLException
- the sQL exception- See Also:
-
getResultSetConcurrency
Gets the result set concurrency.- Specified by:
getResultSetConcurrency
in interfaceStatement
- Returns:
- the result set concurrency
- Throws:
SQLException
- the sQL exception- See Also:
-
getResultSetHoldability
Gets the result set holdability.- Specified by:
getResultSetHoldability
in interfaceStatement
- Returns:
- the result set holdability
- Throws:
SQLException
- the sQL exception- See Also:
-
getResultSetType
Gets the result set type.- Specified by:
getResultSetType
in interfaceStatement
- Returns:
- the result set type
- Throws:
SQLException
- the sQL exception- See Also:
-
getUpdateCount
public final int getUpdateCount()Gets the update count. This method works always - wether the statemnt was closed or not.- Specified by:
getUpdateCount
in interfaceStatement
- Returns:
- the update count
- See Also:
-
getWarnings
Gets the warnings.- Specified by:
getWarnings
in interfaceStatement
- Returns:
- the warnings
- Throws:
SQLException
- the sQL exception- See Also:
-
isClosed
Checks if is closed.- Specified by:
isClosed
in interfaceStatement
- Returns:
- true, if is closed
- Throws:
SQLException
- the sQL exception- See Also:
-
isPoolable
Checks if is poolable.- Specified by:
isPoolable
in interfaceStatement
- Returns:
- true, if is poolable
- Throws:
SQLException
- the sQL exception- See Also:
-
isWrapperFor
Checks if is wrapper for.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
arg0
- the arg0- Returns:
- true, if is wrapper for
- Throws:
SQLException
- the sQL exception- See Also:
-
setCursorName
Sets the cursor name.- Specified by:
setCursorName
in interfaceStatement
- Parameters:
name
- the new cursor name- Throws:
SQLException
- the sQL exception- See Also:
-
setEscapeProcessing
Sets the escape processing.- Specified by:
setEscapeProcessing
in interfaceStatement
- Parameters:
enable
- the new escape processing- Throws:
SQLException
- the sQL exception- See Also:
-
setFetchDirection
Sets the fetch direction.- Specified by:
setFetchDirection
in interfaceStatement
- Parameters:
direction
- the new fetch direction- Throws:
SQLException
- the sQL exception- See Also:
-
setFetchSize
Sets the fetch size.- Specified by:
setFetchSize
in interfaceStatement
- Parameters:
rows
- the new fetch size- Throws:
SQLException
- the sQL exception- See Also:
-
setMaxFieldSize
Sets the max field size.- Specified by:
setMaxFieldSize
in interfaceStatement
- Parameters:
max
- the new max field size- Throws:
SQLException
- the sQL exception- See Also:
-
setMaxRows
Sets the max rows.- Specified by:
setMaxRows
in interfaceStatement
- Parameters:
max
- the new max rows- Throws:
SQLException
- the sQL exception- See Also:
-
setPoolable
Sets the poolable.- Specified by:
setPoolable
in interfaceStatement
- Parameters:
poolable
- the new poolable- Throws:
SQLException
- the sQL exception- See Also:
-
setQueryTimeout
Sets the query timeout.- Specified by:
setQueryTimeout
in interfaceStatement
- Parameters:
seconds
- the new query timeout- Throws:
SQLException
- the sQL exception- See Also:
-
unwrap
Unwrap.- Specified by:
unwrap
in interfaceWrapper
- Type Parameters:
T
- the generic type- Parameters:
statementClass
- the unwrapped statement class- Returns:
- the t
- Throws:
SQLException
- the sQL exception- See Also:
-
closeOnCompletion
Close on completion. This method is not required for Java 6 and below but for Java 7. To be compatible with Java 6 this method has no implementation.- Specified by:
closeOnCompletion
in interfaceStatement
- Throws:
SQLException
- the SQL exception- Since:
- Java 7
-
isCloseOnCompletion
Checks if is close on completion. This method is not required for Java 6 and below but for Java 7. To be compatible with Java 6 this method has no implementation.- Specified by:
isCloseOnCompletion
in interfaceStatement
- Returns:
- true, if is close on completion
- Throws:
SQLException
- the SQL exception- Since:
- Java 7
-
getLargeUpdateCount
Retrieves the current result as an update count; if the result is aResultSet
object or there are no more results, -1 is returned. This method should be called only once per result.This method should be used when the returned row count may exceed
Integer.MAX_VALUE
.- Specified by:
getLargeUpdateCount
in interfaceStatement
- Returns:
- the current result as an update count; -1 if the current result
is a
ResultSet
object or there are no more results - Throws:
SQLException
- if a database access error occurs or this method is called on a closedStatement
- Since:
- Java 8
- See Also:
-
toString
-