Fix batch update job sample

This commit is contained in:
dsyer
2008-07-23 11:41:27 +00:00
parent 408f37e0c7
commit 7a106162c8
10 changed files with 65 additions and 214 deletions

View File

@@ -3,7 +3,6 @@ package org.springframework.batch.sample.item.reader;
import java.math.BigDecimal;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemRecoverer;
import org.springframework.batch.item.MarkFailedException;
import org.springframework.batch.item.ResetFailedException;
import org.springframework.batch.sample.domain.Trade;
@@ -13,7 +12,7 @@ import org.springframework.batch.sample.domain.Trade;
*
* @author Robert Kasanicky
*/
public class GeneratingItemReader implements ItemReader<Trade>, ItemRecoverer {
public class GeneratingItemReader implements ItemReader<Trade> {
private int limit = 1;
@@ -49,13 +48,6 @@ public class GeneratingItemReader implements ItemReader<Trade>, ItemRecoverer {
return limit;
}
/* (non-Javadoc)
* @see org.springframework.batch.item.ItemRecoverer#recover(java.lang.Object, java.lang.Throwable)
*/
public Object recover(Object data, Throwable cause) {
return data;
}
/* (non-Javadoc)
* @see org.springframework.batch.item.ItemStream#mark()
*/

View File

@@ -1,59 +0,0 @@
package org.springframework.batch.sample.item.writer;
import java.math.BigDecimal;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.database.BatchSqlUpdateItemWriter;
import org.springframework.batch.sample.domain.CustomerCredit;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
/**
* Increases customer's credit by fixed amount, delegating to a
* {@link BatchSqlUpdateItemWriter} to push the result out to persistent
* storage.
*
* @author Dave Syer
*/
public class BatchSqlCustomerCreditIncreaseWriter implements ItemWriter<CustomerCredit>, InitializingBean {
private ItemWriter<CustomerCredit> delegate;
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
/**
* Public setter for the {@link ItemWriter}, which must be an instance of
* {@link BatchSqlUpdateItemWriter}.
* @param delegate the delegate to set
*/
public void setDelegate(ItemWriter<CustomerCredit> delegate) {
this.delegate = delegate;
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.state(delegate instanceof BatchSqlUpdateItemWriter, "Delegate must be set and must be an instance of BatchSqlUpdateItemWriter");
}
/*
* (non-Javadoc)
* @see org.springframework.batch.item.processor.DelegatingItemWriter#doProcess(java.lang.Object)
*/
public void write(CustomerCredit customerCredit) throws Exception {
delegate.write(customerCredit);
}
public void clear() throws ClearFailedException {
delegate.clear();
}
public void flush() throws FlushFailedException {
delegate.flush();
}
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.batch.sample.item.writer;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -27,12 +28,14 @@ import org.springframework.batch.sample.domain.CustomerCredit;
*/
public class CustomerCreditUpdatePreparedStatementSetter implements ItemPreparedStatementSetter {
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
/* (non-Javadoc)
* @see org.springframework.batch.io.support.ItemPreparedStatementSetter#setValues(java.lang.Object, java.sql.PreparedStatement)
*/
public void setValues(Object item, PreparedStatement ps) throws SQLException {
CustomerCredit customerCredit = (CustomerCredit) item;
ps.setBigDecimal(1, customerCredit.getCredit());
ps.setBigDecimal(1, customerCredit.getCredit().add(FIXED_AMOUNT));
ps.setLong(2, customerCredit.getId());
}