org.logicalcobwebs.proxool
Class ProxyFactory

java.lang.Object
  extended by org.logicalcobwebs.proxool.ProxyFactory

 class ProxyFactory
extends java.lang.Object

A central place to build proxy objects. It will also provide the original object given a proxy.

Since:
Proxool 0.5
Version:
$Revision: 1.31 $, $Date: 2005/09/26 09:59:22 $
Author:
Bill Horsman (bill@logicalcobwebs.co.uk), $Author: billhorsman $ (current maintainer)

Field Summary
private static java.util.Map interfaceMap
           
private static Log LOG
           
 
Constructor Summary
ProxyFactory()
           
 
Method Summary
protected static java.sql.DatabaseMetaData getDatabaseMetaData(java.sql.DatabaseMetaData databaseMetaData, java.sql.Connection wrappedConnection)
          Create a new DatabaseMetaData from a connection
protected static java.sql.Connection getDelegateConnection(java.sql.Connection connection)
          Gets the real Connection that we got from the delegate driver.
protected static java.sql.Statement getDelegateStatement(java.sql.Statement statement)
          Gets the real Statement that we got from the delegate driver.
private static java.lang.Class[] getInterfaces(java.lang.Class clazz, ConnectionPoolDefinitionIF cpd)
          Get all the interfaces that a class implements.
private static java.lang.Object getProxy(java.lang.Object delegate, Callback callback, ConnectionPoolDefinitionIF def)
           
protected static java.sql.Statement getStatement(java.sql.Statement delegate, ConnectionPool connectionPool, ProxyConnectionIF proxyConnection, java.lang.String sqlStatement)
          Proxies a statement inside a ProxyStatement.
static WrappedConnection getWrappedConnection(java.sql.Connection connection)
          Get the WrappedConnection behind this proxy connection.
protected static java.sql.Connection getWrappedConnection(ProxyConnection proxyConnection)
          Wraps up a proxyConnection inside a WrappedConnection and then proxies it as a simple Connection.
private static void traverseInterfacesRecursively(java.util.Set interfaces, java.lang.Class clazz)
          Recursively looks at all interfaces for a class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Log LOG

interfaceMap

private static java.util.Map interfaceMap
Constructor Detail

ProxyFactory

ProxyFactory()
Method Detail

getWrappedConnection

protected static java.sql.Connection getWrappedConnection(ProxyConnection proxyConnection)
Wraps up a proxyConnection inside a WrappedConnection and then proxies it as a simple Connection. You should call this immediately before the connection is served to the user. The WrappedConnection is disposable (it is thrown away when the connection is returned to the pool).

Parameters:
proxyConnection - the pooled connection we are wrapping up
Returns:
the Connection for use

getStatement

protected static java.sql.Statement getStatement(java.sql.Statement delegate,
                                                 ConnectionPool connectionPool,
                                                 ProxyConnectionIF proxyConnection,
                                                 java.lang.String sqlStatement)
Proxies a statement inside a ProxyStatement.

Parameters:
delegate - the real statement
connectionPool - the pool it belongs to
proxyConnection - the connection it was built from
sqlStatement - Can be null?
Returns:
the proxied statement

getDatabaseMetaData

protected static java.sql.DatabaseMetaData getDatabaseMetaData(java.sql.DatabaseMetaData databaseMetaData,
                                                               java.sql.Connection wrappedConnection)
Create a new DatabaseMetaData from a connection

Parameters:
databaseMetaData - the meta data we use to delegate all calls to (except getConnection())
wrappedConnection - the connection we return if asked for the connection
Returns:
databaseMetaData

getProxy

private static java.lang.Object getProxy(java.lang.Object delegate,
                                         Callback callback,
                                         ConnectionPoolDefinitionIF def)

getDelegateStatement

protected static java.sql.Statement getDelegateStatement(java.sql.Statement statement)
Gets the real Statement that we got from the delegate driver. This is no longer necessary and only provided for backwards compatability.

Parameters:
statement - proxy statement
Returns:
delegate statement
See Also:
ProxoolFacade.getDelegateStatement(java.sql.Statement)

getDelegateConnection

protected static java.sql.Connection getDelegateConnection(java.sql.Connection connection)
Gets the real Connection that we got from the delegate driver. This is no longer necessary and only provided for backwards compatability.

Parameters:
connection - proxy connection
Returns:
deletgate connection
See Also:
ProxoolFacade.getDelegateConnection(java.sql.Connection)

getInterfaces

private static java.lang.Class[] getInterfaces(java.lang.Class clazz,
                                               ConnectionPoolDefinitionIF cpd)
Get all the interfaces that a class implements. Drills down into super interfaces too and super classes too. The results are cached so it's very fast second time round.

Parameters:
clazz - the class to examine.
Returns:
an array of classes (all interfaces) that this class implements.

traverseInterfacesRecursively

private static void traverseInterfacesRecursively(java.util.Set interfaces,
                                                  java.lang.Class clazz)
Recursively looks at all interfaces for a class. Also looks at interfaces implemented by the super class (and its super class, etc.) Quite a lot of processing involved so you shouldn't call it too often.

Parameters:
interfaces - this set is populated with all interfaceMap it finds
clazz - the base class to analyze

getWrappedConnection

public static WrappedConnection getWrappedConnection(java.sql.Connection connection)
Get the WrappedConnection behind this proxy connection.

Parameters:
connection - the connection that was served
Returns:
the wrapped connection or null if it couldn't be found