1 21 22 package org.dbunit.dataset; 23 24 29 public class CompositeTable extends AbstractTable 30 { 31 private final ITableMetaData _metaData; 32 private final ITable[] _tables; 33 34 38 public CompositeTable(ITableMetaData metaData, ITable table) 39 { 40 _metaData = metaData; 41 _tables = new ITable[]{table}; 42 } 43 44 48 public CompositeTable(ITableMetaData metaData, ITable[] tables) 49 { 50 _metaData = metaData; 51 _tables = tables; 52 } 53 54 58 public CompositeTable(ITable table1, ITable table2) 59 { 60 _metaData = table1.getTableMetaData(); 61 _tables = new ITable[]{table1, table2}; 62 } 63 64 68 public CompositeTable(String newName, ITable table) 69 throws DataSetException 70 { 71 ITableMetaData metaData = table.getTableMetaData(); 72 _metaData = new DefaultTableMetaData(newName, 73 metaData.getColumns(), metaData.getPrimaryKeys()); 74 _tables = new ITable[]{table}; 75 } 76 77 80 public ITableMetaData getTableMetaData() 81 { 82 return _metaData; 83 } 84 85 public int getRowCount() 86 { 87 int totalCount = 0; 88 for (int i = 0; i < _tables.length; i++) 89 { 90 ITable table = _tables[i]; 91 totalCount += table.getRowCount(); 92 } 93 94 return totalCount; 95 } 96 97 public Object getValue(int row, String column) throws DataSetException 98 { 99 if (row < 0) 100 { 101 throw new RowOutOfBoundsException(row + " < 0 "); 102 } 103 104 int totalCount = 0; 105 for (int i = 0; i < _tables.length; i++) 106 { 107 ITable table = _tables[i]; 108 109 int count = table.getRowCount(); 110 if (totalCount + count > row) 111 { 112 return table.getValue(row - totalCount, column); 113 } 114 totalCount += count; 115 } 116 117 throw new RowOutOfBoundsException(row + " > " + totalCount); 118 } 119 } 120 121 122 123 124 125 | Popular Tags |