001: /*
002: * AbstractTable.java Feb 17, 2002
003: *
004: * The DbUnit Database Testing Framework
005: * Copyright (C)2002-2004, DbUnit.org
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: */
022:
023: package org.dbunit.dataset;
024:
025: import org.slf4j.Logger;
026: import org.slf4j.LoggerFactory;
027:
028: /**
029: * @author Manuel Laflamme
030: * @version $Revision: 563 $
031: * @since Feb 17, 2002
032: */
033: public abstract class AbstractTable implements ITable {
034:
035: /**
036: * Logger for this class
037: */
038: private static final Logger logger = LoggerFactory
039: .getLogger(AbstractTable.class);
040:
041: protected void assertValidRowIndex(int row) throws DataSetException {
042: logger.debug("assertValidRowIndex(row=" + row + ") - start");
043:
044: assertValidRowIndex(row, getRowCount());
045: }
046:
047: protected void assertValidRowIndex(int row, int rowCount)
048: throws DataSetException {
049: logger.debug("assertValidRowIndex(row=" + row + ", rowCount="
050: + rowCount + ") - start");
051:
052: if (row < 0) {
053: throw new RowOutOfBoundsException(row + " < 0");
054: }
055:
056: if (row >= rowCount) {
057: throw new RowOutOfBoundsException(row + " >= " + rowCount);
058: }
059: }
060:
061: protected void assertValidColumn(String columnName)
062: throws DataSetException {
063: logger.debug("assertValidColumn(columnName=" + columnName
064: + ") - start");
065:
066: ITableMetaData metaData = getTableMetaData();
067: if (DataSetUtils.getColumn(columnName, metaData.getColumns()) == null) {
068: throw new NoSuchColumnException(metaData.getTableName()
069: + "." + columnName);
070: }
071: }
072:
073: protected int getColumnIndex(String columnName)
074: throws DataSetException {
075: logger.debug("getColumnIndex(columnName=" + columnName
076: + ") - start");
077:
078: ITableMetaData metaData = getTableMetaData();
079: Column[] columns = metaData.getColumns();
080: for (int i = 0; i < columns.length; i++) {
081: Column column = columns[i];
082: if (column.getColumnName().equalsIgnoreCase(columnName)) {
083: return i;
084: }
085: }
086:
087: throw new NoSuchColumnException(metaData.getTableName() + "."
088: + columnName);
089: }
090:
091: ////////////////////////////////////////////////////////////////////////////
092: // Object class
093:
094: // public String toString()
095: // {
096: //
097: // try
098: // {
099: // ITableMetaData metaData = getTableMetaData();
100: // String tableName = metaData.getTableName();
101: // String columns = Arrays.asList(metaData.getColumns()).toString();
102: //
103: // return "[name=" + tableName + ", rowCount=" + getRowCount() +
104: // ", columns=" + columns + "]";
105: // }
106: // catch (DataSetException e)
107: // {
108: // return super.toString();
109: // }
110: // }
111: }
|