Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Firebird Open Source J2ee connector - jdbc driver
   * Distributable under LGPL license.
   * You may obtain a copy of the License at
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * LGPL License for more details.
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  * All rights reserved.
 package org.firebirdsql.pool;
 import static org.firebirdsql.ds.ReflectionHelper.findMethod;
 import static org.firebirdsql.ds.ReflectionHelper.getAllInterfaces;
Dynamic proxy handler that together with PooledConnectionHandler ensure that statements will be closed before connection is returned to the pool.

Roman Rokytskyy
 public class StatementHandler implements InvocationHandler {
     private static final Method STATEMENT_CLOSE = 
         findMethod(Statement.class"close"new Class[0]);
     private Statement wrappedObject;
     private Statement proxy;
Create instance of this class for the specified connection handler and

connectionHandler instance of PooledConnectionHandler that is responsible for a connection that created a statement to wrap.
wrappedObject instance of java.sql.Statement to wrap.
     public StatementHandler(PooledConnectionHandler connectionHandler
             Statement wrappedObject
         this. = connectionHandler;
         this. = wrappedObject;
          = (Statement)Proxy.newProxyInstance(

Get dynamic proxy instant wrapping the statement.

instance of java.sql.Statement.
     public Statement getProxy() {
         return ;
Get original statement that was wrapped.

instance of java.sql.Statement.
     public Statement getWrappedObject() {
         return ;
Invoke a specified method with the specified arguments on the specified proxy. This method checks if java.sql.Statement.close() is called and de-registers the statement from automatic close on connection close.

proxy proxy, on which the method was called.
method method that was invoked.
args arguments that were passed to the method.
object that was returned by the method.
java.lang.Throwable throwable that was thrown during method processing.
     public Object invoke(Object proxyMethod methodObject[] args)
            throws Throwable {
        if (.equals(method)) {
        try {
            Object result = method.invoke(args);
            if (result instanceof ResultSet) {
                ResultSetHandler handler = new ResultSetHandler(
                        (Statementproxy, (ResultSetresult);
                result = Proxy.newProxyInstance(getClass().getClassLoader(),
                        new Class[] { ResultSet.class}, handler);
            return result;
        } catch(InvocationTargetException ex) {
            throw ex.getTargetException();
New to GrepCode? Check out our FAQ X