package com.dbxml.db.enterprise.dbfiler;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: DBFilerConnection.java,v 1.2 2004/02/12 00:17:57 bradford Exp $
 */

import java.sql.*;
import java.util.Map;

import com.dbxml.util.ObjectPool;
import com.dbxml.util.Poolable;

/**
 * DBFilerConnection is a pooled Connection wrapper that is used
 * by the DBFiler class.
 */

public final class DBFilerConnection implements Connection, Poolable {
   private ObjectPool pool;
   private Connection conn;

   public DBFilerConnection(Connection conn) {
      this.conn = conn;
   }

   public void setPool(ObjectPool pool) {
      this.pool = pool;
   }

   public void reclaim() {
      if ( isUsable() )
         pool.putObject(this);
   }

   public boolean isUsable() {
      try {
         conn.getMetaData();
         return true;
      }
      catch ( Exception e ) {
         return false;
      }
   }

   public void close() throws SQLException {
      reclaim();
   }

   public Map getTypeMap() throws SQLException {
      return conn.getTypeMap();
   }

   public void setTypeMap(Map map) throws SQLException {
      conn.setTypeMap(map);
   }

   public PreparedStatement prepareStatement(String sql, int type, int concurrency) throws SQLException {
      return conn.prepareStatement(sql, type, concurrency);
   }

   public PreparedStatement prepareStatement(String sql) throws SQLException {
      return conn.prepareStatement(sql);
   }

   public CallableStatement prepareCall(String sql, int type, int concurrency) throws SQLException {
      return conn.prepareCall(sql, type, concurrency);
   }

   public CallableStatement prepareCall(String sql) throws SQLException {
      return conn.prepareCall(sql);
   }

   public Statement createStatement(int type, int concurrency) throws SQLException {
      return conn.createStatement(type, concurrency);
   }

   public Statement createStatement() throws SQLException {
      return conn.createStatement();
   }

   public String nativeSQL(String sql) throws SQLException {
      return conn.nativeSQL(sql);
   }

   public void setAutoCommit(boolean autoCommit) throws SQLException {
      conn.setAutoCommit(autoCommit);
   }

   public boolean getAutoCommit() throws SQLException {
      return conn.getAutoCommit();
   }

   public void commit() throws SQLException {
      conn.commit();
   }

   public void rollback() throws SQLException {
      conn.rollback();
   }

   public boolean isClosed() throws SQLException {
      return conn.isClosed();
   }

   public DatabaseMetaData getMetaData() throws SQLException {
      return conn.getMetaData();
   }

   public void setReadOnly(boolean readOnly) throws SQLException {
      conn.setReadOnly(readOnly);
   }

   public boolean isReadOnly() throws SQLException {
      return conn.isReadOnly();
   }

   public void setCatalog(String catalog) throws SQLException {
      conn.setCatalog(catalog);
   }

   public String getCatalog() throws SQLException {
      return conn.getCatalog();
   }

   public void setTransactionIsolation(int level) throws SQLException {
      conn.setTransactionIsolation(level);
   }

   public int getTransactionIsolation() throws SQLException {
      return conn.getTransactionIsolation();
   }

   public SQLWarning getWarnings() throws SQLException {
      return conn.getWarnings();
   }

   public void clearWarnings() throws SQLException {
      conn.clearWarnings();
   }

   public void setHoldability(int holdability) throws SQLException {
      conn.setHoldability(holdability);
   }

   public int getHoldability() throws SQLException {
      return conn.getHoldability();
   }

   public Savepoint setSavepoint() throws SQLException {
      return conn.setSavepoint();
   }

   public Savepoint setSavepoint(String name) throws SQLException {
      return conn.setSavepoint(name);
   }

   public void rollback(Savepoint savepoint) throws SQLException {
      conn.rollback(savepoint);
   }

   public void releaseSavepoint(Savepoint savepoint) throws SQLException {
      conn.releaseSavepoint(savepoint);
   }

   public Statement createStatement(int type, int concurrency, int holdability) throws SQLException {
      return conn.createStatement(type, concurrency, holdability);
   }

   public PreparedStatement prepareStatement(String sql, int type, int concurrency, int holdability) throws SQLException {
      return conn.prepareStatement(sql, type, concurrency, holdability);
   }

   public CallableStatement prepareCall(String sql, int type, int concurrency, int holdability) throws SQLException {
      return conn.prepareCall(sql, type, concurrency, holdability);
   }

   public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
      return conn.prepareStatement(sql, autoGeneratedKeys);
   }

   public PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException {
      return conn.prepareStatement(sql, columnIndexes);
   }

   public PreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException {
      return conn.prepareStatement(sql, columnNames);
   }
   
   public int hashCode() {
      return conn.hashCode();
   }
   
   public boolean equals(Object obj) {
      return conn.equals(obj);
   }
   
   public String toString() {
      return conn.toString();
   }
}
