MsSqlConnection.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.ext.mssql;

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

  24. import org.dbunit.DatabaseUnitException;
  25. import org.dbunit.database.DatabaseConfig;
  26. import org.dbunit.database.DatabaseConnection;
  27. import org.dbunit.dataset.DataSetException;
  28. import org.dbunit.dataset.FilteredDataSet;
  29. import org.dbunit.dataset.IDataSet;
  30. import org.dbunit.dataset.filter.ExcludeTableFilter;
  31. import org.dbunit.dataset.filter.ITableFilter;

  32. import java.sql.Connection;
  33. import java.sql.SQLException;

  34. /**
  35.  * @author Manuel Laflamme
  36.  * @since May 19, 2003
  37.  * @version $Revision$
  38.  */
  39. public class MsSqlConnection extends DatabaseConnection
  40. {

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

  45.     private final ITableFilter _filter = new ExcludeTableFilter(
  46.             new String[] {"dtproperties"});

  47.     /**
  48.      * Creates a new <code>MsSqlConnection</code>.
  49.      *
  50.      * @param connection the adapted JDBC connection
  51.      * @param schema the database schema
  52.      * @throws DatabaseUnitException
  53.      */
  54.     public MsSqlConnection(Connection connection, String schema) throws DatabaseUnitException
  55.     {
  56.         super(connection, schema);
  57.         getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
  58.                 new MsSqlDataTypeFactory());
  59.     }

  60.     /**
  61.      * Creates a new <code>MsSqlConnection</code>.
  62.      *
  63.      * @param connection the adapted JDBC connection
  64.      * @throws DatabaseUnitException
  65.      */
  66.     public MsSqlConnection(Connection connection) throws DatabaseUnitException
  67.     {
  68.         super(connection);
  69.         getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
  70.                 new MsSqlDataTypeFactory());
  71.     }

  72.     ////////////////////////////////////////////////////////////////////////////
  73.     // IDatabaseConnection

  74.     public IDataSet createDataSet() throws SQLException
  75.     {
  76.         logger.debug("createDataSet() - start");

  77.         IDataSet dataSet = super.createDataSet();
  78.         return new FilteredDataSet(_filter, dataSet);
  79.     }

  80.     public IDataSet createDataSet(String[] tableNames) throws SQLException, DataSetException
  81.     {
  82.         logger.debug("createDataSet(tableNames={}) - start", tableNames);

  83.         IDataSet dataSet = super.createDataSet(tableNames);
  84.         return new FilteredDataSet(_filter, dataSet);
  85.     }
  86. }