View Javadoc
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  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  import org.dbunit.DatabaseUnitException;
27  import org.dbunit.database.DatabaseConfig;
28  import org.dbunit.database.DatabaseConnection;
29  import org.dbunit.dataset.DataSetException;
30  import org.dbunit.dataset.FilteredDataSet;
31  import org.dbunit.dataset.IDataSet;
32  import org.dbunit.dataset.filter.ExcludeTableFilter;
33  import org.dbunit.dataset.filter.ITableFilter;
34  
35  import java.sql.Connection;
36  import java.sql.SQLException;
37  
38  /**
39   * @author Manuel Laflamme
40   * @since May 19, 2003
41   * @version $Revision$
42   */
43  public class MsSqlConnection extends DatabaseConnection
44  {
45  
46      /**
47       * Logger for this class
48       */
49      private static final Logger logger = LoggerFactory.getLogger(MsSqlConnection.class);
50  
51      private final ITableFilter _filter = new ExcludeTableFilter(
52              new String[] {"dtproperties"});
53  
54      /**
55       * Creates a new <code>MsSqlConnection</code>.
56       *
57       * @param connection the adapted JDBC connection
58       * @param schema the database schema
59       * @throws DatabaseUnitException 
60       */
61      public MsSqlConnection(Connection connection, String schema) throws DatabaseUnitException
62      {
63          super(connection, schema);
64          getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
65                  new MsSqlDataTypeFactory());
66      }
67  
68      /**
69       * Creates a new <code>MsSqlConnection</code>.
70       *
71       * @param connection the adapted JDBC connection
72       * @throws DatabaseUnitException 
73       */
74      public MsSqlConnection(Connection connection) throws DatabaseUnitException
75      {
76          super(connection);
77          getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
78                  new MsSqlDataTypeFactory());
79      }
80  
81      ////////////////////////////////////////////////////////////////////////////
82      // IDatabaseConnection
83  
84      public IDataSet createDataSet() throws SQLException
85      {
86          logger.debug("createDataSet() - start");
87  
88          IDataSet dataSet = super.createDataSet();
89          return new FilteredDataSet(_filter, dataSet);
90      }
91  
92      public IDataSet createDataSet(String[] tableNames) throws SQLException, DataSetException
93      {
94          logger.debug("createDataSet(tableNames={}) - start", tableNames);
95  
96          IDataSet dataSet = super.createDataSet(tableNames);
97          return new FilteredDataSet(_filter, dataSet);
98      }
99  }