KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author Manuel Laflamme
27  * @version $Revision: 1.3 $
28  * @since Feb 19, 2003
29  */

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

42     protected ITableIterator createIterator(boolean reversed)
43             throws DataSetException
44     {
45         return new SortedIterator(reversed ?
46                 _dataSet.reverseIterator() : _dataSet.iterator());
47     }
48
49     ////////////////////////////////////////////////////////////////////////////
50
// IDataSet interface
51

52     public String JavaDoc[] getTableNames() throws DataSetException
53     {
54         return _dataSet.getTableNames();
55     }
56
57     public ITableMetaData getTableMetaData(String JavaDoc tableName) throws DataSetException
58     {
59         return _dataSet.getTableMetaData(tableName);
60     }
61
62     public ITable getTable(String JavaDoc tableName) throws DataSetException
63     {
64         return new SortedTable(_dataSet.getTable(tableName));
65     }
66
67     ////////////////////////////////////////////////////////////////////////////
68
// SortedIterator class
69

70     private class SortedIterator implements ITableIterator
71     {
72         private final ITableIterator _iterator;
73
74         public SortedIterator(ITableIterator iterator)
75         {
76             _iterator = iterator;
77         }
78
79         ////////////////////////////////////////////////////////////////////////
80
// ITableIterator interface
81

82         public boolean next() throws DataSetException
83         {
84             return _iterator.next();
85         }
86
87         public ITableMetaData getTableMetaData() throws DataSetException
88         {
89             return _iterator.getTableMetaData();
90         }
91
92         public ITable getTable() throws DataSetException
93         {
94             return new SortedTable(_iterator.getTable());
95         }
96     }
97
98 }
99
100
101
102
103
104
105
Popular Tags