org.logicalcobwebs.proxool
Class AbstractProxyStatement

java.lang.Object
  extended by org.logicalcobwebs.proxool.AbstractProxyStatement
Direct Known Subclasses:
ProxyStatement

abstract class AbstractProxyStatement
extends java.lang.Object

Contains most of the functionality that we require to manipilate the statement. The subclass of this defines how we delegate to the real statement.

Since:
Proxool 0.7
Version:
$Revision: 1.20 $, $Date: 2005/10/07 08:25:15 $
Author:
bill, $Author: billhorsman $ (current maintainer)

Field Summary
private  ConnectionPool connectionPool
           
private static java.text.DateFormat DATE_FORMAT
           
private static Log LOG
           
private  java.util.Map parameters
           
private  ProxyConnectionIF proxyConnection
           
private  java.lang.StringBuffer sqlLog
           
private  java.lang.String sqlStatement
           
private  java.sql.Statement statement
           
 
Constructor Summary
AbstractProxyStatement(java.sql.Statement statement, ConnectionPool connectionPool, ProxyConnectionIF proxyConnection, java.lang.String sqlStatement)
           
 
Method Summary
protected  void appendToSqlLog()
          Get the parameters that have been built up and use them to fill in any parameters withing the sqlStatement and produce a log.
 void close()
          Close the statement and tell the ProxyConnection that it did so.
 boolean equals(java.lang.Object obj)
          Whether the delegate statements are the same
protected  ConnectionPool getConnectionPool()
          The connection pool we are using
protected static java.lang.String getDateAsString(java.util.Date date)
           
 java.sql.Statement getDelegateStatement()
          Gets the real Statement that we got from the delegate driver
protected  java.sql.Statement getStatement()
          The real, delegate statement
protected  boolean isTrace()
           
protected  void putParameter(int index, java.lang.Object value)
          Add a parameter so that we can show its value when tracing
protected  void setSqlStatementIfNull(java.lang.String sqlStatement)
          Sets sqlStatement if it isn't already set
protected  void startExecute()
           
protected  boolean testException(java.lang.Throwable t)
          Check to see whether an exception is a fatal one.
protected  void trace(long startTime, java.lang.Exception exception)
          Trace the call that was just made
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Log LOG

DATE_FORMAT

private static final java.text.DateFormat DATE_FORMAT

statement

private java.sql.Statement statement

connectionPool

private ConnectionPool connectionPool

proxyConnection

private ProxyConnectionIF proxyConnection

parameters

private java.util.Map parameters

sqlStatement

private java.lang.String sqlStatement

sqlLog

private java.lang.StringBuffer sqlLog
Constructor Detail

AbstractProxyStatement

public AbstractProxyStatement(java.sql.Statement statement,
                              ConnectionPool connectionPool,
                              ProxyConnectionIF proxyConnection,
                              java.lang.String sqlStatement)
Parameters:
statement - the real statement that we will delegate to
connectionPool - the connection pool that we are using
proxyConnection - the connection that was used to create the statement
sqlStatement - the SQL statement that was used to create this statement (optional, can be null) so that we can use if for tracing.
Method Detail

testException

protected boolean testException(java.lang.Throwable t)
Check to see whether an exception is a fatal one. If it is, then throw the connection away (and it won't be made available again)

Parameters:
t - the exception to test

getDelegateStatement

public java.sql.Statement getDelegateStatement()
Gets the real Statement that we got from the delegate driver

Returns:
delegate statement

getConnectionPool

protected ConnectionPool getConnectionPool()
The connection pool we are using

Returns:
connectionPool

getStatement

protected java.sql.Statement getStatement()
The real, delegate statement

Returns:
statement

close

public void close()
           throws java.sql.SQLException
Close the statement and tell the ProxyConnection that it did so.

Throws:
java.sql.SQLException - if it couldn't be closed
See Also:
ProxyConnectionIF.registerClosedStatement(java.sql.Statement)

equals

public boolean equals(java.lang.Object obj)
Whether the delegate statements are the same

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

putParameter

protected void putParameter(int index,
                            java.lang.Object value)
Add a parameter so that we can show its value when tracing

Parameters:
index - within the procedure
value - an object describing its value

trace

protected void trace(long startTime,
                     java.lang.Exception exception)
              throws java.sql.SQLException
Trace the call that was just made

Parameters:
startTime - so we can log how long it took
exception - if anything went wrong during execution
Throws:
java.sql.SQLException - if the onExecute method threw one.

startExecute

protected void startExecute()

appendToSqlLog

protected void appendToSqlLog()
Get the parameters that have been built up and use them to fill in any parameters withing the sqlStatement and produce a log. If the log already exists (for instance, if a batch is being peformed) then it is appended to the end.


isTrace

protected boolean isTrace()

setSqlStatementIfNull

protected void setSqlStatementIfNull(java.lang.String sqlStatement)
Sets sqlStatement if it isn't already set

Parameters:
sqlStatement - the statement we are sending the database

getDateAsString

protected static java.lang.String getDateAsString(java.util.Date date)