View Javadoc
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  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  /**
27   * @author Manuel Laflamme
28   * @version $Revision$
29   * @since Feb 17, 2002
30   */
31  public abstract class AbstractTable implements ITable {
32  
33      /**
34       * Logger for this class
35       */
36      private static final Logger logger =
37              LoggerFactory.getLogger(AbstractTable.class);
38  
39      protected void assertValidRowIndex(int row) throws DataSetException {
40          if (logger.isDebugEnabled()) {
41              logger.debug("assertValidRowIndex(row={}) - start", Integer
42                      .toString(row));
43          }
44  
45          assertValidRowIndex(row, getRowCount());
46      }
47  
48      protected void assertValidRowIndex(int row, int rowCount)
49              throws DataSetException {
50          if (logger.isDebugEnabled()) {
51              logger.debug("assertValidRowIndex(row={}, rowCount={}) - start",
52                      Integer.toString(row), Integer.toString(rowCount));
53          }
54  
55          if (row < 0) {
56              throw new RowOutOfBoundsException(row + " < 0");
57          }
58  
59          if (row >= rowCount) {
60              throw new RowOutOfBoundsException(row + " >= " + rowCount);
61          }
62      }
63  
64      protected void assertValidColumn(String columnName) throws DataSetException {
65          logger.debug("assertValidColumn(columnName={}) - start", columnName);
66  
67          ITableMetaData metaData = getTableMetaData();
68          // Try to find the column in the metadata - if it cannot be found an
69          // exception is thrown
70          Columns.getColumnValidated(columnName, metaData.getColumns(), metaData
71                  .getTableName());
72      }
73  
74      protected int getColumnIndex(String columnName) throws DataSetException {
75          logger.debug("getColumnIndex(columnName={}) - start", columnName);
76  
77          ITableMetaData metaData = getTableMetaData();
78          return metaData.getColumnIndex(columnName);
79      }
80  }