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: package org.dbunit.dataset;
022:
023: import org.slf4j.Logger;
024: import org.slf4j.LoggerFactory;
025:
026: /**
027: * Decorator that allows forward only access to decorated dataset.
028: *
029: * @author Manuel Laflamme
030: * @since Apr 9, 2003
031: * @version $Revision: 554 $
032: */
033: public class ForwardOnlyDataSet extends AbstractDataSet {
034:
035: /**
036: * Logger for this class
037: */
038: private static final Logger logger = LoggerFactory
039: .getLogger(ForwardOnlyDataSet.class);
040:
041: private final IDataSet _dataSet;
042: private int _iteratorCount;
043:
044: public ForwardOnlyDataSet(IDataSet dataSet) {
045: _dataSet = dataSet;
046: }
047:
048: ////////////////////////////////////////////////////////////////////////////
049: // AbstractDataSet class
050:
051: protected ITableIterator createIterator(boolean reversed)
052: throws DataSetException {
053: logger.debug("createIterator(reversed=" + reversed
054: + ") - start");
055:
056: if (reversed) {
057: throw new UnsupportedOperationException(
058: "Reverse iterator not supported!");
059: }
060:
061: if (_iteratorCount > 0) {
062: throw new UnsupportedOperationException(
063: "Only one iterator allowed!");
064: }
065:
066: return new ForwardOnlyIterator(_dataSet.iterator());
067: }
068:
069: ////////////////////////////////////////////////////////////////////////////
070: // IDataSet interface
071:
072: public String[] getTableNames() throws DataSetException {
073: logger.debug("getTableNames() - start");
074:
075: throw new UnsupportedOperationException();
076: }
077:
078: public ITableMetaData getTableMetaData(String tableName)
079: throws DataSetException {
080: logger.debug("getTableMetaData(tableName=" + tableName
081: + ") - start");
082:
083: throw new UnsupportedOperationException();
084: }
085:
086: public ITable getTable(String tableName) throws DataSetException {
087: logger.debug("getTable(tableName=" + tableName + ") - start");
088:
089: throw new UnsupportedOperationException();
090: }
091:
092: ////////////////////////////////////////////////////////////////////////////
093: // ForwardOnlyIterator class
094:
095: private class ForwardOnlyIterator implements ITableIterator {
096:
097: /**
098: * Logger for this class
099: */
100: private final Logger logger = LoggerFactory
101: .getLogger(ForwardOnlyIterator.class);
102:
103: private final ITableIterator _iterator;
104:
105: public ForwardOnlyIterator(ITableIterator iterator) {
106: _iterator = iterator;
107: _iteratorCount++;
108: }
109:
110: ////////////////////////////////////////////////////////////////////////////
111: // ITableIterator interface
112:
113: public boolean next() throws DataSetException {
114: logger.debug("next() - start");
115:
116: return _iterator.next();
117: }
118:
119: public ITableMetaData getTableMetaData()
120: throws DataSetException {
121: logger.debug("getTableMetaData() - start");
122:
123: return _iterator.getTableMetaData();
124: }
125:
126: public ITable getTable() throws DataSetException {
127: logger.debug("getTable() - start");
128:
129: return new ForwardOnlyTable(_iterator.getTable());
130: }
131: }
132: }
|