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: * @author Manuel Laflamme
029: * @version $Revision: 554 $
030: * @since Feb 19, 2003
031: */
032: public class SortedDataSet extends AbstractDataSet {
033:
034: /**
035: * Logger for this class
036: */
037: private static final Logger logger = LoggerFactory
038: .getLogger(SortedDataSet.class);
039:
040: private final IDataSet _dataSet;
041:
042: public SortedDataSet(IDataSet dataSet) throws DataSetException {
043: _dataSet = dataSet;
044: }
045:
046: ////////////////////////////////////////////////////////////////////////////
047: // AbstractDataSet class
048:
049: protected ITableIterator createIterator(boolean reversed)
050: throws DataSetException {
051: logger.debug("createIterator(reversed=" + reversed
052: + ") - start");
053:
054: return new SortedIterator(reversed ? _dataSet.reverseIterator()
055: : _dataSet.iterator());
056: }
057:
058: ////////////////////////////////////////////////////////////////////////////
059: // IDataSet interface
060:
061: public String[] getTableNames() throws DataSetException {
062: logger.debug("getTableNames() - start");
063:
064: return _dataSet.getTableNames();
065: }
066:
067: public ITableMetaData getTableMetaData(String tableName)
068: throws DataSetException {
069: logger.debug("getTableMetaData(tableName=" + tableName
070: + ") - start");
071:
072: return _dataSet.getTableMetaData(tableName);
073: }
074:
075: public ITable getTable(String tableName) throws DataSetException {
076: logger.debug("getTable(tableName=" + tableName + ") - start");
077:
078: return new SortedTable(_dataSet.getTable(tableName));
079: }
080:
081: ////////////////////////////////////////////////////////////////////////////
082: // SortedIterator class
083:
084: private class SortedIterator implements ITableIterator {
085:
086: /**
087: * Logger for this class
088: */
089: private final Logger logger = LoggerFactory
090: .getLogger(SortedIterator.class);
091:
092: private final ITableIterator _iterator;
093:
094: public SortedIterator(ITableIterator iterator) {
095: _iterator = iterator;
096: }
097:
098: ////////////////////////////////////////////////////////////////////////
099: // ITableIterator interface
100:
101: public boolean next() throws DataSetException {
102: logger.debug("next() - start");
103:
104: return _iterator.next();
105: }
106:
107: public ITableMetaData getTableMetaData()
108: throws DataSetException {
109: logger.debug("getTableMetaData() - start");
110:
111: return _iterator.getTableMetaData();
112: }
113:
114: public ITable getTable() throws DataSetException {
115: logger.debug("getTable() - start");
116:
117: return new SortedTable(_iterator.getTable());
118: }
119: }
120:
121: }
|