001: /*
002: *
003: * The DbUnit Database Testing Framework
004: * Copyright (C)2002-2004, DbUnit.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: */
021:
022: package org.dbunit.dataset;
023:
024: import org.slf4j.Logger;
025: import org.slf4j.LoggerFactory;
026:
027: /**
028: * Specialized IDataSet decorator that convert the table name and
029: * column names to lower case. Used in DbUnit own test suite to verify that
030: * operations are case insensitive.
031: *
032: * @author Manuel Laflamme
033: * @version $Revision: 554 $
034: * @since Feb 14, 2003
035: */
036: public class LowerCaseDataSet extends AbstractDataSet {
037:
038: /**
039: * Logger for this class
040: */
041: private static final Logger logger = LoggerFactory
042: .getLogger(LowerCaseDataSet.class);
043:
044: private final IDataSet _dataSet;
045:
046: public LowerCaseDataSet(ITable table) throws DataSetException {
047: this (new DefaultDataSet(table));
048: }
049:
050: public LowerCaseDataSet(ITable[] tables) throws DataSetException {
051: this (new DefaultDataSet(tables));
052: }
053:
054: public LowerCaseDataSet(IDataSet dataSet) throws DataSetException {
055: _dataSet = dataSet;
056: }
057:
058: private ITable createLowerTable(ITable table)
059: throws DataSetException {
060: logger.debug("createLowerTable(table=" + table + ") - start");
061:
062: return new CompositeTable(new LowerCaseTableMetaData(table
063: .getTableMetaData()), table);
064: }
065:
066: ////////////////////////////////////////////////////////////////////////////
067: // AbstractDataSet class
068:
069: protected ITableIterator createIterator(boolean reversed)
070: throws DataSetException {
071: logger.debug("createIterator(reversed=" + reversed
072: + ") - start");
073:
074: return new LowerCaseIterator(reversed ? _dataSet
075: .reverseIterator() : _dataSet.iterator());
076: }
077:
078: ////////////////////////////////////////////////////////////////////////////
079: // IDataSet interface
080:
081: public String[] getTableNames() throws DataSetException {
082: logger.debug("getTableNames() - start");
083:
084: String[] tableNames = super .getTableNames();
085: for (int i = 0; i < tableNames.length; i++) {
086: tableNames[i] = tableNames[i].toLowerCase();
087: }
088: return tableNames;
089: }
090:
091: public ITableMetaData getTableMetaData(String tableName)
092: throws DataSetException {
093: logger.debug("getTableMetaData(tableName=" + tableName
094: + ") - start");
095:
096: return new LowerCaseTableMetaData(super
097: .getTableMetaData(tableName));
098: }
099:
100: public ITable getTable(String tableName) throws DataSetException {
101: logger.debug("getTable(tableName=" + tableName + ") - start");
102:
103: return createLowerTable(super .getTable(tableName));
104: }
105:
106: ////////////////////////////////////////////////////////////////////////////
107: // LowerCaseIterator class
108:
109: private class LowerCaseIterator implements ITableIterator {
110:
111: /**
112: * Logger for this class
113: */
114: private final Logger logger = LoggerFactory
115: .getLogger(LowerCaseIterator.class);
116:
117: private final ITableIterator _iterator;
118:
119: public LowerCaseIterator(ITableIterator iterator) {
120: _iterator = iterator;
121: }
122:
123: ////////////////////////////////////////////////////////////////////////
124: // ITableIterator interface
125:
126: public boolean next() throws DataSetException {
127: logger.debug("next() - start");
128:
129: return _iterator.next();
130: }
131:
132: public ITableMetaData getTableMetaData()
133: throws DataSetException {
134: logger.debug("getTableMetaData() - start");
135:
136: return new LowerCaseTableMetaData(_iterator
137: .getTableMetaData());
138: }
139:
140: public ITable getTable() throws DataSetException {
141: logger.debug("getTable() - start");
142:
143: return createLowerTable(_iterator.getTable());
144: }
145: }
146: }
|