Package org.dbunit

Class DataSourceDatabaseTester

All Implemented Interfaces:
IDatabaseTester

public class DataSourceDatabaseTester extends AbstractDatabaseTester
DatabaseTester that uses a DataSource to create connections.
Since:
2.2.0
Version:
$Revision$ $Date$
Author:
Andres Almiray (aalmiray@users.sourceforge.net), Felipe Leme (dbunit@felipeal.net), Last changed by: $Author$
  • Constructor Details

    • DataSourceDatabaseTester

      public DataSourceDatabaseTester(DataSource dataSource)
      Creates a new DataSourceDatabaseTester with the specified DataSource.
      Parameters:
      dataSource - the DataSource to pull connections from
    • DataSourceDatabaseTester

      public DataSourceDatabaseTester(DataSource dataSource, String schema)
      Creates a new DataSourceDatabaseTester with the specified DataSource and schema name.
      Parameters:
      dataSource - the DataSource to pull connections from
      schema - The schema name to be used for new dbunit connections
      Since:
      2.4.5
    • DataSourceDatabaseTester

      public DataSourceDatabaseTester(DataSource dataSource, String schema, CachingConnectionProvider connectionProvider)
      Creates a new DataSourceDatabaseTester with the specified DataSource and schema name, reusing one IDatabaseConnection across calls via the given CachingConnectionProvider instead of creating a new one on every call.
      Share the same connectionProvider instance across the testers created for each test to get reuse across test methods; pair it with IOperationListener.NO_OP_OPERATION_LISTENER (or an equivalent non-closing listener) so the cached connection is not closed after every AbstractDatabaseTester.onSetup()/ AbstractDatabaseTester.onTearDown() call.
      Parameters:
      dataSource - the DataSource to pull connections from
      schema - The schema name to be used for new dbunit connections - can be null
      connectionProvider - caches and validates the connection across calls - can be null, in which case a new connection is created on every call as before
      Since:
      3.4.0
    • DataSourceDatabaseTester

      public DataSourceDatabaseTester(DataSource dataSource, String schema, CachingConnectionProvider connectionProvider, DatabaseConfig databaseConfig)
      Creates a new DataSourceDatabaseTester with the specified DataSource, schema name, optional CachingConnectionProvider, and optional DatabaseConfig whose property and feature values are applied to every connection this tester creates - for example to set DatabaseConfig.PROPERTY_DATATYPE_FACTORY for a specific database without needing an IOperationListener.
      Parameters:
      dataSource - The DataSource to pull connections from.
      schema - The schema name to be used for new dbunit connections - can be null.
      connectionProvider - Caches and validates the connection across calls - can be null, in which case a new connection is created on every call as before.
      databaseConfig - The property and feature values to apply to every connection this tester creates - can be null, in which case each connection keeps its own default DatabaseConfig.
      Since:
      3.5.0
  • Method Details

    • getConnection

      public IDatabaseConnection getConnection() throws Exception
      Description copied from interface: IDatabaseTester
      Returns the test database connection.
      Returns:
      the test database connection.
      Throws:
      Exception - if the connection cannot be retrieved or created.