com.jolbox.bonecp
Class StatementHandle

java.lang.Object
  extended by com.jolbox.bonecp.StatementHandle
All Implemented Interfaces:
Statement, Wrapper
Direct Known Subclasses:
PreparedStatementHandle

public class StatementHandle
extends Object
implements Statement

Wrapper around JDBC Statement.

Version:
$Revision$
Author:
wallacew

Field Summary
protected  StringBuilder batchSQL
          for logging of addBatch.
protected  IStatementCache cache
          Cache pertaining to this statement.
protected  ConnectionHandle connectionHandle
          Handle to the connection holding this statement.
protected  ConnectionHook connectionHook
          Config setting.
protected  boolean enqueuedForClosure
          If true, this statement is being closed off by a separate thread.
 boolean inCache
          If true, this statement is in the cache.
protected  Statement internalStatement
          A handle to the actual statement.
protected static org.slf4j.Logger logger
          Class logger.
protected  AtomicBoolean logicallyClosed
          Set to true if the connection has been "closed".
protected  Map<Object,Object> logParams
          For logging purposes - stores parameters to be used for execution.
protected  boolean logStatementsEnabled
          If enabled, log all statements being executed.
 String openStackTrace
          Stack trace capture of where this statement was opened.
protected  long queryExecuteTimeLimit
          Config setting converted to nanoseconds.
protected  String sql
          SQL Statement used for this statement.
 
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
StatementHandle(Statement internalStatement, ConnectionHandle connectionHandle, boolean logStatementsEnabled)
          Constructor for empty statement (created via connection.createStatement)
StatementHandle(Statement internalStatement, String sql, IStatementCache cache, ConnectionHandle connectionHandle, String cacheKey, boolean logStatementsEnabled)
          Constructor to statement handle wrapper.
 
Method Summary
 void addBatch(String sql)
          
 void cancel()
          
protected  void checkClosed()
          Checks if the connection is marked as being logically open and throws an exception if not.
 void clearBatch()
          
protected  void clearCache()
          Clears out the cache of statements.
 void clearWarnings()
          
 void close()
           
protected  void closeStatement()
          Closes off the statement
 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)
          
 Connection getConnection()
          
 Object getDebugHandle()
          Returns the debugHandle field.
 int getFetchDirection()
          
 int getFetchSize()
          
 ResultSet getGeneratedKeys()
          
 Statement getInternalStatement()
          Returns the statement being wrapped around by this wrapper.
 int getMaxFieldSize()
          
 int getMaxRows()
          
 boolean getMoreResults()
          
 boolean getMoreResults(int current)
          
 String getOpenStackTrace()
          Returns the stack trace where this statement was first opened.
 int getQueryTimeout()
          
 ResultSet getResultSet()
          
 int getResultSetConcurrency()
          
 int getResultSetHoldability()
          
 int getResultSetType()
          
 int getUpdateCount()
          
 SQLWarning getWarnings()
          
 boolean isClosed()
          Returns true if statement is logically closed
 boolean isClosedOrEnqueuedForClosure()
          Return true if statement is closed or is enqueued for closure.
 boolean isEnqueuedForClosure()
          Returns the enqueuedForClosure field.
 boolean isPoolable()
           
 boolean isWrapperFor(Class<?> iface)
           
protected  void queryTimerEnd(String sql, long queryStartTime)
          Call the onQueryExecuteTimeLimitExceeded hook if necessary
protected  long queryTimerStart()
          Start off a timer if necessary
 void setCursorName(String name)
           
 void setDebugHandle(Object debugHandle)
          Sets a debugHandle, an object that is not used by the connection pool at all but may be set by an application to track this particular connection handle for any purpose it deems fit.
 void setEscapeProcessing(boolean enable)
          
 void setFetchDirection(int direction)
          
 void setFetchSize(int rows)
          
 void setInternalStatement(Statement internalStatement)
          Sets the internal statement used by this wrapper.
protected  void setLogicallyOpen()
          Marks this statement as being "open"
 void setMaxFieldSize(int max)
          
 void setMaxRows(int max)
          
 void setOpenStackTrace(String openStackTrace)
          Sets the stack trace where this statement was first opened.
 void setPoolable(boolean poolable)
           
 void setQueryTimeout(int seconds)
          
 String toString()
           
protected  boolean tryTransferOffer(StatementHandle e)
          Tries to move the item to a waiting consumer.
<T> T
unwrap(Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logicallyClosed

protected AtomicBoolean logicallyClosed
Set to true if the connection has been "closed".


internalStatement

protected Statement internalStatement
A handle to the actual statement.


sql

protected String sql
SQL Statement used for this statement.


cache

protected IStatementCache cache
Cache pertaining to this statement.


connectionHandle

protected ConnectionHandle connectionHandle
Handle to the connection holding this statement.


logStatementsEnabled

protected boolean logStatementsEnabled
If enabled, log all statements being executed.


inCache

public volatile boolean inCache
If true, this statement is in the cache.


openStackTrace

public String openStackTrace
Stack trace capture of where this statement was opened.


logger

protected static org.slf4j.Logger logger
Class logger.


queryExecuteTimeLimit

protected long queryExecuteTimeLimit
Config setting converted to nanoseconds.


connectionHook

protected ConnectionHook connectionHook
Config setting.


enqueuedForClosure

protected volatile boolean enqueuedForClosure
If true, this statement is being closed off by a separate thread.


logParams

protected Map<Object,Object> logParams
For logging purposes - stores parameters to be used for execution.


batchSQL

protected StringBuilder batchSQL
for logging of addBatch.

Constructor Detail

StatementHandle

public StatementHandle(Statement internalStatement,
                       String sql,
                       IStatementCache cache,
                       ConnectionHandle connectionHandle,
                       String cacheKey,
                       boolean logStatementsEnabled)
Constructor to statement handle wrapper.

Parameters:
internalStatement - handle to actual statement instance.
sql - statement used for this handle.
cache - Cache handle
connectionHandle - Handle to the connection
cacheKey -
logStatementsEnabled - set to true to log statements.

StatementHandle

public StatementHandle(Statement internalStatement,
                       ConnectionHandle connectionHandle,
                       boolean logStatementsEnabled)
Constructor for empty statement (created via connection.createStatement)

Parameters:
internalStatement - wrapper to statement
connectionHandle - Handle to the connection that this statement is tied to.
logStatementsEnabled - set to true to enable sql logging.
Method Detail

closeStatement

protected void closeStatement()
                       throws SQLException
Closes off the statement

Throws:
SQLException

tryTransferOffer

protected boolean tryTransferOffer(StatementHandle e)
Tries to move the item to a waiting consumer. If there's no consumer waiting, offers the item to the queue if there's space available.

Parameters:
e - Item to transfer
Returns:
true if the item was transferred or placed on the queue, false if there are no waiting clients and there's no more space on the queue.

close

public void close()
           throws SQLException
Specified by:
close in interface Statement
Throws:
SQLException

addBatch

public void addBatch(String sql)
              throws SQLException

Specified by:
addBatch in interface Statement
Throws:
SQLException
See Also:
Statement.addBatch(java.lang.String)

checkClosed

protected void checkClosed()
                    throws SQLException
Checks if the connection is marked as being logically open and throws an exception if not.

Throws:
SQLException - if connection is marked as logically closed.

cancel

public void cancel()
            throws SQLException

Specified by:
cancel in interface Statement
Throws:
SQLException
See Also:
Statement.cancel()

clearBatch

public void clearBatch()
                throws SQLException

Specified by:
clearBatch in interface Statement
Throws:
SQLException
See Also:
Statement.clearBatch()

clearWarnings

public void clearWarnings()
                   throws SQLException

Specified by:
clearWarnings in interface Statement
Throws:
SQLException
See Also:
Statement.clearWarnings()

execute

public boolean execute(String sql)
                throws SQLException

Specified by:
execute in interface Statement
Throws:
SQLException
See Also:
Statement.execute(java.lang.String)

queryTimerEnd

protected void queryTimerEnd(String sql,
                             long queryStartTime)
Call the onQueryExecuteTimeLimitExceeded hook if necessary

Parameters:
sql - sql statement that took too long
queryStartTime - time when query was started.

execute

public boolean execute(String sql,
                       int autoGeneratedKeys)
                throws SQLException

Specified by:
execute in interface Statement
Throws:
SQLException
See Also:
Statement.execute(java.lang.String, int)

queryTimerStart

protected long queryTimerStart()
Start off a timer if necessary

Returns:
Start time

execute

public boolean execute(String sql,
                       int[] columnIndexes)
                throws SQLException

Specified by:
execute in interface Statement
Throws:
SQLException
See Also:
Statement.execute(java.lang.String, int[])

execute

public boolean execute(String sql,
                       String[] columnNames)
                throws SQLException

Specified by:
execute in interface Statement
Throws:
SQLException
See Also:
Statement.execute(java.lang.String, java.lang.String[])

executeBatch

public int[] executeBatch()
                   throws SQLException

Specified by:
executeBatch in interface Statement
Throws:
SQLException
See Also:
Statement.executeBatch()

executeQuery

public ResultSet executeQuery(String sql)
                       throws SQLException

Specified by:
executeQuery in interface Statement
Throws:
SQLException
See Also:
Statement.executeQuery(java.lang.String)

executeUpdate

public int executeUpdate(String sql)
                  throws SQLException

Specified by:
executeUpdate in interface Statement
Throws:
SQLException
See Also:
Statement.executeUpdate(java.lang.String)

executeUpdate

public int executeUpdate(String sql,
                         int autoGeneratedKeys)
                  throws SQLException

Specified by:
executeUpdate in interface Statement
Throws:
SQLException
See Also:
Statement.executeUpdate(java.lang.String, int)

executeUpdate

public int executeUpdate(String sql,
                         int[] columnIndexes)
                  throws SQLException

Specified by:
executeUpdate in interface Statement
Throws:
SQLException
See Also:
Statement.executeUpdate(java.lang.String, int[])

executeUpdate

public int executeUpdate(String sql,
                         String[] columnNames)
                  throws SQLException

Specified by:
executeUpdate in interface Statement
Throws:
SQLException
See Also:
Statement.executeUpdate(java.lang.String, java.lang.String[])

getConnection

public Connection getConnection()
                         throws SQLException

Specified by:
getConnection in interface Statement
Throws:
SQLException
See Also:
Statement.getConnection()

getFetchDirection

public int getFetchDirection()
                      throws SQLException

Specified by:
getFetchDirection in interface Statement
Throws:
SQLException
See Also:
Statement.getFetchDirection()

getFetchSize

public int getFetchSize()
                 throws SQLException

Specified by:
getFetchSize in interface Statement
Throws:
SQLException
See Also:
Statement.getFetchSize()

getGeneratedKeys

public ResultSet getGeneratedKeys()
                           throws SQLException

Specified by:
getGeneratedKeys in interface Statement
Throws:
SQLException
See Also:
Statement.getGeneratedKeys()

getMaxFieldSize

public int getMaxFieldSize()
                    throws SQLException

Specified by:
getMaxFieldSize in interface Statement
Throws:
SQLException
See Also:
Statement.getMaxFieldSize()

getMaxRows

public int getMaxRows()
               throws SQLException

Specified by:
getMaxRows in interface Statement
Throws:
SQLException
See Also:
Statement.getMaxRows()

getMoreResults

public boolean getMoreResults()
                       throws SQLException

Specified by:
getMoreResults in interface Statement
Throws:
SQLException
See Also:
Statement.getMoreResults()

getMoreResults

public boolean getMoreResults(int current)
                       throws SQLException

Specified by:
getMoreResults in interface Statement
Throws:
SQLException
See Also:
Statement.getMoreResults(int)

getQueryTimeout

public int getQueryTimeout()
                    throws SQLException

Specified by:
getQueryTimeout in interface Statement
Throws:
SQLException
See Also:
Statement.getQueryTimeout()

getResultSet

public ResultSet getResultSet()
                       throws SQLException

Specified by:
getResultSet in interface Statement
Throws:
SQLException
See Also:
Statement.getResultSet()

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws SQLException

Specified by:
getResultSetConcurrency in interface Statement
Throws:
SQLException
See Also:
Statement.getResultSetConcurrency()

getResultSetHoldability

public int getResultSetHoldability()
                            throws SQLException

Specified by:
getResultSetHoldability in interface Statement
Throws:
SQLException
See Also:
Statement.getResultSetHoldability()

getResultSetType

public int getResultSetType()
                     throws SQLException

Specified by:
getResultSetType in interface Statement
Throws:
SQLException
See Also:
Statement.getResultSetType()

getUpdateCount

public int getUpdateCount()
                   throws SQLException

Specified by:
getUpdateCount in interface Statement
Throws:
SQLException
See Also:
Statement.getUpdateCount()

getWarnings

public SQLWarning getWarnings()
                       throws SQLException

Specified by:
getWarnings in interface Statement
Throws:
SQLException
See Also:
Statement.getWarnings()

isClosed

public boolean isClosed()
Returns true if statement is logically closed

Specified by:
isClosed in interface Statement
Returns:
True if handle is closed

setPoolable

public void setPoolable(boolean poolable)
                 throws SQLException
Specified by:
setPoolable in interface Statement
Throws:
SQLException

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
                     throws SQLException
Specified by:
isWrapperFor in interface Wrapper
Throws:
SQLException

unwrap

public <T> T unwrap(Class<T> iface)
         throws SQLException
Specified by:
unwrap in interface Wrapper
Throws:
SQLException

isPoolable

public boolean isPoolable()
                   throws SQLException
Specified by:
isPoolable in interface Statement
Throws:
SQLException

setCursorName

public void setCursorName(String name)
                   throws SQLException
Specified by:
setCursorName in interface Statement
Throws:
SQLException

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws SQLException

Specified by:
setEscapeProcessing in interface Statement
Throws:
SQLException
See Also:
Statement.setEscapeProcessing(boolean)

setFetchDirection

public void setFetchDirection(int direction)
                       throws SQLException

Specified by:
setFetchDirection in interface Statement
Throws:
SQLException
See Also:
Statement.setFetchDirection(int)

setFetchSize

public void setFetchSize(int rows)
                  throws SQLException

Specified by:
setFetchSize in interface Statement
Throws:
SQLException
See Also:
Statement.setFetchSize(int)

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws SQLException

Specified by:
setMaxFieldSize in interface Statement
Throws:
SQLException
See Also:
Statement.setMaxFieldSize(int)

setMaxRows

public void setMaxRows(int max)
                throws SQLException

Specified by:
setMaxRows in interface Statement
Throws:
SQLException
See Also:
Statement.setMaxRows(int)

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws SQLException

Specified by:
setQueryTimeout in interface Statement
Throws:
SQLException
See Also:
Statement.setQueryTimeout(int)

clearCache

protected void clearCache()
Clears out the cache of statements.


setLogicallyOpen

protected void setLogicallyOpen()
Marks this statement as being "open"


toString

public String toString()
Overrides:
toString in class Object

getOpenStackTrace

public String getOpenStackTrace()
Returns the stack trace where this statement was first opened.

Returns:
the openStackTrace

setOpenStackTrace

public void setOpenStackTrace(String openStackTrace)
Sets the stack trace where this statement was first opened.

Parameters:
openStackTrace - the openStackTrace to set

getInternalStatement

public Statement getInternalStatement()
Returns the statement being wrapped around by this wrapper.

Returns:
the internalStatement being used.

setInternalStatement

public void setInternalStatement(Statement internalStatement)
Sets the internal statement used by this wrapper.

Parameters:
internalStatement - the internalStatement to set

setDebugHandle

public void setDebugHandle(Object debugHandle)
Sets a debugHandle, an object that is not used by the connection pool at all but may be set by an application to track this particular connection handle for any purpose it deems fit.

Parameters:
debugHandle - any object.

getDebugHandle

public Object getDebugHandle()
Returns the debugHandle field.

Returns:
debugHandle

isEnqueuedForClosure

public boolean isEnqueuedForClosure()
Returns the enqueuedForClosure field.

Returns:
enqueuedForClosure

isClosedOrEnqueuedForClosure

public boolean isClosedOrEnqueuedForClosure()
Return true if statement is closed or is enqueued for closure.

Returns:
true if this statement is closed or about to close.


Copyright © 2009-2011 JolBox. All Rights Reserved.