IN PROGRESS - issue BATCH-262: Hibernate Job blocks on flush

http://jira.springframework.org/browse/BATCH-262

Move session factory to parent context
This commit is contained in:
dsyer
2007-12-21 14:36:24 +00:00
parent 01f64f013f
commit c456d3b306
5 changed files with 112 additions and 93 deletions

View File

@@ -15,8 +15,22 @@
<property name="password" value="${batch.jdbc.password}" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingLocations" value="classpath*:/*.hbm.xml"/>
<property name="hibernateProperties">
<value>
<![CDATA[
hibernate.show_sql=true
hibernate.format_sql=true
]]>
</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Use this to set additional properties on beans at run time -->
@@ -66,4 +80,6 @@
<property name="incrementerName" value="BATCH_PARTITION_EXECUTION_SEQ" />
</bean>
<import resource="alt-data-source-context.xml" />
</beans>

View File

@@ -21,7 +21,8 @@
<property name="tasklet">
<bean
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
<property name="itemReader" ref="hibernateItemReader" />
<property name="itemReader"
ref="hibernateItemReader" />
<property name="itemProcessor">
<bean
class="org.springframework.batch.sample.item.processor.CustomerCreditIncreaseProcessor">
@@ -71,32 +72,12 @@
</bean>
<bean id="hibernateItemReader"
class="org.springframework.batch.io.cursor.HibernateCursorItemReader"
scope="step">
<aop:scoped-proxy />
class="org.springframework.batch.io.cursor.HibernateCursorItemReader" scope="step">
<aop:scoped-proxy/>
<property name="queryString" value="from CustomerCredit" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>CustomerCredit.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
<![CDATA[
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.HSQLDialect
]]>
</value>
</property>
</bean>
<bean parent="customEditorConfigurer" />
</beans>

View File

@@ -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

View File

@@ -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);