KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > AbstractTable


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

22
23 package org.dbunit.dataset;
24
25
26 /**
27  * @author Manuel Laflamme
28  * @version $Revision: 1.13 $
29  * @since Feb 17, 2002
30  */

31 public abstract class AbstractTable implements ITable
32 {
33     protected void assertValidRowIndex(int row) throws DataSetException
34     {
35         assertValidRowIndex(row, getRowCount());
36     }
37
38     protected void assertValidRowIndex(int row, int rowCount)
39             throws DataSetException
40     {
41         if (row < 0)
42         {
43             throw new RowOutOfBoundsException(row + " < 0");
44         }
45
46         if (row >= rowCount)
47         {
48             throw new RowOutOfBoundsException(row + " > " + rowCount);
49         }
50     }
51
52     protected void assertValidColumn(String JavaDoc columnName) throws DataSetException
53     {
54         ITableMetaData metaData = getTableMetaData();
55         if (DataSetUtils.getColumn(columnName, metaData.getColumns()) == null)
56         {
57             throw new NoSuchColumnException(metaData.getTableName() + "." + columnName);
58         }
59     }
60
61     protected int getColumnIndex(String JavaDoc columnName) throws DataSetException
62     {
63         ITableMetaData metaData = getTableMetaData();
64         Column[] columns = metaData.getColumns();
65         for (int i = 0; i < columns.length; i++)
66         {
67             Column column = columns[i];
68             if (column.getColumnName().equalsIgnoreCase(columnName))
69             {
70                 return i;
71             }
72         }
73
74         throw new NoSuchColumnException(metaData.getTableName() + "." + columnName);
75     }
76
77     ////////////////////////////////////////////////////////////////////////////
78
// Object class
79

80 // public String toString()
81
// {
82
//
83
// try
84
// {
85
// ITableMetaData metaData = getTableMetaData();
86
// String tableName = metaData.getTableName();
87
// String columns = Arrays.asList(metaData.getColumns()).toString();
88
//
89
// return "[name=" + tableName + ", rowCount=" + getRowCount() +
90
// ", columns=" + columns + "]";
91
// }
92
// catch (DataSetException e)
93
// {
94
// return super.toString();
95
// }
96
// }
97
}
98
99
100
101
102
103
104
Popular Tags