1 21 22 package org.dbunit.dataset; 23 24 import org.dbunit.database.AmbiguousTableNameException; 25 26 35 public class CaseInsensitiveDataSet extends AbstractDataSet 36 { 37 private final IDataSet _dataSet; 38 39 public CaseInsensitiveDataSet(IDataSet dataSet) 40 { 41 _dataSet = dataSet; 42 } 43 44 private String getInternalTableName(String tableName) throws DataSetException 45 { 46 String found = null; 47 String [] names = _dataSet.getTableNames(); 48 for (int i = 0; i < names.length; i++) 49 { 50 if (tableName.equalsIgnoreCase(names[i])) 51 { 52 if (found != null) 53 { 54 throw new AmbiguousTableNameException(tableName); 55 } 56 found = names[i]; 57 } 58 } 59 60 if (found != null) 61 { 62 return found; 63 } 64 65 throw new NoSuchTableException(tableName); 66 } 67 68 71 protected ITableIterator createIterator(boolean reversed) 72 throws DataSetException 73 { 74 return new CaseInsensitiveIterator(reversed ? 75 _dataSet.reverseIterator() : _dataSet.iterator()); 76 } 77 78 81 public String [] getTableNames() throws DataSetException 82 { 83 return _dataSet.getTableNames(); 84 } 85 86 public ITableMetaData getTableMetaData(String tableName) 87 throws DataSetException 88 { 89 return _dataSet.getTableMetaData(getInternalTableName(tableName)); 90 } 91 92 public ITable getTable(String tableName) throws DataSetException 93 { 94 ITable table = _dataSet.getTable(getInternalTableName(tableName)); 95 return new CaseInsensitiveTable(table); 96 } 97 98 101 private class CaseInsensitiveIterator implements ITableIterator 102 { 103 private final ITableIterator _iterator; 104 105 public CaseInsensitiveIterator(ITableIterator iterator) 106 { 107 _iterator = iterator; 108 } 109 110 113 public boolean next() throws DataSetException 114 { 115 return _iterator.next(); 116 } 117 118 public ITableMetaData getTableMetaData() throws DataSetException 119 { 120 return _iterator.getTableMetaData(); 121 } 122 123 public ITable getTable() throws DataSetException 124 { 125 return new CaseInsensitiveTable(_iterator.getTable()); 126 } 127 } 128 } 129 130 131 132 | Popular Tags |