org.javasimon.jdbc
Class SimonStatement

java.lang.Object
  extended by org.javasimon.jdbc.SimonStatement
All Implemented Interfaces:
Statement, Wrapper
Direct Known Subclasses:
SimonPreparedStatement

public class SimonStatement
extends Object
implements Statement

Simon JDBC proxy statement implementation class.

Since:
1.0
Version:
$Revision: 304 $ $Date: 2011-04-08 10:39:02 +0200 (Fri, 08 Apr 2011) $
Author:
Radovan Sninsky
See Also:
Statement

Field Summary
protected  List<String> batchSql
          List of batched SQL statements.
protected  Connection conn
          SQL connection.
protected  String prefix
          Hierarchy prefix for JDBC Simons.
protected  Split split
          Stopwatch split measuring the lifespan of the statement until it is closed across all executes.
protected  String sqlCmdLabel
          SQL statement label containing part up to the SQL command type.
protected  SqlNormalizer sqlNormalizer
          SQL normalizer helper object.
private  Statement stmt
           
 
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
SimonStatement(Connection conn, Statement stmt, String prefix)
          Class constructor, initializes Simons (lifespan, active) related to statement.
 
Method Summary
 void addBatch(String s)
          Adds given SQL command into batch list of sql and also into real batch.
 void cancel()
          
 void clearBatch()
          Clears batch sql list and real batch too.
 void clearWarnings()
          
 void close()
          Closes real statement, stops lifespan Simon and decrease active Simon.
 boolean execute(String sql)
          Measure and execute SQL operation.
 boolean execute(String sql, int autoGeneratedKeys)
          Measure and execute SQL operation.
 boolean execute(String sql, int[] columnIndexes)
          Measure and execute SQL operation.
 boolean execute(String sql, String[] columnNames)
          Measure and execute SQL operation.
 int[] executeBatch()
          Measure and execute SQL operation.
 ResultSet executeQuery(String sql)
          Measure and execute SQL operation.
 int executeUpdate(String sql)
          Measure and execute SQL operation.
 int executeUpdate(String sql, int autoGeneratedKeys)
          Measure and execute SQL operation.
 int executeUpdate(String sql, int[] columnIndexes)
          Measure and execute SQL operation.
 int executeUpdate(String sql, String[] columnNames)
          Measure and execute SQL operation.
protected  void finish(Split split)
          Called after each SQL command execution.
 Connection getConnection()
          Returns a connection object (simon impl.).
 int getFetchDirection()
          
 int getFetchSize()
          
 ResultSet getGeneratedKeys()
          
 int getMaxFieldSize()
          
 int getMaxRows()
          
 boolean getMoreResults()
          
 boolean getMoreResults(int i)
          
 int getQueryTimeout()
          
 ResultSet getResultSet()
          
 int getResultSetConcurrency()
          
 int getResultSetHoldability()
          
 int getResultSetType()
          
 int getUpdateCount()
          
 SQLWarning getWarnings()
          
protected  Split prepare(List<String> sqls)
          Called before each SQL command execution.
protected  Split prepare(String sql)
          Called before each SQL command execution.
 void setCursorName(String s)
          
 void setEscapeProcessing(boolean b)
          
 void setFetchDirection(int i)
          
 void setFetchSize(int i)
          
 void setMaxFieldSize(int i)
          
 void setMaxRows(int i)
          
 void setQueryTimeout(int i)
          
protected  Split startSplit()
          Starts the split for the SQL specific stopwatch, sets the note and returns the split.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.Statement
isClosed, isPoolable, setPoolable
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Field Detail

batchSql

protected final List<String> batchSql
List of batched SQL statements.


conn

protected Connection conn
SQL connection.


prefix

protected String prefix
Hierarchy prefix for JDBC Simons.


sqlCmdLabel

protected String sqlCmdLabel
SQL statement label containing part up to the SQL command type.


sqlNormalizer

protected SqlNormalizer sqlNormalizer
SQL normalizer helper object.


split

protected Split split
Stopwatch split measuring the lifespan of the statement until it is closed across all executes.


stmt

private Statement stmt
Constructor Detail

SimonStatement

SimonStatement(Connection conn,
               Statement stmt,
               String prefix)
Class constructor, initializes Simons (lifespan, active) related to statement.

Parameters:
conn - database connection (simon impl.)
stmt - real statement
prefix - hierarchy prefix for JDBC Simons
Method Detail

close

public final void close()
                 throws SQLException
Closes real statement, stops lifespan Simon and decrease active Simon.

Specified by:
close in interface Statement
Throws:
SQLException - if real operation fails

getConnection

public final Connection getConnection()
Returns a connection object (simon impl.).

Specified by:
getConnection in interface Statement
Returns:
connection object

prepare

protected final Split prepare(String sql)
Called before each SQL command execution. Prepares (obtains and starts) Stopwatch Simon for measure SQL operation.

Parameters:
sql - sql command for execution
Returns:
simon stopwatch object or null if sql is null or empty

prepare

protected final Split prepare(List<String> sqls)
Called before each SQL command execution. Prepares (obtains and starts) Stopwatch Simon for measure bach SQL operations.

Parameters:
sqls - list of sql commands
Returns:
simon stopwatch object or null if sql is null or empty

startSplit

protected Split startSplit()
Starts the split for the SQL specific stopwatch, sets the note and returns the split. Used in the statment and prepared statement classes to measure runs of "execute" methods.

Returns:
split for the execution of the specific SQL command

finish

protected final void finish(Split split)
Called after each SQL command execution. Stops concrete SQL stopwatch (started in prepare(String)), also adds time to SQL command type Simon and sets human readable SQL cmd as note.

Parameters:
split - started Stopwatch split

executeQuery

public final ResultSet executeQuery(String sql)
                             throws SQLException
Measure and execute SQL operation.

Specified by:
executeQuery in interface Statement
Parameters:
sql - sql command
Returns:
database rows and columns
Throws:
SQLException - if real calls fails
See Also:
SimonResultSet

executeUpdate

public final int executeUpdate(String sql)
                        throws SQLException
Measure and execute SQL operation.

Specified by:
executeUpdate in interface Statement
Parameters:
sql - sql command
Returns:
count of updated rows
Throws:
SQLException - if real calls fails

executeUpdate

public final int executeUpdate(String sql,
                               int autoGeneratedKeys)
                        throws SQLException
Measure and execute SQL operation.

Specified by:
executeUpdate in interface Statement
Parameters:
sql - sql command
autoGeneratedKeys - autoGeneratedKeys flag
Returns:
count of updated rows
Throws:
SQLException - if real calls fails

executeUpdate

public final int executeUpdate(String sql,
                               int[] columnIndexes)
                        throws SQLException
Measure and execute SQL operation.

Specified by:
executeUpdate in interface Statement
Parameters:
sql - sql command
columnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row
Returns:
count of updated rows
Throws:
SQLException - if real calls fails

executeUpdate

public final int executeUpdate(String sql,
                               String[] columnNames)
                        throws SQLException
Measure and execute SQL operation.

Specified by:
executeUpdate in interface Statement
Parameters:
sql - sql command
columnNames - an array of column indexes indicating the columns that should be returned from the inserted row
Returns:
count of updated rows
Throws:
SQLException - if real calls fails

execute

public final boolean execute(String sql)
                      throws SQLException
Measure and execute SQL operation.

Specified by:
execute in interface Statement
Parameters:
sql - sql command
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException - if real calls fails

execute

public final boolean execute(String sql,
                             int autoGeneratedKeys)
                      throws SQLException
Measure and execute SQL operation.

Specified by:
execute in interface Statement
Parameters:
sql - sql command
autoGeneratedKeys - autoGeneratedKeys flag
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException - if real calls fails

execute

public final boolean execute(String sql,
                             int[] columnIndexes)
                      throws SQLException
Measure and execute SQL operation.

Specified by:
execute in interface Statement
Parameters:
sql - sql command
columnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException - if real calls fails

execute

public final boolean execute(String sql,
                             String[] columnNames)
                      throws SQLException
Measure and execute SQL operation.

Specified by:
execute in interface Statement
Parameters:
sql - sql command
columnNames - an array of column indexes indicating the columns that should be returned from the inserted row
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException - if real calls fails

addBatch

public final void addBatch(String s)
                    throws SQLException
Adds given SQL command into batch list of sql and also into real batch.

Specified by:
addBatch in interface Statement
Parameters:
s - sql command
Throws:
SQLException - if real calls fails

executeBatch

public int[] executeBatch()
                   throws SQLException
Measure and execute SQL operation.

Specified by:
executeBatch in interface Statement
Returns:
an array of update counts containing one element for each command in the batch.
Throws:
SQLException - if real calls fails

clearBatch

public void clearBatch()
                throws SQLException
Clears batch sql list and real batch too.

Specified by:
clearBatch in interface Statement
Throws:
SQLException - if real calls fails

getMaxFieldSize

public final int getMaxFieldSize()
                          throws SQLException

Specified by:
getMaxFieldSize in interface Statement
Throws:
SQLException

setMaxFieldSize

public final void setMaxFieldSize(int i)
                           throws SQLException

Specified by:
setMaxFieldSize in interface Statement
Throws:
SQLException

getMaxRows

public final int getMaxRows()
                     throws SQLException

Specified by:
getMaxRows in interface Statement
Throws:
SQLException

setMaxRows

public final void setMaxRows(int i)
                      throws SQLException

Specified by:
setMaxRows in interface Statement
Throws:
SQLException

setEscapeProcessing

public final void setEscapeProcessing(boolean b)
                               throws SQLException

Specified by:
setEscapeProcessing in interface Statement
Throws:
SQLException

getQueryTimeout

public final int getQueryTimeout()
                          throws SQLException

Specified by:
getQueryTimeout in interface Statement
Throws:
SQLException

setQueryTimeout

public final void setQueryTimeout(int i)
                           throws SQLException

Specified by:
setQueryTimeout in interface Statement
Throws:
SQLException

cancel

public final void cancel()
                  throws SQLException

Specified by:
cancel in interface Statement
Throws:
SQLException

getWarnings

public final SQLWarning getWarnings()
                             throws SQLException

Specified by:
getWarnings in interface Statement
Throws:
SQLException

clearWarnings

public final void clearWarnings()
                         throws SQLException

Specified by:
clearWarnings in interface Statement
Throws:
SQLException

setCursorName

public final void setCursorName(String s)
                         throws SQLException

Specified by:
setCursorName in interface Statement
Throws:
SQLException

getResultSet

public final ResultSet getResultSet()
                             throws SQLException

Specified by:
getResultSet in interface Statement
Throws:
SQLException

getUpdateCount

public final int getUpdateCount()
                         throws SQLException

Specified by:
getUpdateCount in interface Statement
Throws:
SQLException

getMoreResults

public final boolean getMoreResults()
                             throws SQLException

Specified by:
getMoreResults in interface Statement
Throws:
SQLException

setFetchDirection

public final void setFetchDirection(int i)
                             throws SQLException

Specified by:
setFetchDirection in interface Statement
Throws:
SQLException

getFetchDirection

public final int getFetchDirection()
                            throws SQLException

Specified by:
getFetchDirection in interface Statement
Throws:
SQLException

setFetchSize

public final void setFetchSize(int i)
                        throws SQLException

Specified by:
setFetchSize in interface Statement
Throws:
SQLException

getFetchSize

public final int getFetchSize()
                       throws SQLException

Specified by:
getFetchSize in interface Statement
Throws:
SQLException

getResultSetConcurrency

public final int getResultSetConcurrency()
                                  throws SQLException

Specified by:
getResultSetConcurrency in interface Statement
Throws:
SQLException

getResultSetType

public final int getResultSetType()
                           throws SQLException

Specified by:
getResultSetType in interface Statement
Throws:
SQLException

getMoreResults

public final boolean getMoreResults(int i)
                             throws SQLException

Specified by:
getMoreResults in interface Statement
Throws:
SQLException

getGeneratedKeys

public final ResultSet getGeneratedKeys()
                                 throws SQLException

Specified by:
getGeneratedKeys in interface Statement
Throws:
SQLException

getResultSetHoldability

public final int getResultSetHoldability()
                                  throws SQLException

Specified by:
getResultSetHoldability in interface Statement
Throws:
SQLException


Copyright © 2011. All Rights Reserved.