org.unitils.dbunit.util
Class DbUnitDatabaseConnection

java.lang.Object
  extended by org.dbunit.database.AbstractDatabaseConnection
      extended by org.unitils.dbunit.util.DbUnitDatabaseConnection
All Implemented Interfaces:
org.dbunit.database.IDatabaseConnection

public class DbUnitDatabaseConnection
extends org.dbunit.database.AbstractDatabaseConnection

Implementation of DBUnits IDatabaseConnection interface. This implementation returns connections from an underlying DataSource. This implementation stores the Connection that was retrieved last, to enable closing it (or returing it to the pool) using closeJdbcConnection().

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
DbUnitDatabaseConnection(DataSource dataSource, String schemaName)
          Creates a new instance that wraps the given DataSource
 
Method Summary
 void close()
          Method that is invoked by DBUnit when the connection is no longer needed.
 void closeJdbcConnection()
          Closes the Connection that was last retrieved using the getConnection() method
 Connection getConnection()
          Returns a Connection that can be used by DBUnit.
protected  Connection getNativeConnection(Connection connection)
           
 String getSchema()
           
 
Methods inherited from class org.dbunit.database.AbstractDatabaseConnection
createDataSet, createDataSet, createQueryTable, getConfig, getRowCount, getRowCount, getStatementFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbUnitDatabaseConnection

public DbUnitDatabaseConnection(DataSource dataSource,
                                String schemaName)
Creates a new instance that wraps the given DataSource

Parameters:
dataSource - The data source, not null
schemaName - The database schema, not null
Method Detail

close

public void close()
           throws SQLException
Method that is invoked by DBUnit when the connection is no longer needed. This method is not implemented, connections are 'closed' (returned to the connection pool) after every DBUnit operation

Throws:
SQLException

getSchema

public String getSchema()
Returns:
The database schema name

getConnection

public Connection getConnection()
                         throws SQLException
Returns a Connection that can be used by DBUnit. A reference to the connection is kept, to be able to 'close' it (return it to the connection pool) after the DBUnit operation finished. If an open connection is already in use by DBUnit, this connection is returned

Returns:
A JDBC connection
Throws:
SQLException

getNativeConnection

protected Connection getNativeConnection(Connection connection)
                                  throws SQLException
Parameters:
connection - The wrapper connection, not null
Returns:
The 'native' connection, which is wrapped by the given connection. Could be the supplied connection itself
Throws:
SQLException

closeJdbcConnection

public void closeJdbcConnection()
                         throws SQLException
Closes the Connection that was last retrieved using the getConnection() method

Throws:
SQLException - When connection close fails


Copyright © 2011. All Rights Reserved.