diff --git a/spring-batch-samples/.classpath b/spring-batch-samples/.classpath
index aaca6557d..0035b36f4 100644
--- a/spring-batch-samples/.classpath
+++ b/spring-batch-samples/.classpath
@@ -1,58 +1,59 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-batch-samples/src/main/resources/data-source-context.xml b/spring-batch-samples/src/main/resources/data-source-context.xml
index c790b12c6..425aa404a 100644
--- a/spring-batch-samples/src/main/resources/data-source-context.xml
+++ b/spring-batch-samples/src/main/resources/data-source-context.xml
@@ -15,8 +15,22 @@
-
+
+
+
+
+
+
+
+
+
+
+
@@ -66,4 +80,6 @@
+
+
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/resources/jobs/hibernateJob.xml b/spring-batch-samples/src/main/resources/jobs/hibernateJob.xml
index f2c9b14a4..5b923a40b 100644
--- a/spring-batch-samples/src/main/resources/jobs/hibernateJob.xml
+++ b/spring-batch-samples/src/main/resources/jobs/hibernateJob.xml
@@ -21,7 +21,8 @@
-
+
@@ -71,32 +72,12 @@
-
+ class="org.springframework.batch.io.cursor.HibernateCursorItemReader" scope="step">
+
-
-
-
-
- CustomerCredit.hbm.xml
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-batch-samples/src/main/resources/log4j.properties b/spring-batch-samples/src/main/resources/log4j.properties
index 4cc711578..be2eacd45 100644
--- a/spring-batch-samples/src/main/resources/log4j.properties
+++ b/spring-batch-samples/src/main/resources/log4j.properties
@@ -14,8 +14,8 @@ log4j.appender.chainsaw.layout=org.apache.log4j.xml.XMLLayout
### set log levels - for more verbose logging change 'info' to 'debug' ###
-log4j.rootLogger=info, stdout
-# log4j.rootLogger=info, stdout, chainsaw
+# log4j.rootLogger=info, stdout
+log4j.rootLogger=info, stdout, chainsaw
### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
@@ -24,6 +24,9 @@ log4j.rootLogger=info, stdout
### enable spring
log4j.logger.org.springframework=error
log4j.logger.org.springframework.batch.sample=info
+#log4j.logger.org.springframework.transaction=debug
+log4j.logger.org.springframework.jdbc.core=debug
+log4j.logger.org.springframework.orm=debug
### debug your specific package or classes with the following example
log4j.logger.org.springframework.batch.sample.module.OrderDataProvider=debug
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java
index 913d96e00..3a6c9ce19 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java
@@ -9,6 +9,10 @@ import java.util.List;
import org.springframework.batch.sample.item.processor.CustomerCreditIncreaseProcessor;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowMapper;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
/**
* Test case for jobs that are expected to update customer credit value by fixed
@@ -17,11 +21,12 @@ import org.springframework.jdbc.core.RowMapper;
* @author Robert Kasanicky
* @author Dave Syer
*/
-public abstract class AbstractCustomerCreditIncreaseTests extends
- AbstractValidatingBatchLauncherTests {
+public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValidatingBatchLauncherTests {
protected JdbcOperations jdbcTemplate;
+ protected PlatformTransactionManager transactionManager;
+
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT;
private static final String ALL_CUSTOMERS = "select * from CUSTOMER order by ID";
@@ -32,18 +37,33 @@ public abstract class AbstractCustomerCreditIncreaseTests extends
private List creditsBeforeUpdate;
+ /**
+ * @param jdbcTemplate
+ */
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
+ /**
+ * Public setter for the PlatformTransactionManager.
+ * @param transactionManager the transactionManager to set
+ */
+ public void setTransactionManager(PlatformTransactionManager transactionManager) {
+ this.transactionManager = transactionManager;
+ }
+
/**
* All customers have the same credit
*/
protected void validatePreConditions() throws Exception {
super.validatePreConditions();
- creditsBeforeUpdate = jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
- public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
- return rs.getBigDecimal(CREDIT_COLUMN);
+ creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
+ public Object doInTransaction(TransactionStatus status) {
+ return jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
+ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
+ return rs.getBigDecimal(CREDIT_COLUMN);
+ }
+ });
}
});
}
@@ -52,15 +72,14 @@ public abstract class AbstractCustomerCreditIncreaseTests extends
* Credit was increased by CREDIT_INCREASE
*/
protected void validatePostConditions() throws Exception {
-
+
final List matches = new ArrayList();
jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
final BigDecimal creditBeforeUpdate = (BigDecimal) creditsBeforeUpdate.get(rowNum);
- final BigDecimal expectedCredit = creditBeforeUpdate
- .add(CREDIT_INCREASE);
+ final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE);
if (expectedCredit.equals(rs.getBigDecimal(CREDIT_COLUMN))) {
matches.add(rs.getBigDecimal(ID_COLUMN));
}
@@ -68,7 +87,6 @@ public abstract class AbstractCustomerCreditIncreaseTests extends
}
});
-
assertEquals(getExpectedMatches(), matches.size());
checkMatches(matches);