1 /*
2 *
3 * The DbUnit Database Testing Framework
4 * Copyright (C)2002-2008, DbUnit.org
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21 package org.dbunit.dataset;
22
23 import org.dbunit.dataset.filter.IColumnFilter;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28 * A table that filters some columns out from the original table.
29 *
30 * @author gommma (gommma AT users.sourceforge.net)
31 * @author Last changed by: $Author$
32 * @version $Revision$ $Date$
33 * @since 2.4.0
34 */
35 public class ColumnFilterTable implements ITable
36 {
37 /**
38 * logger
39 */
40 private final Logger logger = LoggerFactory.getLogger(ColumnFilterTable.class);
41
42 /**
43 * reference to the original table being wrapped
44 */
45 private final ITable originalTable;
46
47 /**
48 * The filtered table metadata
49 */
50 private final ITableMetaData tableMetaData;
51
52
53 /**
54 * @param table The table from which some columns should be filtered
55 * @param columnFilter The filter defining which columns to be filtered
56 * @throws DataSetException
57 */
58 public ColumnFilterTable(ITable table, IColumnFilter columnFilter)
59 throws DataSetException
60 {
61 if (columnFilter == null) {
62 throw new NullPointerException(
63 "The parameter 'columnFilter' must not be null");
64 }
65 if (table == null) {
66 throw new NullPointerException(
67 "The parameter 'table' must not be null");
68 }
69
70 this.tableMetaData = new FilteredTableMetaData(
71 table.getTableMetaData(), columnFilter);
72 this.originalTable = table;
73 }
74
75
76 public int getRowCount()
77 {
78 logger.debug("getRowCount() - start");
79 return this.originalTable.getRowCount();
80 }
81
82 public ITableMetaData getTableMetaData()
83 {
84 logger.debug("getTableMetaData() - start");
85 return this.tableMetaData;
86 }
87
88 public Object getValue(int row, String column) throws DataSetException
89 {
90 if(logger.isDebugEnabled())
91 logger.debug("getValue(row={}, columnName={}) - start", Integer.toString(row), column);
92
93 return this.originalTable.getValue(row, column);
94 }
95
96 public ITableMetaData getOriginalMetaData()
97 {
98 logger.debug("getOriginalMetaData() - start");
99 return this.originalTable.getTableMetaData();
100 }
101
102 public String toString()
103 {
104 return this.originalTable.toString();
105 }
106 }