1 21 package org.dbunit.dataset.filter; 22 23 import org.dbunit.database.AmbiguousTableNameException; 24 import org.dbunit.dataset.*; 25 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 40 public class SequenceTableFilter implements ITableFilter 41 { 42 private final String [] _tableNames; 43 44 47 public SequenceTableFilter(String [] tableNames) 48 { 49 _tableNames = tableNames; 50 } 51 52 private boolean accept(String tableName, String [] tableNames, 53 boolean verifyDuplicate) throws AmbiguousTableNameException 54 { 55 boolean found = false; 56 for (int i = 0; i < tableNames.length; i++) 57 { 58 if (tableName.equalsIgnoreCase(tableNames[i])) 59 { 60 if (!verifyDuplicate) 61 { 62 return true; 63 } 64 65 if (found) 66 { 67 throw new AmbiguousTableNameException(tableName); 68 } 69 found = true; 70 } 71 } 72 73 return found; 74 } 75 76 79 public boolean accept(String tableName) throws DataSetException 80 { 81 return accept(tableName, _tableNames, true); 82 } 83 84 public String [] getTableNames(IDataSet dataSet) throws DataSetException 85 { 86 List nameList = new ArrayList (); 87 for (int i = 0; i < _tableNames.length; i++) 88 { 89 try 90 { 91 ITableMetaData metaData = dataSet.getTableMetaData(_tableNames[i]); 95 nameList.add(metaData.getTableName()); 96 } 97 catch (NoSuchTableException e) 98 { 99 } 102 } 103 104 return (String [])nameList.toArray(new String [0]); 105 } 106 107 public ITableIterator iterator(IDataSet dataSet, boolean reversed) 108 throws DataSetException 109 { 110 String [] tableNames = getTableNames(dataSet); 111 return new SequenceTableIterator(reversed ? 112 DataSetUtils.reverseStringArray(tableNames) : tableNames, dataSet); 113 } 114 } 115 116 | Popular Tags |