KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 package org.dbunit.dataset;
23
24
25 /**
26  * Specialized ITableMetaData implementation that convert the table name and
27  * column names to lower case. Used in DbUnit own test suite to verify that
28  * operations are case insensitive.
29  *
30  * @author Manuel Laflamme
31  * @version $Revision: 1.2 $
32  * @since Feb 14, 2003
33  */

34 public class LowerCaseTableMetaData extends AbstractTableMetaData
35 {
36     private final String JavaDoc _tableName;
37     private final Column[] _columns;
38     private final Column[] _primaryKeys;
39
40     public LowerCaseTableMetaData(String JavaDoc tableName, Column[] columns)
41             //throws DataSetException
42
{
43         this(tableName, columns, new Column[0]);
44     }
45
46     public LowerCaseTableMetaData(String JavaDoc tableName, Column[] columns,
47             String JavaDoc[] primaryKeys) //throws DataSetException
48
{
49         this(tableName, columns, getPrimaryKeys(columns, primaryKeys));
50     }
51
52     public LowerCaseTableMetaData(ITableMetaData metaData) throws DataSetException
53     {
54         this(metaData.getTableName(), metaData.getColumns(),
55                 metaData.getPrimaryKeys());
56     }
57
58     public LowerCaseTableMetaData(String JavaDoc tableName, Column[] columns,
59             Column[] primaryKeys) //throws DataSetException
60
{
61         _tableName = tableName.toLowerCase();
62         _columns = createLowerColumns(columns);
63         _primaryKeys = createLowerColumns(primaryKeys);
64     }
65
66     private Column[] createLowerColumns(Column[] columns)
67     {
68         Column[] lowerColumns = new Column[columns.length];
69         for (int i = 0; i < columns.length; i++)
70         {
71             lowerColumns[i] = createLowerColumn(columns[i]);
72         }
73
74         return lowerColumns;
75     }
76
77     private Column createLowerColumn(Column column)
78     {
79         return new Column(
80                 column.getColumnName().toLowerCase(),
81                 column.getDataType(),
82                 column.getSqlTypeName(),
83                 column.getNullable());
84     }
85
86     ////////////////////////////////////////////////////////////////////////////
87
// ITableMetaData interface
88

89     public String JavaDoc getTableName()
90     {
91         return _tableName;
92     }
93
94     public Column[] getColumns()
95     {
96         return _columns;
97     }
98
99     public Column[] getPrimaryKeys()
100     {
101         return _primaryKeys;
102     }
103 }
104
105
106
107
108
109
Popular Tags