1 21 package org.dbunit.dataset.stream; 22 23 import org.dbunit.dataset.*; 24 25 26 31 public class DataSetProducerAdapter implements IDataSetProducer 32 { 33 private static final IDataSetConsumer EMPTY_CONSUMER = new DefaultConsumer(); 34 35 private final ITableIterator _iterator; 36 private IDataSetConsumer _consumer = EMPTY_CONSUMER; 37 38 public DataSetProducerAdapter(ITableIterator iterator) 39 { 40 _iterator = iterator; 41 } 42 43 public DataSetProducerAdapter(IDataSet dataSet) throws DataSetException 44 { 45 _iterator = dataSet.iterator(); 46 } 47 48 51 public void setConsumer(IDataSetConsumer consumer) throws DataSetException 52 { 53 _consumer = consumer; 54 } 55 56 public void produce() throws DataSetException 57 { 58 _consumer.startDataSet(); 59 while(_iterator.next()) 60 { 61 ITable table = _iterator.getTable(); 62 ITableMetaData metaData = table.getTableMetaData(); 63 64 _consumer.startTable(metaData); 65 try 66 { 67 Column[] columns = metaData.getColumns(); 68 if (columns.length == 0) 69 { 70 _consumer.endTable(); 71 continue; 72 } 73 74 for (int i = 0; ; i++) 75 { 76 Object [] values = new Object [columns.length]; 77 for (int j = 0; j < columns.length; j++) 78 { 79 Column column = columns[j]; 80 values[j] = table.getValue(i, column.getColumnName()); 81 } 82 _consumer.row(values); 83 } 84 } 85 catch (RowOutOfBoundsException e) 86 { 87 _consumer.endTable(); 89 } 90 } 91 _consumer.endDataSet(); 92 } 93 } 94 95 | Popular Tags |