User: mulder  
  Date: 00/06/02 06:48:44

  Added:       src/main/org/jboss/minerva/jdbc ConnectionInPool.java
                        ConnectionWrapper.java ResultSetInPool.java
                        StatementInPool.java package.html
  Log:
  Initial entry of Minerva JDBC Pools into CVS.
  
  Pools, DataSources, and other non-jBoss-dependent code is under
    org.jboss.minerva.*
  
  JavaDoc source HTML files are included - the package comments are in
    the package.html files in the various packages, and the overview
    comments are in org/jboss/minerva/minerva.html
  
  MBeans to load a pool into jBoss are in org.jboss.jdbc
  
  A new logging Writer is on org.jboss.logging.
  
  Revision  Changes    Path
  1.1                  jboss/src/main/org/jboss/minerva/jdbc/ConnectionInPool.java
  
  Index: ConnectionInPool.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.minerva.jdbc;
  
  import java.sql.*;
  import java.util.*;
  import org.jboss.minerva.pools.*;
  
  /**
   * Wrapper for database connections in a pool.  Handles closing appropriately.
   * The connection is returned to the pool rather than truly closing, any
   * outstanding statements are closed, and the connection is rolled back.  This
   * class is also used by statements, etc. to update the last used time for the
   * connection.
   * @version $Revision: 1.1 $
   * @author Aaron Mulder ([EMAIL PROTECTED])
   */
  public class ConnectionInPool implements PooledObject, ConnectionWrapper {
      private final static String CLOSED = "Connection has been closed!";
  
      private Connection con;
      private HashSet statements;
      private Vector listeners;
  
      /**
       * Creates a new connection wrapper.
       * @param con The "real" database connection to wrap.
       * @param pool The database pool this connection came from.
       */
      public ConnectionInPool(Connection con) {
          this.con = con;
          statements = new HashSet();
          listeners = new Vector();
      }
  
      /**
       * Adds a listener for pool events.
       */
      public void addPoolEventListener(PoolEventListener listener) {
          listeners.addElement(listener);
      }
  
      /**
       * Removes a listener for pool events.
       */
      public void removePoolEventListener(PoolEventListener listener) {
          listeners.remove(listener);
      }
  
      /**
       * Gets a reference to the "real" connection.  This should only be used if
       * you need to cast that to a specific type to call a proprietary method -
       * you will defeat all the pooling if you use the underlying connection
       * directly.
       */
      public Connection getUnderlyingConnection() {
          return con;
      }
  
      /**
       * Closes this connection wrapper permanently.  All further calls with throw
       * a SQLException.
       */
      public void shutdown() {
          con = null;
          statements = null;
          listeners = null;
      }
  
      /**
       * Updates the last used time for this connection to the current time.
       */
      public void setLastUsed() {
          firePoolEvent(new PoolEvent(this, PoolEvent.OBJECT_USED));
      }
  
      /**
       * Indicates that an error occured on this connection.
       */
      public void setError(SQLException e) {
          firePoolEvent(new PoolEvent(this, PoolEvent.OBJECT_ERROR));
      }
  
      /**
       * Indicates that a statement has been closed and no longer needs to be
       * tracked.  Outstanding statements are closed when the connection is
       * returned to the pool.
       */
      public void statementClosed(Statement st) {
          statements.remove(st);
      }
  
      /**
       * Prepares a connection to be returned to the pool.  All outstanding
       * statements are closed, and if AutoCommit is off, the connection is
       * rolled back.  No further SQL calls are possible once this is called.
       */
      public void reset() throws SQLException {
          Connection local = con;
          con = null;
  
          Collection copy = (Collection)statements.clone();
          Iterator it = copy.iterator();
          while(it.hasNext())
              try {
                  ((Statement)it.next()).close();
              } catch(SQLException e) {}
          if(!local.getAutoCommit())
              local.rollback();
      }
  
      /**
       * Dispatches an event to the listeners.
       */
      protected void firePoolEvent(PoolEvent evt) {
          Vector local = (Vector)listeners.clone();
          for(int i=local.size()-1; i >= 0; i--)
              if(evt.getType() == PoolEvent.OBJECT_CLOSED)
                  ((PoolEventListener)local.elementAt(i)).objectClosed(evt);
              else if(evt.getType() == PoolEvent.OBJECT_ERROR)
                  ((PoolEventListener)local.elementAt(i)).objectError(evt);
              else
                  ((PoolEventListener)local.elementAt(i)).objectUsed(evt);
      }
  
      // ---- Implementation of java.sql.Connection ----
      public Statement createStatement() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              StatementInPool st = new StatementInPool(con.createStatement(), this);
              statements.add(st);
              return st;
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public PreparedStatement prepareStatement(String sql) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.prepareStatement(sql);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public CallableStatement prepareCall(String sql) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.prepareCall(sql);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public String nativeSQL(String sql) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.nativeSQL(sql);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setAutoCommit(boolean autoCommit) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.setAutoCommit(autoCommit);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public boolean getAutoCommit() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.getAutoCommit();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void commit() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.commit();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void rollback() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.rollback();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void close() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          firePoolEvent(new PoolEvent(this, PoolEvent.OBJECT_CLOSED));
          shutdown();
      }
  
      public boolean isClosed() throws SQLException {
          if(con == null) return true;
          try {
              return con.isClosed();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public DatabaseMetaData getMetaData() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.getMetaData();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setReadOnly(boolean readOnly) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.setReadOnly(readOnly);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public boolean isReadOnly() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.isReadOnly();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setCatalog(String catalog) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.setCatalog(catalog);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public String getCatalog() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.getCatalog();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setTransactionIsolation(int level) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.setTransactionIsolation(level);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getTransactionIsolation() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.getTransactionIsolation();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public SQLWarning getWarnings() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.getWarnings();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void clearWarnings() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.clearWarnings();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public Statement createStatement(int resultSetType, int resultSetConcurrency) 
throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              StatementInPool st = new 
StatementInPool(con.createStatement(resultSetType, resultSetConcurrency), this);
              statements.add(st);
              return st;
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public PreparedStatement prepareStatement(String sql, int resultSetType, int 
resultSetConcurrency) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.prepareStatement(sql, resultSetType, resultSetConcurrency);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public CallableStatement prepareCall(String sql, int resultSetType, int 
resultSetConcurrency) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.prepareCall(sql, resultSetType, resultSetConcurrency);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public Map getTypeMap() throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              return con.getTypeMap();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setTypeMap(Map map) throws SQLException {
          if(con == null) throw new SQLException(CLOSED);
          try {
              con.setTypeMap(map);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  }
  
  
  1.1                  jboss/src/main/org/jboss/minerva/jdbc/ConnectionWrapper.java
  
  Index: ConnectionWrapper.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.minerva.jdbc;
  
  import java.sql.*;
  
  /**
   * Wrapper for database connections.  Tracks open statements, last used time,
   * and records errors.  In practice, this is used both as a wrapper for
   * connections in a pool and as a wrapper for connections handed out by an
   * XAConnection.
   * @see javax.sql.XAConnection
   * @version $Revision: 1.1 $
   * @author Aaron Mulder ([EMAIL PROTECTED])
   */
  public interface ConnectionWrapper extends Connection {
      /**
       * Sets the time this connection (or a statement or result set derived from
       * it) was used.
       */
      public void setLastUsed();
      /**
       * Indicates to the connection that an error occured.  This is typically
       * used by statements and result sets derived from this connection.
       */
      public void setError(SQLException e);
      /**
       * Indicates that a statement derived from this connection was closed.
       * Statements are tracked so that any open statements can be closed when
       * the connection is closed (or reused in a pool).
       */
      public void statementClosed(Statement st);
  }
  
  
  1.1                  jboss/src/main/org/jboss/minerva/jdbc/ResultSetInPool.java
  
  Index: ResultSetInPool.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.minerva.jdbc;
  
  import java.sql.*;
  
  /**
   * Wraps a result set to track the last used time for the owning connection.
   * That time is updated every time a navigation action is performed on the
   * result set (next, previous, etc.).
   * @version $Revision: 1.1 $
   * @author Aaron Mulder ([EMAIL PROTECTED])
   */
  public class ResultSetInPool implements ResultSet {
      private final static String CLOSED = "ResultSet has been closed!";
      private ResultSet impl;
      private StatementInPool st;
  
      /**
       * Creates a new wrapper from a source result set and statement wrapper.
       */
      ResultSetInPool(ResultSet source, StatementInPool owner) {
          impl = source;
          st = owner;
      }
  
      /**
       * Updates the last used time for the owning connection to the current time.
       */
      public void setLastUsed() {
          st.setLastUsed();
      }
  
      /**
       * Indicates that an error occured on the owning statement.
       */
      public void setError(SQLException e) {
          if(st != null)
              st.setError(e);
      }
  
      /**
       * Gets a reference to the "real" ResultSet.  This should only be used if
       * you need to cast that to a specific type to call a proprietary method -
       * you will defeat all the pooling if you use the underlying ResultSet
       * directly.
       */
      public ResultSet getUnderlyingResultSet() {
          return impl;
      }
  
      // ---- Implementation of java.sql.ResultSet ----
  
      public boolean absolute(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          return impl.absolute(arg0);
      }
  
      public void afterLast() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.afterLast();
      }
  
      public void beforeFirst() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.beforeFirst();
      }
  
      public void cancelRowUpdates() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.cancelRowUpdates();
      }
  
      public void clearWarnings() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.clearWarnings();
      }
  
      public void close() throws java.sql.SQLException {
          if(impl != null) {
              impl.close();
              impl = null;
          }
          st = null;
      }
  
      public void deleteRow() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.deleteRow();
      }
  
      public int findColumn(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.findColumn(arg0);
      }
  
      public boolean first() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          return impl.first();
      }
  
      public java.sql.Array getArray(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getArray(arg0);
      }
  
      public java.sql.Array getArray(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getArray(arg0);
      }
  
      public java.io.InputStream getAsciiStream(int arg0) throws java.sql.SQLException 
{
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getAsciiStream(arg0);
      }
  
      public java.io.InputStream getAsciiStream(String arg0) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getAsciiStream(arg0);
      }
  
      public java.math.BigDecimal getBigDecimal(int arg0) throws java.sql.SQLException 
{
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBigDecimal(arg0);
      }
  
      public java.math.BigDecimal getBigDecimal(int arg0, int arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBigDecimal(arg0, arg1);
      }
  
      public java.math.BigDecimal getBigDecimal(String arg0) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBigDecimal(arg0);
      }
  
      public java.math.BigDecimal getBigDecimal(String arg0, int arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBigDecimal(arg0, arg1);
      }
  
      public java.io.InputStream getBinaryStream(int arg0) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBinaryStream(arg0);
      }
  
      public java.io.InputStream getBinaryStream(String arg0) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBinaryStream(arg0);
      }
  
      public java.sql.Blob getBlob(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBlob(arg0);
      }
  
      public java.sql.Blob getBlob(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBlob(arg0);
      }
  
      public boolean getBoolean(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBoolean(arg0);
      }
  
      public boolean getBoolean(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBoolean(arg0);
      }
  
      public byte getByte(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getByte(arg0);
      }
  
      public byte getByte(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getByte(arg0);
      }
  
      public byte[] getBytes(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBytes(arg0);
      }
  
      public byte[] getBytes(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getBytes(arg0);
      }
  
      public java.io.Reader getCharacterStream(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getCharacterStream(arg0);
      }
  
      public java.io.Reader getCharacterStream(String arg0) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getCharacterStream(arg0);
      }
  
      public java.sql.Clob getClob(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getClob(arg0);
      }
  
      public java.sql.Clob getClob(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getClob(arg0);
      }
  
      public int getConcurrency() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getConcurrency();
      }
  
      public String getCursorName() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getCursorName();
      }
  
      public java.sql.Date getDate(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getDate(arg0);
      }
  
      public java.sql.Date getDate(int arg0, java.util.Calendar arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getDate(arg0, arg1);
      }
  
      public java.sql.Date getDate(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getDate(arg0);
      }
  
      public java.sql.Date getDate(String arg0, java.util.Calendar arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getDate(arg0, arg1);
      }
  
      public double getDouble(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getDouble(arg0);
      }
  
      public double getDouble(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getDouble(arg0);
      }
  
      public int getFetchDirection() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getFetchDirection();
      }
  
      public int getFetchSize() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getFetchSize();
      }
  
      public float getFloat(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getFloat(arg0);
      }
  
      public float getFloat(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getFloat(arg0);
      }
  
      public int getInt(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getInt(arg0);
      }
  
      public int getInt(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getInt(arg0);
      }
  
      public long getLong(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getLong(arg0);
      }
  
      public long getLong(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getLong(arg0);
      }
  
      public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getMetaData();
      }
  
      public Object getObject(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getObject(arg0);
      }
  
      public Object getObject(int arg0, java.util.Map arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getObject(arg0, arg1);
      }
  
      public Object getObject(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getObject(arg0);
      }
  
      public Object getObject(String arg0, java.util.Map arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getObject(arg0, arg1);
      }
  
      public java.sql.Ref getRef(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getRef(arg0);
      }
  
      public java.sql.Ref getRef(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getRef(arg0);
      }
  
      public int getRow() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getRow();
      }
  
      public short getShort(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getShort(arg0);
      }
  
      public short getShort(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getShort(arg0);
      }
  
      public java.sql.Statement getStatement() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getStatement();
      }
  
      public String getString(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getString(arg0);
      }
  
      public String getString(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getString(arg0);
      }
  
      public java.sql.Time getTime(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTime(arg0);
      }
  
      public java.sql.Time getTime(int arg0, java.util.Calendar arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTime(arg0, arg1);
      }
  
      public java.sql.Time getTime(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTime(arg0);
      }
  
      public java.sql.Time getTime(String arg0, java.util.Calendar arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTime(arg0, arg1);
      }
  
      public java.sql.Timestamp getTimestamp(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTimestamp(arg0);
      }
  
      public java.sql.Timestamp getTimestamp(int arg0, java.util.Calendar arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTimestamp(arg0, arg1);
      }
  
      public java.sql.Timestamp getTimestamp(String arg0) throws java.sql.SQLException 
{
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTimestamp(arg0);
      }
  
      public java.sql.Timestamp getTimestamp(String arg0, java.util.Calendar arg1) 
throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getTimestamp(arg0, arg1);
      }
  
      public int getType() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getType();
      }
  
      public java.io.InputStream getUnicodeStream(int arg0) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getUnicodeStream(arg0);
      }
  
      public java.io.InputStream getUnicodeStream(String arg0) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getUnicodeStream(arg0);
      }
  
      public java.sql.SQLWarning getWarnings() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.getWarnings();
      }
  
      public void insertRow() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.insertRow();
      }
  
      public boolean isAfterLast() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.isAfterLast();
      }
  
      public boolean isBeforeFirst() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.isBeforeFirst();
      }
  
      public boolean isFirst() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.isFirst();
      }
  
      public boolean isLast() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.isLast();
      }
  
      public boolean last() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          return impl.last();
      }
  
      public void moveToCurrentRow() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.moveToCurrentRow();
      }
  
      public void moveToInsertRow() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.moveToInsertRow();
      }
  
      public boolean next() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          return impl.next();
      }
  
      public boolean previous() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          return impl.previous();
      }
  
      public void refreshRow() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.refreshRow();
      }
  
      public boolean relative(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          return impl.relative(arg0);
      }
  
      public boolean rowDeleted() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.rowDeleted();
      }
  
      public boolean rowInserted() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.rowInserted();
      }
  
      public boolean rowUpdated() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.rowUpdated();
      }
  
      public void setFetchDirection(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.setFetchDirection(arg0);
      }
  
      public void setFetchSize(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.setFetchSize(arg0);
      }
  
      public void updateAsciiStream(int arg0, java.io.InputStream arg1, int arg2) 
throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateAsciiStream(arg0, arg1, arg2);
      }
  
      public void updateAsciiStream(String arg0, java.io.InputStream arg1, int arg2) 
throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateAsciiStream(arg0, arg1, arg2);
      }
  
      public void updateBigDecimal(int arg0, java.math.BigDecimal arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBigDecimal(arg0, arg1);
      }
  
      public void updateBigDecimal(String arg0, java.math.BigDecimal arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBigDecimal(arg0, arg1);
      }
  
      public void updateBinaryStream(int arg0, java.io.InputStream arg1, int arg2) 
throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBinaryStream(arg0, arg1, arg2);
      }
  
      public void updateBinaryStream(String arg0, java.io.InputStream arg1, int arg2) 
throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBinaryStream(arg0, arg1, arg2);
      }
  
      public void updateBoolean(int arg0, boolean arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBoolean(arg0, arg1);
      }
  
      public void updateBoolean(String arg0, boolean arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBoolean(arg0, arg1);
      }
  
      public void updateByte(int arg0, byte arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateByte(arg0, arg1);
      }
  
      public void updateByte(String arg0, byte arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateByte(arg0, arg1);
      }
  
      public void updateBytes(int arg0, byte[] arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBytes(arg0, arg1);
      }
  
      public void updateBytes(String arg0, byte[] arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateBytes(arg0, arg1);
      }
  
      public void updateCharacterStream(int arg0, java.io.Reader arg1, int arg2) 
throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateCharacterStream(arg0, arg1, arg2);
      }
  
      public void updateCharacterStream(String arg0, java.io.Reader arg1, int arg2) 
throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateCharacterStream(arg0, arg1, arg2);
      }
  
      public void updateDate(int arg0, java.sql.Date arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateDate(arg0, arg1);
      }
  
      public void updateDate(String arg0, java.sql.Date arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateDate(arg0, arg1);
      }
  
      public void updateDouble(int arg0, double arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateDouble(arg0, arg1);
      }
  
      public void updateDouble(String arg0, double arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateDouble(arg0, arg1);
      }
  
      public void updateFloat(int arg0, float arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateFloat(arg0, arg1);
      }
  
      public void updateFloat(String arg0, float arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateFloat(arg0, arg1);
      }
  
      public void updateInt(int arg0, int arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateInt(arg0, arg1);
      }
  
      public void updateInt(String arg0, int arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateInt(arg0, arg1);
      }
  
      public void updateLong(int arg0, long arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateLong(arg0, arg1);
      }
  
      public void updateLong(String arg0, long arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateLong(arg0, arg1);
      }
  
      public void updateNull(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateNull(arg0);
      }
  
      public void updateNull(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateNull(arg0);
      }
  
      public void updateObject(int arg0, Object arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateObject(arg0, arg1);
      }
  
      public void updateObject(int arg0, Object arg1, int arg2) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateObject(arg0, arg1, arg2);
      }
  
      public void updateObject(String arg0, Object arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateObject(arg0, arg1);
      }
  
      public void updateObject(String arg0, Object arg1, int arg2) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateObject(arg0, arg1, arg2);
      }
  
      public void updateRow() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          setLastUsed();
          impl.updateRow();
      }
  
      public void updateShort(int arg0, short arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateShort(arg0, arg1);
      }
  
      public void updateShort(String arg0, short arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateShort(arg0, arg1);
      }
  
      public void updateString(int arg0, String arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateString(arg0, arg1);
      }
  
      public void updateString(String arg0, String arg1) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateString(arg0, arg1);
      }
  
      public void updateTime(int arg0, java.sql.Time arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateTime(arg0, arg1);
      }
  
      public void updateTime(String arg0, java.sql.Time arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateTime(arg0, arg1);
      }
  
      public void updateTimestamp(int arg0, java.sql.Timestamp arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateTimestamp(arg0, arg1);
      }
  
      public void updateTimestamp(String arg0, java.sql.Timestamp arg1) throws 
java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          impl.updateTimestamp(arg0, arg1);
      }
  
      public boolean wasNull() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return impl.wasNull();
      }
  
      // ---- End Implementation of java.sql.ResultSet ----
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/minerva/jdbc/StatementInPool.java
  
  Index: StatementInPool.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.minerva.jdbc;
  
  import java.sql.*;
  
  /**
   * Wraps a Statement to track errors and the last used time for the owning
   * connection. That time is updated every time a SQL action is performed
   * (executeQuery, executeUpdate, etc.).
   * @version $Revision: 1.1 $
   * @author Aaron Mulder ([EMAIL PROTECTED])
   */
  public class StatementInPool implements Statement {
      private final static String CLOSED = "Statement has been closed!";
      private Statement impl;
      private ConnectionWrapper con;
  
      /**
       * Creates a new statement from a source statement and wrapper connection.
       */
      public StatementInPool(Statement source, ConnectionWrapper owner) {
          if(source == null || owner == null) throw new NullPointerException();
          impl = source;
          con = owner;
      }
  
      /**
       * Updates the last used time for the owning connection to the current time.
       */
      public void setLastUsed() {
          if(con != null)
              con.setLastUsed();
      }
  
      /**
       * Indicates that an error occured on the owning connection.
       */
      public void setError(SQLException e) {
          if(con != null)
              con.setError(e);
      }
  
      /**
       * Gets a reference to the "real" Statement.  This should only be used if
       * you need to cast that to a specific type to call a proprietary method -
       * you will defeat all the pooling if you use the underlying Statement
       * directly.
       */
      public Statement getUnderlyingStatement() {
          return impl;
      }
  
      // ---- Implementation of java.sql.Statement ----
  
      public void addBatch(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.addBatch(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void cancel() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.cancel();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void clearBatch() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.clearBatch();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void clearWarnings() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.clearWarnings();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void close() throws java.sql.SQLException {
          if(impl != null) {
              impl.close();
              con.statementClosed(this);
          }
          con = null;
          impl = null;
      }
  
      public boolean execute(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              setLastUsed();
              return impl.execute(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int[] executeBatch() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              setLastUsed();
              return impl.executeBatch();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public ResultSet executeQuery(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              setLastUsed();
              return new ResultSetInPool(impl.executeQuery(arg0), this);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int executeUpdate(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              setLastUsed();
              return impl.executeUpdate(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public Connection getConnection() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          return con;
      }
  
      public int getFetchDirection() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getFetchDirection();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getFetchSize() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getFetchSize();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getMaxFieldSize() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getMaxFieldSize();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getMaxRows() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getMaxRows();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public boolean getMoreResults() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getMoreResults();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getQueryTimeout() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getQueryTimeout();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public ResultSet getResultSet() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return new ResultSetInPool(impl.getResultSet(), this);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getResultSetConcurrency() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getResultSetConcurrency();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getResultSetType() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getResultSetType();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public int getUpdateCount() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getUpdateCount();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public java.sql.SQLWarning getWarnings() throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              return impl.getWarnings();
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setCursorName(String arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.setCursorName(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setEscapeProcessing(boolean arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.setEscapeProcessing(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setFetchDirection(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.setFetchDirection(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setFetchSize(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.setFetchSize(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setMaxFieldSize(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.setMaxFieldSize(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setMaxRows(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.setMaxRows(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      public void setQueryTimeout(int arg0) throws java.sql.SQLException {
          if(impl == null) throw new SQLException(CLOSED);
          try {
              impl.setQueryTimeout(arg0);
          } catch(SQLException e) {
              setError(e);
              throw e;
          }
      }
  
      // ---- End Implementation of java.sql.Statement ----
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/minerva/jdbc/package.html
  
  Index: package.html
  ===================================================================
  <HTML>
    <HEAD>
      <TITLE>Minerva Pools: Package org.jboss.minerva.jdbc</TITLE>
    </HEAD>
    <BODY BGCOLOR="WHITE">
      <P>Wrapper classes for JDBC objects.  These are used to track errors and
        last used times on a database connection (and derived statements,
        result sets, etc.).  Also tracks outstanding statements on a connection
        so they can be closed when the connection is returned to a pool.</P>
    </BODY>
  </HTML>
  
  

Reply via email to