KickJava   Java API By Example, From Geeks To Geeks.

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


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 IDataSet decorator 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.3 $
32  * @since Feb 14, 2003
33  */

34 public class LowerCaseDataSet extends AbstractDataSet
35 {
36     private final IDataSet _dataSet;
37
38     public LowerCaseDataSet(ITable table) throws DataSetException
39     {
40         this(new DefaultDataSet(table));
41     }
42
43     public LowerCaseDataSet(ITable[] tables) throws DataSetException
44     {
45         this(new DefaultDataSet(tables));
46     }
47
48     public LowerCaseDataSet(IDataSet dataSet) throws DataSetException
49     {
50         _dataSet = dataSet;
51     }
52
53     private ITable createLowerTable(ITable table) throws DataSetException
54     {
55         return new CompositeTable(
56                 new LowerCaseTableMetaData(table.getTableMetaData()), table);
57     }
58
59     ////////////////////////////////////////////////////////////////////////////
60
// AbstractDataSet class
61

62     protected ITableIterator createIterator(boolean reversed)
63             throws DataSetException
64     {
65         return new LowerCaseIterator(reversed ?
66                 _dataSet.reverseIterator() : _dataSet.iterator());
67     }
68
69     ////////////////////////////////////////////////////////////////////////////
70
// IDataSet interface
71

72     public String JavaDoc[] getTableNames() throws DataSetException
73     {
74         String JavaDoc[] tableNames = super.getTableNames();
75         for (int i = 0; i < tableNames.length; i++)
76         {
77             tableNames[i] = tableNames[i].toLowerCase();
78         }
79         return tableNames;
80     }
81
82     public ITableMetaData getTableMetaData(String JavaDoc tableName) throws DataSetException
83     {
84         return new LowerCaseTableMetaData(super.getTableMetaData(tableName));
85     }
86
87     public ITable getTable(String JavaDoc tableName) throws DataSetException
88     {
89         return createLowerTable(super.getTable(tableName));
90     }
91
92     ////////////////////////////////////////////////////////////////////////////
93
// LowerCaseIterator class
94

95     private class LowerCaseIterator implements ITableIterator
96     {
97         private final ITableIterator _iterator;
98
99         public LowerCaseIterator(ITableIterator iterator)
100         {
101             _iterator = iterator;
102         }
103
104         ////////////////////////////////////////////////////////////////////////
105
// ITableIterator interface
106

107         public boolean next() throws DataSetException
108         {
109             return _iterator.next();
110         }
111
112         public ITableMetaData getTableMetaData() throws DataSetException
113         {
114             return new LowerCaseTableMetaData(_iterator.getTableMetaData());
115         }
116
117         public ITable getTable() throws DataSetException
118         {
119             return createLowerTable(_iterator.getTable());
120         }
121     }
122 }
123
124
125
126
127
128
129
Popular Tags