org.springframework.test
Class AbstractTransactionalDataSourceSpringContextTests
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
- All Implemented Interfaces:
- junit.framework.Test
- Direct Known Subclasses:
- AbstractAnnotationAwareTransactionalTests
public abstract class AbstractTransactionalDataSourceSpringContextTests
- extends AbstractTransactionalSpringContextTests
Subclass of AbstractTransactionalSpringContextTests that adds some convenience
functionality for JDBC access. Expects a 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.
- Since:
- 1.1.1
- Author:
- Rod Johnson, Juergen Hoeller, Thomas Risberg
- See Also:
setDataSource(javax.sql.DataSource),
getJdbcTemplate()
|
Method Summary |
protected int |
countRowsInTable(String tableName)
Count the rows in the given table |
protected void |
deleteFromTables(String[] names)
Convenient method to delete all rows from these tables. |
protected void |
executeSqlScript(String sqlResourcePath,
boolean continueOnError)
Execute the given SQL script. |
JdbcTemplate |
getJdbcTemplate()
Return the JdbcTemplate that this base class manages. |
protected 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. |
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. |
| Methods inherited from class org.springframework.test.AbstractTransactionalSpringContextTests |
endTransaction, isDefaultRollback, isRollback, onSetUp, onSetUpBeforeTransaction, onSetUpInTransaction, onTearDown, onTearDownAfterTransaction, onTearDownInTransaction, preventTransaction, setDefaultRollback, setTransactionDefinition, setTransactionManager, startNewTransaction |
| Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests |
contextKey, createApplicationContext, createBeanDefinitionReader, customizeBeanFactory, getApplicationContext, getConfigLocations, getConfigPath, getConfigPaths, getLoadCount, loadContext, loadContextLocations, prepareApplicationContext, setDirty, setUp, tearDown |
| Methods inherited from class junit.framework.TestCase |
countTestCases, createResult, getName, run, run, runTest, setName, toString |
| Methods inherited from class junit.framework.Assert |
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format |
jdbcTemplate
protected JdbcTemplate jdbcTemplate
AbstractTransactionalDataSourceSpringContextTests
public AbstractTransactionalDataSourceSpringContextTests()
- Default constructor for AbstractTransactionalDataSourceSpringContextTests.
AbstractTransactionalDataSourceSpringContextTests
public AbstractTransactionalDataSourceSpringContextTests(String name)
- Constructor for AbstractTransactionalDataSourceSpringContextTests with a JUnit name.
setDataSource
public void setDataSource(DataSource dataSource)
- Setter: DataSource is provided by Dependency Injection.
getJdbcTemplate
public final JdbcTemplate getJdbcTemplate()
- Return the JdbcTemplate that this base class manages.
setSqlScriptEncoding
public void setSqlScriptEncoding(String sqlScriptEncoding)
- Specify the encoding for SQL scripts, if different from the platform encoding.
- See Also:
executeSqlScript(java.lang.String, boolean)
deleteFromTables
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:
setComplete()
setComplete
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.
- Overrides:
setComplete in class AbstractTransactionalSpringContextTests
- See Also:
AbstractTransactionalSpringContextTests.setComplete()
countRowsInTable
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
executeSqlScript
protected void executeSqlScript(String sqlResourcePath,
boolean continueOnError)
throws DataAccessException
- 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