org.logicalcobwebs.proxool
Class ProxyStatement

java.lang.Object
  extended byorg.logicalcobwebs.proxool.AbstractProxyStatement
      extended byorg.logicalcobwebs.proxool.ProxyStatement
All Implemented Interfaces:
Callback, InvocationHandler, MethodInterceptor

class ProxyStatement
extends AbstractProxyStatement
implements InvocationHandler, MethodInterceptor

Delegates to Statement for all calls. But also, for all execute methods, it checks the SQLException and compares it to the fatalSqlException list in the ConnectionPoolDefinition. If it detects a fatal exception it will destroy the Connection so that it isn't used again.

Version:
$Revision: 1.25 $, $Date: 2003/12/12 19:29:47 $
Author:
billhorsman, $Author: billhorsman $ (current maintainer)

Field Summary
private static java.lang.String ADD_BATCH_METHOD
           
private static java.lang.String CLOSE_METHOD
           
private static java.lang.String EQUALS_METHOD
           
private static java.lang.String EXECUTE_BATCH_METHOD
           
private static java.lang.String EXECUTE_FRAGMENT
           
private static Log LOG
           
private static java.lang.String SET_NULL_METHOD
           
private static java.lang.String SET_PREFIX
           
 
Constructor Summary
ProxyStatement(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
 java.sql.Statement getDelegateStatement()
          Gets the real Statement that we got from the delegate driver
protected  java.sql.Statement getStatement()
          The real, delegate statement
 java.lang.Object intercept(java.lang.Object obj, java.lang.reflect.Method method, java.lang.Object[] args, MethodProxy proxy)
          All generated proxied methods call this method instead of the original method.
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
           
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  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

EXECUTE_FRAGMENT

private static final java.lang.String EXECUTE_FRAGMENT
See Also:
Constant Field Values

EXECUTE_BATCH_METHOD

private static final java.lang.String EXECUTE_BATCH_METHOD
See Also:
Constant Field Values

ADD_BATCH_METHOD

private static final java.lang.String ADD_BATCH_METHOD
See Also:
Constant Field Values

EQUALS_METHOD

private static final java.lang.String EQUALS_METHOD
See Also:
Constant Field Values

CLOSE_METHOD

private static final java.lang.String CLOSE_METHOD
See Also:
Constant Field Values

SET_NULL_METHOD

private static final java.lang.String SET_NULL_METHOD
See Also:
Constant Field Values

SET_PREFIX

private static final java.lang.String SET_PREFIX
See Also:
Constant Field Values
Constructor Detail

ProxyStatement

public ProxyStatement(java.sql.Statement statement,
                      ConnectionPool connectionPool,
                      ProxyConnectionIF proxyConnection,
                      java.lang.String sqlStatement)
Method Detail

intercept

public java.lang.Object intercept(java.lang.Object obj,
                                  java.lang.reflect.Method method,
                                  java.lang.Object[] args,
                                  MethodProxy proxy)
                           throws java.lang.Throwable
Description copied from interface: MethodInterceptor
All generated proxied methods call this method instead of the original method. The original method may either be invoked by normal reflection using the Method object, or by using the MethodProxy (faster).

Specified by:
intercept in interface MethodInterceptor
Parameters:
obj - "this", the enhanced object
method - intercepted Method
args - argument array; primitive types are wrapped
proxy - used to invoke super (non-intercepted method); may be called as many times as needed
Returns:
any value compatible with the signature of the proxied method. Method returning void will ignore this value.
Throws:
java.lang.Throwable - any exception may be thrown; if so, super method will not be invoked
See Also:
MethodProxy

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
java.lang.Throwable
See Also:
java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object)

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

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.

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