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 http://www.gnu.org/copyleft/lgpl.html
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * 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.jca;
 
 import static org.firebirdsql.ds.ReflectionHelper.findMethod;
 import static org.firebirdsql.ds.ReflectionHelper.getAllInterfaces;
 
 
 
Simple Connection wrapper returned by FBXAConnection.

Deprecated:
Author(s):
Ludovic Orban
 
 public class FBXAConnectionHandle implements InvocationHandler {
     
     private final static Method CONNECTION_CLOSE = findMethod(
         Connection.class"close"new Class[0]);
 
     private final static Method CONNECTION_IS_CLOSED = findMethod(
         Connection.class"isClosed"new Class[0]);
 
     
     private AbstractConnection connection;
     private XAConnection owner;
     
     private Connection proxy;
     
     private SQLException closeStackTrace;

    
Construct instance of this class. This method constructs new proxy that implements java.sql.Connection interface and uses newly constructed object as invocation handler.

Parameters:
connection connection to wrap.
owner instance of javax.sql.XAConnection that owns this connection instance.
Throws:
java.sql.SQLException if something went wrong during initialization.
 
     public 
         FBXAConnectionHandle(AbstractConnection connectionXAConnection owner
             throws SQLException
         {
             
             this. = connection;
             this. = owner;
             
             Class[] implementedInterfaces = 
                 getAllInterfaces(connection.getClass());
 
              = (Connection)Proxy.newProxyInstance(
                 FirebirdConnection.class.getClassLoader(),
                 implementedInterfaces,
                 this);
         }
    
    
Get proxy implementing java.sql.Connection interface and using this instance as invocation handler.

Returns:
instance of java.sql.Connection.
 
     public Connection getProxy() {
         return ;
     }
    
    
Get manager of this connection wrapper.

Returns:
instance of javax.sql.XAConnection.
    public XAConnection getXAConnection() {
        return ;
    }
    
    // Connection overridings
    
    public void handleConnectionClose() throws SQLException {
         = null;
         = new SQLException("Close trace.");
    }

    
Invoke method on a specified proxy. Here we check if method is a method java.sql.Connection.prepareStatement(java.lang.String). If yes, we check if there is already a prepared statement for the wrapped connection or wrap a newly created one.

Parameters:
proxy proxy on which method is invoked.
method instance of java.lang.reflect.Method describing method being invoked.
args array with arguments.
Returns:
result of method invokation.
Throws:
java.lang.Throwable if invoked method threw an exception.
    public Object invoke(Object proxyMethod methodObject[] args
        throws Throwable 
    {
        try {
            
            // if object is closed, throw an exception
            if ( == null) { 
                // check whether Connection.isClose() method is called first
                if (.equals(method))
                    return .;
                
                FBSQLException ex = new FBSQLException(
                    "Connection " + this + " was closed. " +
                            "See the attached exception to find the place " +
                            "where it was closed");
                ex.setNextException();
                throw ex;
            }
            
            if (method.equals()) {
                handleConnectionClose();
                return .;
            } else
                return method.invoke(args);
        } catch(InvocationTargetException ex) {
            throw ex.getTargetException();
        } catch(SQLException ex) {
            throw ex;
        }
    }
New to GrepCode? Check out our FAQ X