AbstractTable.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.dataset;

  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;

  24. /**
  25.  * @author Manuel Laflamme
  26.  * @version $Revision$
  27.  * @since Feb 17, 2002
  28.  */
  29. public abstract class AbstractTable implements ITable {

  30.     /**
  31.      * Logger for this class
  32.      */
  33.     private static final Logger logger =
  34.             LoggerFactory.getLogger(AbstractTable.class);

  35.     protected void assertValidRowIndex(int row) throws DataSetException {
  36.         if (logger.isDebugEnabled()) {
  37.             logger.debug("assertValidRowIndex(row={}) - start", Integer
  38.                     .toString(row));
  39.         }

  40.         assertValidRowIndex(row, getRowCount());
  41.     }

  42.     protected void assertValidRowIndex(int row, int rowCount)
  43.             throws DataSetException {
  44.         if (logger.isDebugEnabled()) {
  45.             logger.debug("assertValidRowIndex(row={}, rowCount={}) - start",
  46.                     Integer.toString(row), Integer.toString(rowCount));
  47.         }

  48.         if (row < 0) {
  49.             throw new RowOutOfBoundsException(row + " < 0");
  50.         }

  51.         if (row >= rowCount) {
  52.             throw new RowOutOfBoundsException(row + " >= " + rowCount);
  53.         }
  54.     }

  55.     protected void assertValidColumn(String columnName) throws DataSetException {
  56.         logger.debug("assertValidColumn(columnName={}) - start", columnName);

  57.         ITableMetaData metaData = getTableMetaData();
  58.         // Try to find the column in the metadata - if it cannot be found an
  59.         // exception is thrown
  60.         Columns.getColumnValidated(columnName, metaData.getColumns(), metaData
  61.                 .getTableName());
  62.     }

  63.     protected int getColumnIndex(String columnName) throws DataSetException {
  64.         logger.debug("getColumnIndex(columnName={}) - start", columnName);

  65.         ITableMetaData metaData = getTableMetaData();
  66.         return metaData.getColumnIndex(columnName);
  67.     }
  68. }