1 21 22 package org.dbunit.dataset; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import java.util.ListIterator ; 27 28 35 public class CompositeDataSet extends AbstractDataSet 36 { 37 private ITable[] _tables; 38 39 43 public CompositeDataSet(IDataSet[] dataSets) throws DataSetException 44 { 45 this(dataSets, true); 46 } 47 48 57 public CompositeDataSet(IDataSet[] dataSets, boolean combine) 58 throws DataSetException 59 { 60 List tableList = new ArrayList (); 61 for (int i = 0; i < dataSets.length; i++) 62 { 63 IDataSet dataSet = dataSets[i]; 64 ITableIterator iterator = dataSet.iterator(); 65 while(iterator.next()) 66 { 67 addTable(iterator.getTable(), tableList, combine); 68 } 69 } 70 71 _tables = (ITable[])tableList.toArray(new ITable[0]); 72 } 73 74 78 public CompositeDataSet(IDataSet dataSet1, IDataSet dataSet2) 79 throws DataSetException 80 { 81 this(new IDataSet[]{dataSet1, dataSet2}); 82 } 83 84 95 public CompositeDataSet(IDataSet dataSet1, IDataSet dataSet2, boolean combine) 96 throws DataSetException 97 { 98 this(new IDataSet[]{dataSet1, dataSet2}, combine); 99 } 100 101 112 public CompositeDataSet(IDataSet dataSet, boolean combine) 113 throws DataSetException 114 { 115 this(new IDataSet[]{dataSet}, combine); 116 } 117 118 124 public CompositeDataSet(IDataSet dataSet) throws DataSetException 125 { 126 this(new IDataSet[]{dataSet}, true); 127 } 128 129 133 public CompositeDataSet(ITable[] tables) throws DataSetException 134 { 135 List tableList = new ArrayList (); 136 for (int i = 0; i < tables.length; i++) 137 { 138 addTable(tables[i], tableList, true); 139 } 140 141 _tables = (ITable[])tableList.toArray(new ITable[0]); 142 } 143 144 private void addTable(ITable newTable, List tableList, boolean combine) 145 { 146 if (!combine) 148 { 149 tableList.add(newTable); 150 return; 151 } 152 153 String tableName = newTable.getTableMetaData().getTableName(); 155 for (ListIterator it = tableList.listIterator(); it.hasNext();) 156 { 157 ITable table = (ITable)it.next(); 158 if (tableName.equalsIgnoreCase(table.getTableMetaData().getTableName())) 159 { 160 it.set(new CompositeTable(table, newTable)); 162 return; 163 } 164 } 165 166 tableList.add(newTable); 168 } 169 170 173 protected ITableIterator createIterator(boolean reversed) 174 throws DataSetException 175 { 176 return new DefaultTableIterator(_tables, reversed); 177 } 178 } 179 180 181 182 183 184 185 186 | Popular Tags |