|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
public abstract class AbstractTransactionalDataSourceSpringContextTests
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.
setDataSource(javax.sql.DataSource)
,
getJdbcTemplate()
Field Summary | |
---|---|
protected JdbcTemplate |
jdbcTemplate
|
Fields inherited from class org.springframework.test.AbstractTransactionalSpringContextTests |
---|
transactionDefinition, transactionManager, transactionStatus |
Fields inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests |
---|
AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_NO |
Fields inherited from class org.springframework.test.AbstractSingleSpringContextTests |
---|
applicationContext |
Fields inherited from class org.springframework.test.ConditionalTestCase |
---|
logger |
Constructor Summary | |
---|---|
AbstractTransactionalDataSourceSpringContextTests()
Default constructor for AbstractTransactionalDataSourceSpringContextTests. |
|
AbstractTransactionalDataSourceSpringContextTests(String name)
Constructor for AbstractTransactionalDataSourceSpringContextTests with a JUnit name. |
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.AbstractDependencyInjectionSpringContextTests |
---|
getAutowireMode, injectDependencies, isDependencyCheck, isPopulateProtectedVariables, prepareTestInstance, setAutowireMode, setDependencyCheck, setPopulateProtectedVariables |
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 org.springframework.test.AbstractSpringContextTests |
---|
addContext, contextKeyString, getContext, hasCachedContext, isContextKeyEmpty, setDirty |
Methods inherited from class org.springframework.test.ConditionalTestCase |
---|
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare |
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected JdbcTemplate jdbcTemplate
Constructor Detail |
---|
public AbstractTransactionalDataSourceSpringContextTests()
public AbstractTransactionalDataSourceSpringContextTests(String name)
Method Detail |
---|
public void setDataSource(DataSource dataSource)
public final JdbcTemplate getJdbcTemplate()
public void setSqlScriptEncoding(String sqlScriptEncoding)
executeSqlScript(java.lang.String, boolean)
protected void deleteFromTables(String[] names)
setComplete()
impossible.
setComplete()
protected final void setComplete()
setComplete
in class AbstractTransactionalSpringContextTests
AbstractTransactionalSpringContextTests.setComplete()
protected int countRowsInTable(String tableName)
tableName
- table name to count rows in
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException
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
DataAccessException
- if there is an error executing a statement
and continueOnError was false
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |