当前页面:
在线文档首页 >
Spring Framework 2.1.0 API 文档英文版
AbstractTransactionalDataSourceSpringContextTests (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版
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:
- 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
- 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. |
Methods inherited from class org.springframework.test.AbstractTransactionalSpringContextTests |
endTransaction, onSetUp, onSetUpBeforeTransaction, onSetUpInTransaction, onTearDown, onTearDownAfterTransaction, onTearDownInTransaction, preventTransaction, setDefaultRollback, setTransactionDefinition, setTransactionManager, startNewTransaction |
Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests |
contextKey, createApplicationContext, customizeBeanFactory, getApplicationContext, getConfigLocations, getConfigPath, getConfigPaths, getLoadCount, loadContext, loadContextLocations, setDirty, setUp, tearDown |
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 |
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.
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. There should be one statement
per line. Any semicolons will be removed.
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
Copyright © 2002-2007 The Spring Framework.