01: /*
02: *
03: * The DbUnit Database Testing Framework
04: * Copyright (C)2005, DbUnit.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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:
22: package org.dbunit.database.search;
23:
24: import org.slf4j.Logger;
25: import org.slf4j.LoggerFactory;
26:
27: import java.sql.ResultSet;
28: import java.util.Map;
29:
30: import org.dbunit.database.IDatabaseConnection;
31: import org.dbunit.database.PrimaryKeyFilter;
32: import org.dbunit.dataset.filter.ITableFilter;
33: import org.dbunit.util.search.IEdge;
34: import org.dbunit.util.search.SearchException;
35:
36: /**
37: * Extension of the ImportedKeysSearchCallback, where each new edge is added to a
38: * PrimaryKeyFilter.
39: * @author Felipe Leme <dbunit@felipeal.net>
40: * @version $Revision: 554 $
41: * @since Sep 9, 2005
42: */
43: public class ImportedKeysSearchCallbackFilteredByPKs extends
44: ImportedKeysSearchCallback {
45:
46: /**
47: * Logger for this class
48: */
49: private static final Logger logger = LoggerFactory
50: .getLogger(ImportedKeysSearchCallbackFilteredByPKs.class);
51:
52: // primary key filter associated with the call back
53: private final PrimaryKeyFilter pksFilter;
54:
55: /**
56: * Default constructor.
57: * @param connection database connection
58: * @param allowedPKs map of allowed rows, based on the primary keys (key is the name
59: * of a table; value is a Set with allowed primary keys for that table)
60: */
61: public ImportedKeysSearchCallbackFilteredByPKs(
62: IDatabaseConnection connection, Map allowedPKs) {
63: super (connection);
64: this .pksFilter = new PrimaryKeyFilter(connection, allowedPKs,
65: false);
66: }
67:
68: /**
69: * Get the primary key filter associated with the call back
70: * @return primary key filter associated with the call back
71: */
72: public ITableFilter getFilter() {
73: logger.debug("getFilter() - start");
74:
75: return this .pksFilter;
76: }
77:
78: public void nodeAdded(Object node) throws SearchException {
79: logger.debug("nodeAdded(node=" + node + ") - start");
80:
81: this .pksFilter.nodeAdded(node);
82: }
83:
84: protected IEdge newEdge(ResultSet rs, int type, String from,
85: String to, String fkColumn, String pkColumn)
86: throws SearchException {
87: logger.debug("newEdge(rs=" + rs + ", type=" + type + ", from="
88: + from + ", to=" + to + ", fkColumn=" + fkColumn
89: + ", pkColumn=" + pkColumn + ") - start");
90:
91: ForeignKeyRelationshipEdge edge = createFKEdge(rs, type, from,
92: to, fkColumn, pkColumn);
93: this.pksFilter.edgeAdded(edge);
94: return edge;
95: }
96:
97: }
|