@ -33,17 +33,18 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
/ * *
/ * *
* Abstract { @link Transactional transactional } extension of
* Abstract { @linkplain Transactional transactional } extension of
* { @link AbstractJUnit4SpringContextTests } which adds convenience functionality
* { @link AbstractJUnit4SpringContextTests } which adds convenience functionality
* for JDBC access . Expects a { @link DataSource } bean and a
* for JDBC access . Expects a { @link DataSource } bean and a
* { @link PlatformTransactionManager } bean to be defined in the Spring
* { @link PlatformTransactionManager } bean to be defined in the Spring
* { @link ApplicationContext application context } .
* { @linkplain ApplicationContext application context } .
*
*
* < p > This class exposes a { @link JdbcTemplate } and provides an easy way
* < p > This class exposes a { @link JdbcTemplate } and provides an easy way to
* to { @link # countRowsInTable ( String ) count the number of rows in a table } ,
* { @linkplain # countRowsInTable count the number of rows in a table }
* { @link # deleteFromTables ( String . . . ) delete from tables } , and
* ( potentially { @linkplain # countRowsInTableWhere with a WHERE clause } ) ,
* { @link # executeSqlScript ( String , boolean ) execute SQL scripts } within a
* { @linkplain # deleteFromTables delete from tables } ,
* transaction .
* { @linkplain # dropTables drop tables } , and
* { @linkplain # executeSqlScript execute SQL scripts } within a transaction .
*
*
* < p > Concrete subclasses must fulfill the same requirements outlined in
* < p > Concrete subclasses must fulfill the same requirements outlined in
* { @link AbstractJUnit4SpringContextTests } .
* { @link AbstractJUnit4SpringContextTests } .
@ -86,6 +87,7 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
/ * *
/ * *
* The { @code JdbcTemplate } that this base class manages , available to subclasses .
* The { @code JdbcTemplate } that this base class manages , available to subclasses .
* @since 3 . 2
* /
* /
protected JdbcTemplate jdbcTemplate ;
protected JdbcTemplate jdbcTemplate ;
@ -120,6 +122,19 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
return JdbcTestUtils . countRowsInTable ( this . jdbcTemplate , tableName ) ;
return JdbcTestUtils . countRowsInTable ( this . jdbcTemplate , tableName ) ;
}
}
/ * *
* Count the rows in the given table , using the provided { @code WHERE } clause .
* < p > See the Javadoc for { @link JdbcTestUtils # countRowsInTableWhere ( ) } for details .
* @param tableName the name of the table to count rows in
* @param whereClause the { @code WHERE } clause to append to the query
* @return the number of rows in the table that match the provided
* { @code WHERE } clause
* @since 3 . 2
* /
protected int countRowsInTableWhere ( String tableName , String whereClause ) {
return JdbcTestUtils . countRowsInTableWhere ( this . jdbcTemplate , tableName , whereClause ) ;
}
/ * *
/ * *
* Convenience method for deleting all rows from the specified tables . Use
* Convenience method for deleting all rows from the specified tables . Use
* with caution outside of a transaction !
* with caution outside of a transaction !
@ -130,6 +145,16 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
return JdbcTestUtils . deleteFromTables ( this . jdbcTemplate , names ) ;
return JdbcTestUtils . deleteFromTables ( this . jdbcTemplate , names ) ;
}
}
/ * *
* Convenience method for dropping all of the specified tables . Use
* with caution outside of a transaction !
* @param names the names of the tables to drop
* @since 3 . 2
* /
protected void dropTables ( String . . . names ) {
JdbcTestUtils . dropTables ( this . jdbcTemplate , names ) ;
}
/ * *
/ * *
* Execute the given SQL script . Use with caution outside of a transaction !
* Execute the given SQL script . Use with caution outside of a transaction !
* < p > The script will normally be loaded by classpath . There should be one
* < p > The script will normally be loaded by classpath . There should be one