[Proxool-cvs] proxool/src/java/org/logicalcobwebs/proxool ProxyFactory.java,1.30,1.31
UNMAINTAINED!
Brought to you by:
billhorsman
From: <bil...@us...> - 2005-09-26 09:59:32
|
Update of /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11135/src/java/org/logicalcobwebs/proxool Modified Files: ProxyFactory.java Log Message: Explicitly use the ProxyFactory class loader when using Cglib's Enhancer to avoid class loading issues. Index: ProxyFactory.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxyFactory.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** ProxyFactory.java 4 May 2005 16:31:41 -0000 1.30 --- ProxyFactory.java 26 Sep 2005 09:59:22 -0000 1.31 *************** *** 8,11 **** --- 8,12 ---- import org.logicalcobwebs.cglib.proxy.Enhancer; import org.logicalcobwebs.cglib.proxy.Factory; + import org.logicalcobwebs.cglib.proxy.Callback; import org.logicalcobwebs.logging.Log; import org.logicalcobwebs.logging.LogFactory; *************** *** 45,66 **** */ protected static Connection getWrappedConnection(ProxyConnection proxyConnection) { ! final WrappedConnection wrappedConnection = new WrappedConnection(proxyConnection); ! /* ! Object delegate = Proxy.newProxyInstance( ! proxyConnection.getConnection().getClass().getClassLoader(), ! getInterfaces(proxyConnection.getConnection().getClass(), proxyConnection.getConnectionPool()), ! wrappedConnection); ! */ ! /* ! Object delegate = Enhancer.create( ! proxyConnection.getConnection().getClass(), ! getInterfaces(proxyConnection.getConnection().getClass(), proxyConnection.getConnectionPool()), ! wrappedConnection); ! */ ! Object delegate = Enhancer.create( ! null, ! getInterfaces(proxyConnection.getConnection().getClass(), proxyConnection.getDefinition()), ! wrappedConnection); ! return (Connection) delegate; } --- 46,80 ---- */ protected static Connection getWrappedConnection(ProxyConnection proxyConnection) { ! return (Connection) getProxy(proxyConnection.getConnection(), new WrappedConnection(proxyConnection), proxyConnection.getDefinition()); ! } ! ! /** ! * Proxies a statement inside a {@link ProxyStatement}. ! * @param delegate the real statement ! * @param connectionPool the pool it belongs to ! * @param proxyConnection the connection it was built from ! * @param sqlStatement Can be null? ! * @return the proxied statement ! */ ! protected static Statement getStatement(Statement delegate, ConnectionPool connectionPool, ProxyConnectionIF proxyConnection, String sqlStatement) { ! return (Statement) getProxy(delegate, new ProxyStatement(delegate, connectionPool, proxyConnection, sqlStatement), proxyConnection.getDefinition()); ! } ! ! /** ! * Create a new DatabaseMetaData from a connection ! * @param databaseMetaData the meta data we use to delegate all calls to (except getConnection()) ! * @param wrappedConnection the connection we return if asked for the connection ! * @return databaseMetaData ! */ ! protected static DatabaseMetaData getDatabaseMetaData(DatabaseMetaData databaseMetaData, Connection wrappedConnection) { ! return (DatabaseMetaData) getProxy(databaseMetaData, new ProxyDatabaseMetaData(databaseMetaData, wrappedConnection), null); ! } ! ! private static Object getProxy(Object delegate, Callback callback, ConnectionPoolDefinitionIF def) { ! Enhancer e = new Enhancer(); ! e.setInterfaces(getInterfaces(delegate.getClass(), def)); ! e.setCallback(callback); ! e.setClassLoader(ProxyFactory.class.getClassLoader()); ! return e.create(); } *************** *** 74,80 **** protected static Statement getDelegateStatement(Statement statement) { Statement ds = statement; - /* - ProxyStatement ps = (ProxyStatement) Proxy.getInvocationHandler(statement); - */ ProxyStatement ps = (ProxyStatement) ((Factory)statement).getCallback(0); ds = ps.getDelegateStatement(); --- 88,91 ---- *************** *** 90,120 **** */ protected static Connection getDelegateConnection(Connection connection) { - /* - WrappedConnection wc = (WrappedConnection) Proxy.getInvocationHandler(connection); - */ WrappedConnection wc = (WrappedConnection) ((Factory)connection).getCallback(0); return wc.getProxyConnection().getConnection(); } - protected static Statement getStatement(Statement delegate, ConnectionPool connectionPool, ProxyConnectionIF proxyConnection, String sqlStatement) { - Object o = Enhancer.create( - null, - getInterfaces(delegate.getClass(), proxyConnection.getDefinition()), - new ProxyStatement(delegate, connectionPool, proxyConnection, sqlStatement)); - /* - Object o = Enhancer.create( - delegate.getClass(), - getInterfaces(delegate.getClass(), connectionPool), - new ProxyStatement(delegate, connectionPool, proxyConnection, sqlStatement)); - */ - return (Statement) o; - /* - return (Statement) Proxy.newProxyInstance( - delegate.getClass().getClassLoader(), - getInterfaces(delegate.getClass(), connectionPool), - new ProxyStatement(delegate, connectionPool, proxyConnection, sqlStatement)); - */ - } - /** * Get all the interfaces that a class implements. Drills down into super interfaces too --- 101,108 ---- *************** *** 244,274 **** /** - * Create a new DatabaseMetaData from a connection - * @param databaseMetaData the meta data we use to delegate all calls to (except getConnection()) - * @param wrappedConnection the connection we return if asked for the connection - * @return databaseMetaData - */ - protected static DatabaseMetaData getDatabaseMetaData(DatabaseMetaData databaseMetaData, Connection wrappedConnection) { - /* - return (DatabaseMetaData) Proxy.newProxyInstance( - DatabaseMetaData.class.getClassLoader(), - new Class[]{DatabaseMetaData.class}, - new ProxyDatabaseMetaData(connection, wrappedConnection) - ); - */ - ProxyDatabaseMetaData proxyDatabaseMetaData = new ProxyDatabaseMetaData(databaseMetaData, wrappedConnection); - Object delegate = Enhancer.create( - null, - getInterfaces(databaseMetaData.getClass(), null), - proxyDatabaseMetaData); - /* - Object delegate = Enhancer.create( - databaseMetaData.getClass(), - proxyDatabaseMetaData); - */ - return (DatabaseMetaData) delegate; - } - - /** * Get the WrappedConnection behind this proxy connection. * @param connection the connection that was served --- 232,235 ---- *************** *** 276,282 **** */ public static WrappedConnection getWrappedConnection(Connection connection) { - /* - return (WrappedConnection) Proxy.getInvocationHandler(connection); - */ return (WrappedConnection) ((Factory)connection).getCallback(0); } --- 237,240 ---- *************** *** 287,290 **** --- 245,251 ---- Revision history: $Log$ + Revision 1.31 2005/09/26 09:59:22 billhorsman + Explicitly use the ProxyFactory class loader when using Cglib's Enhancer to avoid class loading issues. + Revision 1.30 2005/05/04 16:31:41 billhorsman Use the definition referenced by the proxy connection rather than the pool instead. |