001: /*
002: *
003: * The DbUnit Database Testing Framework
004: * Copyright (C)2005, DbUnit.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: */
021:
022: package org.dbunit.database.search;
023:
024: import org.slf4j.Logger;
025: import org.slf4j.LoggerFactory;
026:
027: import java.sql.ResultSet;
028: import java.util.Map;
029:
030: import org.dbunit.database.IDatabaseConnection;
031: import org.dbunit.database.PrimaryKeyFilter;
032: import org.dbunit.dataset.filter.ITableFilter;
033: import org.dbunit.util.search.IEdge;
034: import org.dbunit.util.search.SearchException;
035:
036: /**
037: * Extension of the ImportedAndExportedKeysSearchCallback, where each new edge is
038: * added to a PrimaryKeyFilter.
039: * @author Felipe Leme <dbunit@felipeal.net>
040: * @version $Revision: 554 $
041: * @since Sep 9, 2005
042: * @author Felipe Leme <dbunit@felipeal.net>
043: * @version $Revision: 554 $
044: * @since Sep 9, 2005
045: */
046: public class ImportedAndExportedKeysSearchCallbackFilteredByPKs extends
047: ImportedAndExportedKeysSearchCallback {
048:
049: /**
050: * Logger for this class
051: */
052: private static final Logger logger = LoggerFactory
053: .getLogger(ImportedAndExportedKeysSearchCallbackFilteredByPKs.class);
054:
055: // primary key filter associated with the call back
056: private final PrimaryKeyFilter pksFilter;
057:
058: /**
059: * Default constructor.
060: * @param connection database connection
061: * @param allowedPKs map of allowed rows, based on the primary keys (key is the name
062: * of a table; value is a Set with allowed primary keys for that table)
063: */
064: public ImportedAndExportedKeysSearchCallbackFilteredByPKs(
065: IDatabaseConnection connection, Map allowedPKs) {
066: super (connection);
067: this .pksFilter = new PrimaryKeyFilter(connection, allowedPKs,
068: true);
069: }
070:
071: /**
072: * Get the primary key filter associated with the call back
073: * @return primary key filter associated with the call back
074: */
075: public ITableFilter getFilter() {
076: logger.debug("getFilter() - start");
077:
078: return this .pksFilter;
079: }
080:
081: public void nodeAdded(Object node) throws SearchException {
082: logger.debug("nodeAdded(node=" + node + ") - start");
083:
084: this .pksFilter.nodeAdded(node);
085: }
086:
087: protected IEdge newEdge(ResultSet rs, int type, String from,
088: String to, String fkColumn, String pkColumn)
089: throws SearchException {
090: logger.debug("newEdge(rs=" + rs + ", type=" + type + ", from="
091: + from + ", to=" + to + ", fkColumn=" + fkColumn
092: + ", pkColumn=" + pkColumn + ") - start");
093:
094: ForeignKeyRelationshipEdge edge = createFKEdge(rs, type, from,
095: to, fkColumn, pkColumn);
096: this.pksFilter.edgeAdded(edge);
097: return edge;
098: }
099:
100: }
|