KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.dbunit.dataset;
22
23 /**
24  * Decorator that allows forward only access to decorated dataset.
25  *
26  * @author Manuel Laflamme
27  * @since Apr 9, 2003
28  * @version $Revision: 1.3 $
29  */

30 public class ForwardOnlyDataSet extends AbstractDataSet
31 {
32     private final IDataSet _dataSet;
33     private int _iteratorCount;
34
35     public ForwardOnlyDataSet(IDataSet dataSet)
36     {
37         _dataSet = dataSet;
38     }
39
40     ////////////////////////////////////////////////////////////////////////////
41
// AbstractDataSet class
42

43     protected ITableIterator createIterator(boolean reversed)
44             throws DataSetException
45     {
46         if (reversed)
47         {
48             throw new UnsupportedOperationException JavaDoc(
49                     "Reverse iterator not supported!");
50         }
51
52         if (_iteratorCount > 0)
53         {
54             throw new UnsupportedOperationException JavaDoc(
55                     "Only one iterator allowed!");
56         }
57
58         return new ForwardOnlyIterator(_dataSet.iterator());
59     }
60
61     ////////////////////////////////////////////////////////////////////////////
62
// IDataSet interface
63

64     public String JavaDoc[] getTableNames() throws DataSetException
65     {
66         throw new UnsupportedOperationException JavaDoc();
67     }
68
69     public ITableMetaData getTableMetaData(String JavaDoc tableName) throws DataSetException
70     {
71         throw new UnsupportedOperationException JavaDoc();
72     }
73
74     public ITable getTable(String JavaDoc tableName) throws DataSetException
75     {
76         throw new UnsupportedOperationException JavaDoc();
77     }
78
79     ////////////////////////////////////////////////////////////////////////////
80
// ForwardOnlyIterator class
81

82     private class ForwardOnlyIterator implements ITableIterator
83     {
84         private final ITableIterator _iterator;
85
86         public ForwardOnlyIterator(ITableIterator iterator)
87         {
88             _iterator = iterator;
89             _iteratorCount++;
90         }
91
92         ////////////////////////////////////////////////////////////////////////////
93
// ITableIterator interface
94

95         public boolean next() throws DataSetException
96         {
97             return _iterator.next();
98         }
99
100         public ITableMetaData getTableMetaData() throws DataSetException
101         {
102             return _iterator.getTableMetaData();
103         }
104
105         public ITable getTable() throws DataSetException
106         {
107             return new ForwardOnlyTable(_iterator.getTable());
108         }
109     }
110 }
111
Popular Tags