ImportedAndExportedKeysSearchCallbackFilteredByPKs.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2005, 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.database.search;

  22. import java.sql.ResultSet;

  23. import org.dbunit.database.IDatabaseConnection;
  24. import org.dbunit.database.PrimaryKeyFilter;
  25. import org.dbunit.database.PrimaryKeyFilter.PkTableMap;
  26. import org.dbunit.dataset.filter.ITableFilter;
  27. import org.dbunit.util.search.IEdge;
  28. import org.dbunit.util.search.SearchException;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;

  31. /**
  32.  * Extension of the ImportedAndExportedKeysSearchCallback, where each new edge is
  33.  * added to a PrimaryKeyFilter.
  34.  *
  35.  * @author Felipe Leme (dbunit@felipeal.net)
  36.  * @version $Revision$
  37.  * @since Sep 9, 2005
  38.  */
  39. public class ImportedAndExportedKeysSearchCallbackFilteredByPKs extends ImportedAndExportedKeysSearchCallback
  40. {

  41.     /**
  42.      * Logger for this class
  43.      */
  44.     private static final Logger logger = LoggerFactory.getLogger(ImportedAndExportedKeysSearchCallbackFilteredByPKs.class);

  45.     // primary key filter associated with the call back
  46.     private final PrimaryKeyFilter pksFilter;

  47.     /**
  48.      * Default constructor.
  49.      *
  50.      * @param connection
  51.      *            database connection
  52.      * @param allowedPKs
  53.      *            map of allowed rows, based on the primary keys (key is the
  54.      *            name of a table; value is a Set with allowed primary keys for
  55.      *            that table)
  56.      */
  57.     public ImportedAndExportedKeysSearchCallbackFilteredByPKs(IDatabaseConnection connection, PkTableMap allowedPKs)
  58.     {
  59.         super(connection);
  60.         this.pksFilter = new PrimaryKeyFilter(connection, allowedPKs, true);
  61.     }

  62.     /**
  63.      * Get the primary key filter associated with the call back
  64.      *
  65.      * @return primary key filter associated with the call back
  66.      */
  67.     public ITableFilter getFilter()
  68.     {
  69.         return this.pksFilter;
  70.     }

  71.     public void nodeAdded(Object node) throws SearchException
  72.     {
  73.         logger.debug("nodeAdded(node={}) - start", node);
  74.         this.pksFilter.nodeAdded(node);
  75.     }

  76.     protected IEdge newEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException
  77.     {
  78.         if (logger.isDebugEnabled())
  79.         {
  80.             logger.debug("newEdge(rs={}, type={}, from={}, to={}, fkColumn={}, pkColumn={}) - start",
  81.                 new Object[] { rs, String.valueOf(type), from, to, fkColumn, pkColumn });
  82.         }

  83.         ForeignKeyRelationshipEdge edge = createFKEdge(rs, type, from, to, fkColumn, pkColumn);
  84.         this.pksFilter.edgeAdded(edge);
  85.         return edge;
  86.     }

  87. }