KickJava   Java API By Example, From Geeks To Geeks.

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


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.dbunit.dataset.datatype.DataType;
24
25 /**
26  * @author Manuel Laflamme
27  * @since Apr 12, 2003
28  * @version $Revision: 1.2 $
29  */

30 public class MockTableMetaData extends AbstractTableMetaData
31 {
32     private String JavaDoc _tableName;
33     private Column[] _columns = new Column[0];
34     private String JavaDoc[] _keyNames = new String JavaDoc[0];
35
36     public MockTableMetaData()
37     {
38     }
39
40     public MockTableMetaData(String JavaDoc tableName, String JavaDoc[] columnNames)
41     {
42         _tableName = tableName;
43         setupColumns(columnNames);
44     }
45
46     public void setTableName(String JavaDoc tableName)
47     {
48         _tableName = tableName;
49     }
50
51     public void setupColumns(Column[] columns)
52     {
53         _columns = columns;
54     }
55
56     public void setupColumns(String JavaDoc[] columnNames)
57     {
58         Column[] columns = new Column[columnNames.length];
59         for (int i = 0; i < columnNames.length; i++)
60         {
61             String JavaDoc columnName = columnNames[i];
62             columns[i] = new Column(columnName, DataType.UNKNOWN);
63         }
64         _columns = columns;
65     }
66
67     public void setupPrimaryKeys(String JavaDoc[] keyNames)
68     {
69         _keyNames = keyNames;
70     }
71
72     ////////////////////////////////////////////////////////////////////////////
73
// ITableMetaData interface
74

75     public String JavaDoc getTableName()
76     {
77         return _tableName;
78     }
79
80     public Column[] getColumns() throws DataSetException
81     {
82         return _columns;
83     }
84
85     public Column[] getPrimaryKeys() throws DataSetException
86     {
87         return getPrimaryKeys(_columns, _keyNames);
88     }
89 }
90
Popular Tags