avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource AbstractJdbcConnection.java
Date Wed, 23 Jan 2002 14:46:21 GMT
bloritsch    02/01/23 06:46:21

  Modified:    src/java/org/apache/avalon/excalibur/datasource
                        AbstractJdbcConnection.java
  Log:
  Fix carriage return issues && logic error
  
  Revision  Changes    Path
  1.8       +217 -217  jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/AbstractJdbcConnection.java
  
  Index: AbstractJdbcConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/datasource/AbstractJdbcConnection.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractJdbcConnection.java	17 Jan 2002 13:31:05 -0000	1.7
  +++ AbstractJdbcConnection.java	23 Jan 2002 14:46:21 -0000	1.8
  @@ -1,217 +1,217 @@
  -/*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  - *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE.txt file.
  - */
  -package org.apache.avalon.excalibur.datasource;
  -
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import java.sql.CallableStatement;
  -import java.sql.Connection;
  -import java.sql.PreparedStatement;
  -import java.sql.SQLException;
  -import java.sql.Statement;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.excalibur.pool.Recyclable;
  -import org.apache.avalon.excalibur.pool.Pool;
  -import org.apache.avalon.framework.logger.Logger;
  -
  -/**
  - * 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.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2002/01/17 13:31:05 $
  - * @since 4.1
  - */
  -public abstract class AbstractJdbcConnection
  -    extends AbstractLogEnabled
  -    implements Connection, Recyclable, Disposable, Initializable
  -{
  -    protected Connection         m_connection;
  -    protected Pool               m_pool;
  -    protected PreparedStatement  m_testStatement;
  -    protected SQLException       m_testException;
  -    protected long               m_lastUsed        = System.currentTimeMillis();
  -
  -    /**
  -     * Private default constructor so that it cannot be instantiated any
  -     * other way than we desire.
  -     */
  -    private AbstractJdbcConnection() {}
  -
  -    /**
  -     * @deprecated Use the version with keepAlive specified
  -     */
  -    public AbstractJdbcConnection( final Connection connection, final boolean oradb )
  -    {
  -        this(connection, (oradb) ? "select 1 from dual" : "select 1");
  -    }
  -
  -    public AbstractJdbcConnection( final Connection connection, final String keepAlive
)
  -    {
  -        m_connection = connection;
  -
  -        // subclasses can override initialize()
  -        this.initialize();
  -
  -        if (null == keepAlive && "".equals(keepAlive.trim()))
  -        {
  -            m_testStatement = null;
  -            m_testException = null;
  -        }
  -        else
  -        {
  -            try
  -            {
  -                m_testStatement = prepareStatement(keepAlive);
  -            }
  -            catch ( final SQLException se )
  -            {
  -                m_testStatement = null;
  -                m_testException = se;
  -            }
  -        }
  -    }
  -
  -    public void initialize() {}
  -
  -    public void enableLogging( final Logger log )
  -    {
  -        super.enableLogging(log);
  -
  -        if (m_testStatement == null && m_testException != null)
  -        {
  -            if (getLogger().isWarnEnabled())
  -            {
  -                getLogger().warn("Could not prepare test statement, connection recycled
on basis of time.", m_testException);
  -            }
  -            m_testException = null;
  -        }
  -    }
  -
  -    protected void setPool(Pool pool)
  -    {
  -        m_pool = pool;
  -    }
  -
  -    public void recycle() {
  -        m_lastUsed = System.currentTimeMillis();
  -        m_testException = null;
  -        try
  -        {
  -            m_connection.clearWarnings();
  -        }
  -        catch ( SQLException se )
  -        {
  -            // ignore
  -        }
  -    }
  -
  -    public boolean isClosed()
  -        throws SQLException
  -    {
  -        if ( m_connection.isClosed())
  -        {
  -            return true;
  -        }
  -
  -        if ( System.currentTimeMillis() - m_lastUsed
  -               > 1000*60*60 ) // over an hour?
  -        {
  -            this.dispose();
  -            return true;
  -        }
  -
  -        if (m_testStatement != null)
  -        {
  -            try
  -            {
  -                m_testStatement.executeQuery();
  -            }
  -            catch (final SQLException se)
  -            {
  -                this.dispose();
  -                return true;
  -            }
  -        }
  -
  -        return false;
  -    }
  -
  -    public void close()
  -        throws SQLException
  -    {
  -        clearWarnings();
  -        m_pool.put( this );
  -    }
  -
  -    public void dispose()
  -    {
  -        try { m_connection.close(); }
  -        catch( final SQLException se )
  -        {
  -            if (getLogger().isWarnEnabled())
  -            {
  -                getLogger().warn( "Could not close connection", se );
  -            }
  -        }
  -    }
  -
  -@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 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@
  -}
  +/*
  + * Copyright (C) The Apache Software Foundation. All rights reserved.
  + *
  + * This software is published under the terms of the Apache Software License
  + * version 1.1, a copy of which has been included with this distribution in
  + * the LICENSE.txt file.
  + */
  +package org.apache.avalon.excalibur.datasource;
  +
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import java.sql.CallableStatement;
  +import java.sql.Connection;
  +import java.sql.PreparedStatement;
  +import java.sql.SQLException;
  +import java.sql.Statement;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.excalibur.pool.Recyclable;
  +import org.apache.avalon.excalibur.pool.Pool;
  +import org.apache.avalon.framework.logger.Logger;
  +
  +/**
  + * 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.
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision: 1.8 $ $Date: 2002/01/23 14:46:21 $
  + * @since 4.1
  + */
  +public abstract class AbstractJdbcConnection
  +    extends AbstractLogEnabled
  +    implements Connection, Recyclable, Disposable, Initializable
  +{
  +    protected Connection         m_connection;
  +    protected Pool               m_pool;
  +    protected PreparedStatement  m_testStatement;
  +    protected SQLException       m_testException;
  +    protected long               m_lastUsed        = System.currentTimeMillis();
  +
  +    /**
  +     * Private default constructor so that it cannot be instantiated any
  +     * other way than we desire.
  +     */
  +    private AbstractJdbcConnection() {}
  +
  +    /**
  +     * @deprecated Use the version with keepAlive specified
  +     */
  +    public AbstractJdbcConnection( final Connection connection, final boolean oradb )
  +    {
  +        this(connection, (oradb) ? "select 1 from dual" : "select 1");
  +    }
  +
  +    public AbstractJdbcConnection( final Connection connection, final String keepAlive
)
  +    {
  +        m_connection = connection;
  +
  +        // subclasses can override initialize()
  +        this.initialize();
  +
  +        if (null == keepAlive || "".equals(keepAlive.trim()))
  +        {
  +            m_testStatement = null;
  +            m_testException = null;
  +        }
  +        else
  +        {
  +            try
  +            {
  +                m_testStatement = prepareStatement(keepAlive);
  +            }
  +            catch ( final SQLException se )
  +            {
  +                m_testStatement = null;
  +                m_testException = se;
  +            }
  +        }
  +    }
  +
  +    public void initialize() {}
  +
  +    public void enableLogging( final Logger log )
  +    {
  +        super.enableLogging(log);
  +
  +        if (m_testStatement == null && m_testException != null)
  +        {
  +            if (getLogger().isWarnEnabled())
  +            {
  +                getLogger().warn("Could not prepare test statement, connection recycled
on basis of time.", m_testException);
  +            }
  +            m_testException = null;
  +        }
  +    }
  +
  +    protected void setPool(Pool pool)
  +    {
  +        m_pool = pool;
  +    }
  +
  +    public void recycle() {
  +        m_lastUsed = System.currentTimeMillis();
  +        m_testException = null;
  +        try
  +        {
  +            m_connection.clearWarnings();
  +        }
  +        catch ( SQLException se )
  +        {
  +            // ignore
  +        }
  +    }
  +
  +    public boolean isClosed()
  +        throws SQLException
  +    {
  +        if ( m_connection.isClosed())
  +        {
  +            return true;
  +        }
  +
  +        if ( System.currentTimeMillis() - m_lastUsed
  +               > 1000*60*60 ) // over an hour?
  +        {
  +            this.dispose();
  +            return true;
  +        }
  +
  +        if (m_testStatement != null)
  +        {
  +            try
  +            {
  +                m_testStatement.executeQuery();
  +            }
  +            catch (final SQLException se)
  +            {
  +                this.dispose();
  +                return true;
  +            }
  +        }
  +
  +        return false;
  +    }
  +
  +    public void close()
  +        throws SQLException
  +    {
  +        clearWarnings();
  +        m_pool.put( this );
  +    }
  +
  +    public void dispose()
  +    {
  +        try { m_connection.close(); }
  +        catch( final SQLException se )
  +        {
  +            if (getLogger().isWarnEnabled())
  +            {
  +                getLogger().warn( "Could not close connection", se );
  +            }
  +        }
  +    }
  +
  +@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 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@
  +}
  
  
  

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


Mime
View raw message