CachedResultSetTable.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2002-2004, DbUnit.org
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2.1 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  *
  20.  */

  21. package org.dbunit.database;

  22. import org.dbunit.dataset.CachedTable;
  23. import org.dbunit.dataset.DataSetException;
  24. import org.dbunit.dataset.ITableMetaData;

  25. import java.sql.ResultSet;
  26. import java.sql.SQLException;

  27. /**
  28.  * @author Manuel Laflamme
  29.  * @version $Revision$
  30.  * @since Feb 20, 2002
  31.  */
  32. public class CachedResultSetTable extends CachedTable implements IResultSetTable
  33. {
  34.     /**
  35.      * @param metaData
  36.      * @param resultSet
  37.      * @throws SQLException
  38.      * @throws DataSetException
  39.      * @deprecated since 2.3.0 prefer direct usage of {@link ForwardOnlyResultSetTable#ForwardOnlyResultSetTable(ITableMetaData, ResultSet)} and then invoke {@link CachedResultSetTable#CachedResultSetTable(IResultSetTable)}
  40.      */
  41.     public CachedResultSetTable(ITableMetaData metaData, ResultSet resultSet)
  42.             throws SQLException, DataSetException
  43.     {
  44.         this(new ForwardOnlyResultSetTable(metaData, resultSet));
  45.     }

  46.     /**
  47.      * @param metaData
  48.      * @param connection
  49.      * @throws SQLException
  50.      * @throws DataSetException
  51.      * @deprecated since 2.4.4 prefer direct usage of {@link ForwardOnlyResultSetTable#ForwardOnlyResultSetTable(ITableMetaData, IDatabaseConnection)} and then invoke {@link CachedResultSetTable#CachedResultSetTable(IResultSetTable)}
  52.      */
  53.     public CachedResultSetTable(ITableMetaData metaData,
  54.             IDatabaseConnection connection) throws SQLException, DataSetException
  55.     {
  56.         this(new ForwardOnlyResultSetTable(metaData, connection));
  57.     }

  58.     public CachedResultSetTable(IResultSetTable table) throws DataSetException, SQLException
  59.     {
  60.         super(table.getTableMetaData());
  61.         try
  62.         {
  63.             addTableRows(table);
  64.         }
  65.         finally
  66.         {
  67.             table.close();
  68.         }
  69.     }

  70.     ////////////////////////////////////////////////////////////////////////////
  71.     // IResultSetTable interface

  72.     public void close() throws DataSetException
  73.     {
  74.         // nothing to do, resultset already been closed
  75.     }
  76. }