You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2003/03/05 19:59:03 UTC

cvs commit: avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource PoolSettable.java AbstractJdbcConnection.java Jdbc3Connection.java JdbcConnection.java JdbcConnectionFactory.java JdbcConnectionPool.java ResourceLimitingJdbcConnectionPool.java

bloritsch    2003/03/05 10:59:02

  Modified:    datasource/src/java/org/apache/avalon/excalibur/datasource
                        AbstractJdbcConnection.java Jdbc3Connection.java
                        JdbcConnection.java JdbcConnectionFactory.java
                        JdbcConnectionPool.java
                        ResourceLimitingJdbcConnectionPool.java
  Added:       datasource/src/java/org/apache/avalon/excalibur/datasource
                        PoolSettable.java
  Log:
  update datasource so that it no longer requires conditional compilation, and should work in any environment
  
  Revision  Changes    Path
  1.25      +45 -56    avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/AbstractJdbcConnection.java
  
  Index: AbstractJdbcConnection.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/AbstractJdbcConnection.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- AbstractJdbcConnection.java	27 Feb 2003 15:20:55 -0000	1.24
  +++ AbstractJdbcConnection.java	5 Mar 2003 18:59:00 -0000	1.25
  @@ -49,19 +49,21 @@
   */
   package org.apache.avalon.excalibur.datasource;
   
  +import java.lang.reflect.InvocationHandler;
  +import java.lang.reflect.Method;
   import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
  +import java.util.HashMap;
   import java.util.Iterator;
   import java.util.LinkedList;
   import java.util.List;
  +import java.util.Map;
   
   import org.apache.avalon.excalibur.pool.Pool;
  -import org.apache.avalon.excalibur.pool.Recyclable;
   import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.Logger;
   
  @@ -73,15 +75,27 @@
    * @version CVS $Revision$ $Date$
    * @since 4.1
    */
  -public abstract class AbstractJdbcConnection
  +public class AbstractJdbcConnection
       extends AbstractLogEnabled
  -    implements Connection, Recyclable, Disposable, Initializable
  +    implements PoolSettable, Disposable,  InvocationHandler
   {
       protected Connection m_connection;
       protected Pool m_pool;
       protected PreparedStatement m_testStatement;
       protected SQLException m_testException;
       protected long m_lastUsed = System.currentTimeMillis();
  +    private static final Map m_methods;
  +    
  +    static {
  +        m_methods = new HashMap();
  +        Method[] methods = AbstractJdbcConnection.class.getDeclaredMethods();
  +        
  +        for ( int i = 0; i < methods.length; i++ )
  +        {
  +            m_methods.put(methods[i].getName(), methods[i]);
  +        }
  +    }
  +    
       /**
        * Contains Statements created on the original jdbc connection
        * between a {@link JdbcDataSource#getConnection} and {@link
  @@ -155,7 +169,7 @@
           }
       }
   
  -    protected void setPool( Pool pool )
  +    public void setPool( Pool pool )
       {
           m_pool = pool;
       }
  @@ -219,7 +233,7 @@
           try
           {
               clearAllocatedStatements();
  -            clearWarnings();
  +            m_connection.clearWarnings();
               m_pool.put( this );
           }
           catch ( SQLException se )
  @@ -291,53 +305,28 @@
               }
           }
       }
  -
  -/*    @JDBC3_START@
  -    public abstract void setHoldability( int holdability )
  -        throws SQLException;
  -
  -    public abstract int getHoldability()
  -        throws SQLException;
  -
  -    public abstract java.sql.Savepoint setSavepoint()
  -        throws SQLException;
  -
  -    public abstract java.sql.Savepoint setSavepoint( String savepoint )
  -        throws SQLException;
  -
  -    public abstract void rollback( java.sql.Savepoint savepoint )
  -        throws SQLException;
  -
  -    public abstract void releaseSavepoint( java.sql.Savepoint savepoint )
  -        throws SQLException;
  -
  -    public abstract Statement createStatement( int resulSetType,
  -                                               int resultSetConcurrency,
  -                                               int resultSetHoldability )
  -        throws SQLException;
  -
  -    public abstract PreparedStatement prepareStatement( String sql,
  -                                                        int resulSetType,
  -                                                        int resultSetConcurrency,
  -                                                        int resultSetHoldability )
  -        throws SQLException;
  -
  -    public abstract java.sql.CallableStatement prepareCall( String sql,
  -                                                   int resulSetType,
  -                                                   int resultSetConcurrency,
  -                                                   int resultSetHoldability )
  -        throws SQLException;
  -
  -    public abstract PreparedStatement prepareStatement( String sql,
  -                                                        int autoGeneratedKeys )
  -        throws SQLException;
  -
  -    public abstract PreparedStatement prepareStatement( String sql,
  -                                                        int[] columnIndexes )
  -        throws SQLException;
  -
  -    public abstract PreparedStatement prepareStatement( String sql,
  -                                                        String[] columnNames )
  -        throws SQLException;
  -    @JDBC3_END@ */
  +    
  +    public Object invoke(Object proxy, Method method, Object[] args)
  +              throws Throwable
  +    {
  +        Object retVal = null;
  +        Method executeMethod = (Method)m_methods.get(method.getName());
  +        
  +        if ( null == executeMethod )
  +        {
  +            retVal = method.invoke(m_connection, args);
  +        }
  +        else
  +        {
  +            retVal = executeMethod.invoke(this, args);
  +        }
  +        
  +        
  +        if ( getLogger().isDebugEnabled())
  +        {
  +            getLogger().debug(((null == executeMethod) ? "connection" : "implemented:") + method.getName());
  +        }
  +        
  +        return retVal;
  +    }
   }
  
  
  
  1.15      +9 -297    avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/Jdbc3Connection.java
  
  Index: Jdbc3Connection.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/Jdbc3Connection.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Jdbc3Connection.java	27 Feb 2003 15:20:55 -0000	1.14
  +++ Jdbc3Connection.java	5 Mar 2003 18:59:00 -0000	1.15
  @@ -49,23 +49,14 @@
   */
   package org.apache.avalon.excalibur.datasource;
   
  -import java.sql.CallableStatement;
   import java.sql.Connection;
  -import java.sql.DatabaseMetaData;
  -import java.sql.PreparedStatement;
  -import java.sql.SQLException;
  -import java.sql.SQLWarning;
  -import java.sql.Savepoint;
  -import java.sql.Statement;
  -import java.util.Map;
  +
   
   /**
    * The Connection object used in conjunction with the JdbcDataSource
    * object.
    *
  - * TODO: Implement a configurable closed end Pool, where the Connection
  - * acts like JDBC PooledConnections work.  That means we can limit the
  - * total number of Connection objects that are created.
  + * @deprecated No longer necessary due to the dynamic proxies 
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @version CVS $Revision$ $Date$
  @@ -74,293 +65,14 @@
   public class Jdbc3Connection
       extends AbstractJdbcConnection
   {
  +    /**
  +     * @param connection a driver specific JDBC connection to be wrapped.
  +     * @param keepAlive a query which will be used to check the statis of the connection after it
  +     *                  has been idle.  A null value will cause the keep alive feature to
  +     *                  be disabled.
  +     */
       public Jdbc3Connection( final Connection connection, final String keepAlive )
       {
           super( connection, keepAlive );
  -    }
  -
  -    public final Statement createStatement()
  -        throws SQLException
  -    {
  -        final Statement temp = m_connection.createStatement();
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( final String sql )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement( sql );
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final CallableStatement prepareCall( final String sql )
  -        throws SQLException
  -    {
  -        final CallableStatement temp = m_connection.prepareCall( sql );
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final String nativeSQL( final String sql )
  -        throws SQLException
  -    {
  -        return m_connection.nativeSQL( sql );
  -    }
  -
  -    public final void setAutoCommit( final boolean autoCommit )
  -        throws SQLException
  -    {
  -        m_connection.setAutoCommit( autoCommit );
  -    }
  -
  -    public final boolean getAutoCommit()
  -        throws SQLException
  -    {
  -        return m_connection.getAutoCommit();
  -    }
  -
  -    public final void commit()
  -        throws SQLException
  -    {
  -        m_connection.commit();
  -        m_lastUsed = System.currentTimeMillis();
  -    }
  -
  -    public final void rollback()
  -        throws SQLException
  -    {
  -        m_connection.rollback();
  -        m_lastUsed = System.currentTimeMillis();
  -    }
  -
  -    public final DatabaseMetaData getMetaData()
  -        throws SQLException
  -    {
  -        return m_connection.getMetaData();
  -    }
  -
  -    public final void setReadOnly( final boolean readOnly )
  -        throws SQLException
  -    {
  -        m_connection.setReadOnly( readOnly );
  -    }
  -
  -    public final boolean isReadOnly()
  -        throws SQLException
  -    {
  -        return m_connection.isReadOnly();
  -    }
  -
  -    public final void setCatalog( final String catalog )
  -        throws SQLException
  -    {
  -        m_connection.setCatalog( catalog );
  -    }
  -
  -    public final String getCatalog()
  -        throws SQLException
  -    {
  -        return m_connection.getCatalog();
  -    }
  -
  -    public final void setTransactionIsolation( final int level )
  -        throws SQLException
  -    {
  -        m_connection.setTransactionIsolation( level );
  -    }
  -
  -    public final int getTransactionIsolation()
  -        throws SQLException
  -    {
  -        return m_connection.getTransactionIsolation();
  -    }
  -
  -    public final SQLWarning getWarnings()
  -        throws SQLException
  -    {
  -        return m_connection.getWarnings();
  -    }
  -
  -    public final void clearWarnings()
  -        throws SQLException
  -    {
  -        m_connection.clearWarnings();
  -    }
  -
  -    public final Statement createStatement( final int resultSetType,
  -                                            final int resultSetConcurrency )
  -        throws SQLException
  -    {
  -        final Statement temp = m_connection.createStatement(
  -            resultSetType, resultSetConcurrency
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( final String sql,
  -                                                     final int resultSetType,
  -                                                     final int resultSetConcurrency )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement(
  -            sql, resultSetType, resultSetConcurrency
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final CallableStatement prepareCall( final String sql,
  -                                                final int resultSetType,
  -                                                final int resultSetConcurrency )
  -        throws SQLException
  -    {
  -        final CallableStatement temp = m_connection.prepareCall(
  -            sql, resultSetType, resultSetConcurrency
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final Map getTypeMap()
  -        throws SQLException
  -    {
  -        return m_connection.getTypeMap();
  -    }
  -
  -    public final void setTypeMap( final Map map )
  -        throws SQLException
  -    {
  -        m_connection.setTypeMap( map );
  -    }
  -
  -    public final void setHoldability( int holdability )
  -        throws SQLException
  -    {
  -        m_connection.setHoldability( holdability );
  -    }
  -
  -    public final int getHoldability()
  -        throws SQLException
  -    {
  -        return m_connection.getHoldability();
  -    }
  -
  -    public final Savepoint setSavepoint()
  -        throws SQLException
  -    {
  -        return m_connection.setSavepoint();
  -    }
  -
  -    public final Savepoint setSavepoint( String savepoint )
  -        throws SQLException
  -    {
  -        return m_connection.setSavepoint( savepoint );
  -    }
  -
  -    public final void rollback( Savepoint savepoint )
  -        throws SQLException
  -    {
  -        m_connection.rollback( savepoint );
  -        m_lastUsed = System.currentTimeMillis();
  -    }
  -
  -    public final void releaseSavepoint( Savepoint savepoint )
  -        throws SQLException
  -    {
  -        m_connection.releaseSavepoint( savepoint );
  -    }
  -
  -    public final Statement createStatement( int resultSetType,
  -                                            int resultSetConcurrency,
  -                                            int resultSetHoldability )
  -        throws SQLException
  -    {
  -        final Statement temp = m_connection.createStatement(
  -            resultSetType, resultSetConcurrency, resultSetHoldability
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     int resultSetType,
  -                                                     int resultSetConcurrency,
  -                                                     int resultSetHoldability )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement(
  -            sql, resultSetType, resultSetConcurrency, resultSetHoldability
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        return temp;
  -    }
  -
  -    public final CallableStatement prepareCall( String sql,
  -                                                int resultSetType,
  -                                                int resultSetConcurrency,
  -                                                int resultSetHoldability )
  -        throws SQLException
  -    {
  -        final CallableStatement temp = m_connection.prepareCall(
  -            sql, resultSetType, resultSetConcurrency, resultSetHoldability
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     int autoGeneratedKeys )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement(
  -            sql, autoGeneratedKeys
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     int[] columnIndexes )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement(
  -            sql, columnIndexes
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     String[] columnNames )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement(
  -            sql, columnNames
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
       }
   }
  
  
  
  1.11      +2 -262    avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnection.java
  
  Index: JdbcConnection.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnection.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JdbcConnection.java	27 Feb 2003 15:20:55 -0000	1.10
  +++ JdbcConnection.java	5 Mar 2003 18:59:01 -0000	1.11
  @@ -49,22 +49,13 @@
   */
   package org.apache.avalon.excalibur.datasource;
   
  -import java.sql.CallableStatement;
   import java.sql.Connection;
  -import java.sql.DatabaseMetaData;
  -import java.sql.PreparedStatement;
  -import java.sql.SQLException;
  -import java.sql.SQLWarning;
  -import java.sql.Statement;
  -import java.util.Map;
   
   /**
    * The Connection object used in conjunction with the JdbcDataSource
    * object.
    *
  - * TODO: Implement a configurable closed end Pool, where the Connection
  - * acts like JDBC PooledConnections work.  That means we can limit the
  - * total number of Connection objects that are created.
  + * @deprecated No longer necessary due to the dynamic proxies 
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @version CVS $Revision$ $Date$
  @@ -83,256 +74,5 @@
       {
           super( connection, keepAlive );
       }
  -
  -    public final Statement createStatement()
  -        throws SQLException
  -    {
  -        final Statement temp = m_connection.createStatement();
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( final String sql )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement( sql );
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final CallableStatement prepareCall( final String sql )
  -        throws SQLException
  -    {
  -        final CallableStatement temp = m_connection.prepareCall( sql );
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final String nativeSQL( final String sql )
  -        throws SQLException
  -    {
  -        return m_connection.nativeSQL( sql );
  -    }
  -
  -    public final void setAutoCommit( final boolean autoCommit )
  -        throws SQLException
  -    {
  -        m_connection.setAutoCommit( autoCommit );
  -    }
  -
  -    public final boolean getAutoCommit()
  -        throws SQLException
  -    {
  -        return m_connection.getAutoCommit();
  -    }
  -
  -    public final void commit()
  -        throws SQLException
  -    {
  -        m_connection.commit();
  -        m_lastUsed = System.currentTimeMillis();
  -    }
  -
  -    public final void rollback()
  -        throws SQLException
  -    {
  -        m_connection.rollback();
  -        m_lastUsed = System.currentTimeMillis();
  -    }
  -
  -    public final DatabaseMetaData getMetaData()
  -        throws SQLException
  -    {
  -        return m_connection.getMetaData();
  -    }
  -
  -    public final void setReadOnly( final boolean readOnly )
  -        throws SQLException
  -    {
  -        m_connection.setReadOnly( readOnly );
  -    }
  -
  -    public final boolean isReadOnly()
  -        throws SQLException
  -    {
  -        return m_connection.isReadOnly();
  -    }
  -
  -    public final void setCatalog( final String catalog )
  -        throws SQLException
  -    {
  -        m_connection.setCatalog( catalog );
  -    }
  -
  -    public final String getCatalog()
  -        throws SQLException
  -    {
  -        return m_connection.getCatalog();
  -    }
  -
  -    public final void setTransactionIsolation( final int level )
  -        throws SQLException
  -    {
  -        m_connection.setTransactionIsolation( level );
  -    }
  -
  -    public final int getTransactionIsolation()
  -        throws SQLException
  -    {
  -        return m_connection.getTransactionIsolation();
  -    }
  -
  -    public final SQLWarning getWarnings()
  -        throws SQLException
  -    {
  -        return m_connection.getWarnings();
  -    }
  -
  -    public final void clearWarnings()
  -        throws SQLException
  -    {
  -        m_connection.clearWarnings();
  -    }
  -
  -    public final Statement createStatement( final int resultSetType,
  -                                            final int resultSetConcurrency )
  -        throws SQLException
  -    {
  -        final Statement temp = m_connection.createStatement(
  -            resultSetType, resultSetConcurrency
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final PreparedStatement prepareStatement( final String sql,
  -                                                     final int resultSetType,
  -                                                     final int resultSetConcurrency )
  -        throws SQLException
  -    {
  -        final PreparedStatement temp = m_connection.prepareStatement(
  -            sql, resultSetType, resultSetConcurrency
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final CallableStatement prepareCall( final String sql,
  -                                                final int resultSetType,
  -                                                final int resultSetConcurrency )
  -        throws SQLException
  -    {
  -        final CallableStatement temp = m_connection.prepareCall(
  -            sql, resultSetType, resultSetConcurrency
  -        );
  -
  -        m_lastUsed = System.currentTimeMillis();
  -        registerAllocatedStatement( temp );
  -        return temp;
  -    }
  -
  -    public final Map getTypeMap()
  -        throws SQLException
  -    {
  -        return m_connection.getTypeMap();
  -    }
  -
  -    public final void setTypeMap( final Map map )
  -        throws SQLException
  -    {
  -        m_connection.setTypeMap( map );
  -    }
  -
  -/*    @JDBC3_START@
  -    public final void setHoldability( int holdability )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final int getHoldability()
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final java.sql.Savepoint setSavepoint()
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final java.sql.Savepoint setSavepoint( String savepoint )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final void rollback( java.sql.Savepoint savepoint )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final void releaseSavepoint( java.sql.Savepoint savepoint )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final Statement createStatement( int resulSetType,
  -                                            int resultSetConcurrency,
  -                                            int resultSetHoldability )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     int resulSetType,
  -                                                     int resultSetConcurrency,
  -                                                     int resultSetHoldability )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final CallableStatement prepareCall( String sql,
  -                                                int resulSetType,
  -                                                int resultSetConcurrency,
  -                                                int resultSetHoldability )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     int autoGeneratedKeys )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     int[] columnIndexes )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -
  -    public final PreparedStatement prepareStatement( String sql,
  -                                                     String[] columnNames )
  -        throws SQLException
  -    {
  -        throw new SQLException( "This is not a Jdbc 3.0 Compliant Connection" );
  -    }
  -    @JDBC3_END@ */
   }
   
  
  
  
  1.18      +41 -36    avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionFactory.java
  
  Index: JdbcConnectionFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionFactory.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- JdbcConnectionFactory.java	27 Feb 2003 15:20:55 -0000	1.17
  +++ JdbcConnectionFactory.java	5 Mar 2003 18:59:01 -0000	1.18
  @@ -50,11 +50,16 @@
   package org.apache.avalon.excalibur.datasource;
   
   import java.lang.reflect.Constructor;
  +import java.lang.reflect.InvocationHandler;
  +import java.lang.reflect.Proxy;
   import java.sql.Connection;
   import java.sql.DriverManager;
   
   import org.apache.avalon.excalibur.pool.ObjectFactory;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.logger.LogEnabled;
   
   /**
    * The Factory implementation for JdbcConnections.
  @@ -157,23 +162,17 @@
           String className = m_connectionClass;
           if( null == className )
           {
  -            try
  -            {
  -                java.lang.reflect.Method meth = connection.getClass().getMethod( "getHoldability", new Class[]{} );
  -                className = "org.apache.avalon.excalibur.datasource.Jdbc3Connection";
  -            }
  -            catch( Exception e )
  -            {
  -                className = "org.apache.avalon.excalibur.datasource.JdbcConnection";
  -            }
  +            m_class = AbstractJdbcConnection.class;
  +        }
  +        else
  +        {
  +            m_class = Thread.currentThread().getContextClassLoader().loadClass( className );
           }
  -
  -        this.m_class = Thread.currentThread().getContextClassLoader().loadClass( className );
       }
   
       public Object newInstance() throws Exception
       {
  -        AbstractJdbcConnection jdbcConnection = null;
  +        Connection jdbcConnection = null;
           Connection connection = m_firstConnection;
   
           if( null == connection )
  @@ -210,37 +209,19 @@
   
           try
           {
  -            Class[] paramTypes = new Class[]{Connection.class, String.class};
  -            Object[] params = new Object[]{connection, this.m_keepAlive};
  -
  -            Constructor constructor = m_class.getConstructor( paramTypes );
  -            jdbcConnection = (AbstractJdbcConnection)constructor.newInstance( params );
  +            jdbcConnection = getProxy(connection, this.m_keepAlive);
           }
           catch( Exception e )
           {
  -            try
  +            if( getLogger().isDebugEnabled() )
               {
  -                // Support the deprecated connection constructor as well.
  -                boolean oracleKeepAlive = ( m_keepAlive != null ) && m_keepAlive.equalsIgnoreCase( JdbcConnectionFactory.ORACLE_KEEPALIVE );
  -
  -                Class[] paramTypes = new Class[]{Connection.class, boolean.class};
  -                Object[] params = new Object[]{connection, new Boolean( oracleKeepAlive )};
  -
  -                Constructor constructor = m_class.getConstructor( paramTypes );
  -                jdbcConnection = (AbstractJdbcConnection)constructor.newInstance( params );
  +                getLogger().debug( "Exception in JdbcConnectionFactory.newInstance:", e );
               }
  -            catch( Exception ie )
  -            {
  -                if( getLogger().isDebugEnabled() )
  -                {
  -                    getLogger().debug( "Exception in JdbcConnectionFactory.newInstance:", ie );
  -                }
   
  -                throw new NoValidConnectionException( ie.getMessage() );
  -            }
  +            throw new NoValidConnectionException( e.getMessage() );
           }
   
  -        jdbcConnection.enableLogging( getLogger() );
  +        ContainerUtil.enableLogging(jdbcConnection, getLogger());
   
           // Not all drivers are friendly to explicitly setting autocommit
           if( jdbcConnection.getAutoCommit() != m_autoCommit )
  @@ -267,5 +248,29 @@
           {
               ( (AbstractJdbcConnection)object ).dispose();
           }
  +    }
  +    
  +    private Connection getProxy(Connection conn, String keepAlive)
  +    {
  +        InvocationHandler handler = null;
  +        
  +        try
  +        {
  +            Constructor builder = m_class.getConstructor(new Class[]{Connection.class, String.class});
  +            handler = (InvocationHandler)builder.newInstance(new Object[]{conn, keepAlive});
  +        }
  +        catch (Exception e)
  +        {
  +            getLogger().error("Could not create the proper invocation handler, defaulting to AbstractJdbcConnection", e);
  +            handler = new AbstractJdbcConnection(conn, keepAlive);
  +        }
  +        
  +        return (Connection) Proxy.newProxyInstance(
  +                m_class.getClassLoader(),
  +                new Class[]{Connection.class,
  +                            LogEnabled.class,
  +                            PoolSettable.class,
  +                            Disposable.class},
  +                handler);
       }
   }
  
  
  
  1.20      +12 -10    avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionPool.java
  
  Index: JdbcConnectionPool.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/JdbcConnectionPool.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- JdbcConnectionPool.java	27 Feb 2003 15:20:55 -0000	1.19
  +++ JdbcConnectionPool.java	5 Mar 2003 18:59:02 -0000	1.20
  @@ -49,12 +49,14 @@
   */
   package org.apache.avalon.excalibur.datasource;
   
  +import java.sql.Connection;
   import java.util.HashSet;
   import java.util.Iterator;
   
   import org.apache.avalon.excalibur.pool.DefaultPoolController;
   import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
   import org.apache.avalon.excalibur.pool.Poolable;
  +import org.apache.avalon.excalibur.pool.Recyclable;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   
  @@ -113,11 +115,11 @@
   
       protected final Poolable newPoolable() throws Exception
       {
  -        AbstractJdbcConnection conn = null;
  +        PoolSettable conn = null;
   
           if( m_wait < 1 )
           {
  -            conn = (AbstractJdbcConnection)super.newPoolable();
  +            conn = (PoolSettable)super.newPoolable();
           }
           else
           {
  @@ -142,7 +144,7 @@
   
                   try
                   {
  -                    conn = (AbstractJdbcConnection)super.newPoolable();
  +                    conn = (PoolSettable)super.newPoolable();
                   }
                   finally
                   {
  @@ -179,7 +181,7 @@
               }
           }
   
  -        AbstractJdbcConnection obj = (AbstractJdbcConnection)super.get();
  +        PoolSettable obj = (PoolSettable)super.get();
   
           if( obj.isClosed() )
           {
  @@ -196,9 +198,9 @@
                       m_active.remove( obj );
                   }
   
  -                this.removePoolable( obj );
  +                this.removePoolable( (Recyclable)obj );
   
  -                obj = (AbstractJdbcConnection)this.newPoolable();
  +                obj = (PoolSettable)this.newPoolable();
   
                   m_active.add( obj );
               }
  @@ -216,12 +218,12 @@
               }
           }
   
  -        if( obj.getAutoCommit() != m_autoCommit )
  +        if( ((Connection)obj).getAutoCommit() != m_autoCommit )
           {
  -            obj.setAutoCommit( m_autoCommit );
  +            ((Connection)obj).setAutoCommit( m_autoCommit );
           }
   
  -        return obj;
  +        return (Poolable)obj;
       }
   
       public void put( Poolable obj )
  
  
  
  1.4       +5 -4      avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcConnectionPool.java
  
  Index: ResourceLimitingJdbcConnectionPool.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/ResourceLimitingJdbcConnectionPool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ResourceLimitingJdbcConnectionPool.java	27 Feb 2003 15:20:55 -0000	1.3
  +++ ResourceLimitingJdbcConnectionPool.java	5 Mar 2003 18:59:02 -0000	1.4
  @@ -49,6 +49,7 @@
   */
   package org.apache.avalon.excalibur.datasource;
   
  +import java.sql.Connection;
   import java.sql.SQLException;
   
   import org.apache.avalon.excalibur.pool.ObjectFactory;
  @@ -119,13 +120,13 @@
        */
       protected Poolable newPoolable() throws Exception
       {
  -        AbstractJdbcConnection conn = (AbstractJdbcConnection)super.newPoolable();
  +        PoolSettable conn = (PoolSettable)super.newPoolable();
   
           // Store a reference to this pool in the connection
           conn.setPool( this );
   
           // Set the auto commit flag for new connections.
  -        conn.setAutoCommit( m_autoCommit );
  +        ((Connection)conn).setAutoCommit( m_autoCommit );
   
           return conn;
       }
  @@ -141,7 +142,7 @@
        */
       protected boolean validatePoolable( Poolable poolable )
       {
  -        AbstractJdbcConnection conn = (AbstractJdbcConnection)poolable;
  +        PoolSettable conn = (PoolSettable)poolable;
           try
           {
               // Calling isClosed() may take time if the connection has not been
  
  
  
  1.1                  avalon-excalibur/datasource/src/java/org/apache/avalon/excalibur/datasource/PoolSettable.java
  
  Index: PoolSettable.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
   
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
   
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
   
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
   
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
   
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
   
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"  
      must not be used to endorse or promote products derived from this  software 
      without  prior written permission. For written permission, please contact 
      apache@apache.org.
   
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
   
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the 
   Apache Software Foundation, please see <http://www.apache.org/>.
   
  */
  package org.apache.avalon.excalibur.datasource;
  
  import java.sql.SQLException;
  
  import org.apache.avalon.excalibur.pool.Pool;
  import org.apache.avalon.excalibur.pool.Recyclable;
  
  /**
   * Hack class to work around the dynamic proxy issues of not allowing
   * abstract base classes as an "interface".
   */
  public interface PoolSettable extends Recyclable
  {
      /**
       * Set the pool that will be used to recycle.
       * 
       * @param pool
       */
      void setPool( Pool pool );
      
      boolean isClosed() throws SQLException;
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org