1 21 22 package org.dbunit.dataset; 23 24 import org.dbunit.dataset.filter.IColumnFilter; 25 26 import java.util.List ; 27 import java.util.ArrayList ; 28 29 34 public class FilteredTableMetaData extends AbstractTableMetaData 35 { 36 private final String _tableName; 37 private final Column[] _columns; 38 private final Column[] _primaryKeys; 39 40 public FilteredTableMetaData(ITableMetaData metaData, 41 IColumnFilter columnFilter) throws DataSetException 42 { 43 _tableName = metaData.getTableName(); 44 _columns = getFilteredColumns(_tableName, metaData.getColumns(), columnFilter); 45 _primaryKeys = getFilteredColumns(_tableName, metaData.getPrimaryKeys(), columnFilter); 46 } 47 48 public static Column[] getFilteredColumns(String tableName, 49 Column[] columns, IColumnFilter columnFilter) 50 { 51 if (columns == null) 52 { 53 return new Column[0]; 54 } 55 56 List columnList = new ArrayList (); 57 for (int i = 0; i < columns.length; i++) 58 { 59 Column column = columns[i]; 60 if (columnFilter.accept(tableName, column)) 61 { 62 columnList.add(column); 63 } 64 } 65 return (Column[])columnList.toArray(new Column[0]); 66 } 67 68 71 public String getTableName() 72 { 73 return _tableName; 74 } 75 76 public Column[] getColumns() throws DataSetException 77 { 78 return _columns; 79 } 80 81 public Column[] getPrimaryKeys() throws DataSetException 82 { 83 return _primaryKeys; 84 } 85 } 86 | Popular Tags |