1 21 22 package org.dbunit.dataset; 23 24 import org.dbunit.dataset.stream.IDataSetConsumer; 25 import org.dbunit.dataset.stream.IDataSetProducer; 26 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 37 public class CachedDataSet extends AbstractDataSet implements IDataSetConsumer 38 { 39 private ITable[] _tables; 40 41 private List _tableList; 42 private DefaultTable _activeTable; 43 44 47 public CachedDataSet() 48 { 49 } 50 51 54 public CachedDataSet(IDataSet dataSet) throws DataSetException 55 { 56 List tableList = new ArrayList (); 57 ITableIterator iterator = dataSet.iterator(); 58 while (iterator.next()) 59 { 60 tableList.add(new CachedTable(iterator.getTable())); 61 } 62 _tables = (ITable[])tableList.toArray(new ITable[0]); 63 } 64 65 68 public CachedDataSet(IDataSetProducer producer) throws DataSetException 69 { 70 producer.setConsumer(this); 71 producer.produce(); 72 } 73 74 77 protected ITableIterator createIterator(boolean reversed) 78 throws DataSetException 79 { 80 return new DefaultTableIterator(_tables, reversed); 81 } 82 83 86 public void startDataSet() throws DataSetException 87 { 88 _tableList = new ArrayList (); 89 _tables = null; 90 } 91 92 public void endDataSet() throws DataSetException 93 { 94 _tables = (ITable[])_tableList.toArray(new ITable[0]); 95 _tableList = null; 96 } 97 98 public void startTable(ITableMetaData metaData) throws DataSetException 99 { 100 _activeTable = new DefaultTable(metaData); 101 } 103 104 public void endTable() throws DataSetException 105 { 106 _tableList.add(_activeTable); 108 _activeTable = null; 109 } 110 111 public void row(Object [] values) throws DataSetException 112 { 113 _activeTable.addRow(values); 114 } 115 } 116 | Popular Tags |