public abstract class

AbstractTransactionalDataSourceSpringContextTests

extends AbstractTransactionalSpringContextTests
java.lang.Object
   ↳ junit.framework.Assert
     ↳ junit.framework.TestCase
       ↳ org.springframework.test.ConditionalTestCase
         ↳ org.springframework.test.AbstractSpringContextTests
           ↳ org.springframework.test.AbstractSingleSpringContextTests
             ↳ org.springframework.test.AbstractDependencyInjectionSpringContextTests
               ↳ org.springframework.test.AbstractTransactionalSpringContextTests
                 ↳ org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
Known Direct Subclasses
Known Indirect Subclasses

This class is deprecated.
as of Spring 3.0, in favor of using the listener-based test context framework (AbstractJUnit38SpringContextTests)

Class Overview

Subclass of AbstractTransactionalSpringContextTests that adds some convenience functionality for JDBC access. Expects a javax.sql.DataSource bean to be defined in the Spring application context.

This class exposes a JdbcTemplate and provides an easy way to delete from the database in a new transaction.

Summary

[Expand]
Inherited Constants
From class org.springframework.test.AbstractDependencyInjectionSpringContextTests
Fields
protected JdbcTemplate jdbcTemplate
[Expand]
Inherited Fields
From class org.springframework.test.AbstractTransactionalSpringContextTests
From class org.springframework.test.AbstractSingleSpringContextTests
From class org.springframework.test.ConditionalTestCase
Public Constructors
AbstractTransactionalDataSourceSpringContextTests()
Default constructor for AbstractTransactionalDataSourceSpringContextTests.
AbstractTransactionalDataSourceSpringContextTests(String name)
Constructor for AbstractTransactionalDataSourceSpringContextTests with a JUnit name.
Public Methods
final JdbcTemplate getJdbcTemplate()
Return the JdbcTemplate that this base class manages.
void setDataSource(DataSource dataSource)
Setter: DataSource is provided by Dependency Injection.
void setSqlScriptEncoding(String sqlScriptEncoding)
Specify the encoding for SQL scripts, if different from the platform encoding.
Protected Methods
int countRowsInTable(String tableName)
Count the rows in the given table
void deleteFromTables(String[] names)
Convenient method to delete all rows from these tables.
void executeSqlScript(String sqlResourcePath, boolean continueOnError)
Execute the given SQL script.
final void setComplete()
Overridden to prevent the transaction committing if a number of tables have been cleared, as a defensive measure against accidental permanent wiping of a database.
[Expand]
Inherited Methods
From class org.springframework.test.AbstractTransactionalSpringContextTests
From class org.springframework.test.AbstractDependencyInjectionSpringContextTests
From class org.springframework.test.AbstractSingleSpringContextTests
From class org.springframework.test.AbstractSpringContextTests
From class org.springframework.test.ConditionalTestCase
From class junit.framework.TestCase
From class junit.framework.Assert
From class java.lang.Object
From interface junit.framework.Test

Fields

protected JdbcTemplate jdbcTemplate

Public Constructors

public AbstractTransactionalDataSourceSpringContextTests ()

Default constructor for AbstractTransactionalDataSourceSpringContextTests.

public AbstractTransactionalDataSourceSpringContextTests (String name)

Constructor for AbstractTransactionalDataSourceSpringContextTests with a JUnit name.

Public Methods

public final JdbcTemplate getJdbcTemplate ()

Return the JdbcTemplate that this base class manages.

public void setDataSource (DataSource dataSource)

Setter: DataSource is provided by Dependency Injection.

public void setSqlScriptEncoding (String sqlScriptEncoding)

Specify the encoding for SQL scripts, if different from the platform encoding.

Protected Methods

protected int countRowsInTable (String tableName)

Count the rows in the given table

Parameters
tableName table name to count rows in
Returns
  • the number of rows in the table

protected void deleteFromTables (String[] names)

Convenient method to delete all rows from these tables. Calling this method will make avoidance of rollback by calling setComplete() impossible.

See Also

protected void executeSqlScript (String sqlResourcePath, boolean continueOnError)

Execute the given SQL script. Will be rolled back by default, according to the fate of the current transaction.

Parameters
sqlResourcePath Spring resource path for the SQL script. Should normally be loaded by classpath.

Statements should be delimited with a semicolon. If statements are not delimited with a semicolon then there should be one statement per line. Statements are allowed to span lines only if they are delimited with a semicolon.

Do not use this method to execute DDL if you expect rollback.

continueOnError whether or not to continue without throwing an exception in the event of an error
Throws
DataAccessException if there is an error executing a statement and continueOnError was false

protected final void setComplete ()

Overridden to prevent the transaction committing if a number of tables have been cleared, as a defensive measure against accidental permanent wiping of a database.

See Also