DefaultTableFilter.java

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

  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;

  24. import org.dbunit.dataset.DataSetException;

  25. /**
  26.  * This filter exposes only tables matching include patterns and not matching
  27.  * exclude patterns. This implementation do not modify the original table
  28.  * sequence from the filtered dataset and support duplicate table names.
  29.  *
  30.  * @author Manuel Laflamme
  31.  * @since Apr 17, 2004
  32.  * @version $Revision$
  33.  */
  34. public class DefaultTableFilter extends AbstractTableFilter implements ITableFilter
  35. {

  36.     /**
  37.      * Logger for this class
  38.      */
  39.     private static final Logger logger = LoggerFactory.getLogger(DefaultTableFilter.class);

  40.     private final IncludeTableFilter _includeFilter = new IncludeTableFilter();
  41.     private final ExcludeTableFilter _excludeFilter = new ExcludeTableFilter();

  42.     /**
  43.      * Add a new accepted table name pattern.
  44.      * The following wildcard characters are supported:
  45.      * '*' matches zero or more characters,
  46.      * '?' matches one character.
  47.      */
  48.     public void includeTable(String patternName)
  49.     {
  50.         logger.debug("includeTable(patternName=" + patternName + ") - start");

  51.         _includeFilter.includeTable(patternName);
  52.     }

  53.     /**
  54.      * Add a new refused table pattern name.
  55.      * The following wildcard characters are supported:
  56.      * '*' matches zero or more characters,
  57.      * '?' matches one character.
  58.      */
  59.     public void excludeTable(String patternName)
  60.     {
  61.         logger.debug("excludeTable(patternName=" + patternName + ") - start");

  62.         _excludeFilter.excludeTable(patternName);
  63.     }

  64.     ////////////////////////////////////////////////////////////////////////////
  65.     // AbstractTableFilter interface

  66.     public boolean isValidName(String tableName) throws DataSetException
  67.     {
  68.         logger.debug("isValidName(tableName=" + tableName + ") - start");

  69.         if (_includeFilter.isEmpty() || _includeFilter.accept(tableName))
  70.         {
  71.             return _excludeFilter.accept(tableName);
  72.         }
  73.         return false;
  74.     }
  75. }