[BATCH-430] Incremental commit of exception moving

This commit is contained in:
nebhale
2008-03-07 11:54:20 +00:00
parent a60fc1e621
commit 8c2901093e
106 changed files with 736 additions and 848 deletions

View File

@@ -1,8 +1,8 @@
package org.springframework.batch.sample.dao;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.sample.domain.Game;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.util.Assert;

View File

@@ -1,8 +1,8 @@
package org.springframework.batch.sample.dao;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.sample.domain.PlayerSummary;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.util.Assert;

View File

@@ -4,8 +4,8 @@ import java.math.BigDecimal;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemRecoverer;
import org.springframework.batch.item.exception.MarkFailedException;
import org.springframework.batch.item.exception.ResetFailedException;
import org.springframework.batch.item.MarkFailedException;
import org.springframework.batch.item.ResetFailedException;
import org.springframework.batch.sample.domain.Trade;
/**

View File

@@ -3,8 +3,8 @@ package org.springframework.batch.sample.item.reader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.exception.MarkFailedException;
import org.springframework.batch.item.exception.ResetFailedException;
import org.springframework.batch.item.MarkFailedException;
import org.springframework.batch.item.ResetFailedException;
/**

View File

@@ -14,7 +14,7 @@ import org.springframework.batch.core.StepListener;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.item.ReaderNotOpenException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.sample.item.writer.StagingItemWriter;
import org.springframework.dao.OptimisticLockingFailureException;
@@ -41,9 +41,10 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
private volatile boolean initialized = false;
private volatile Iterator keys;
/**
* Public setter for the {@link LobHandler}.
*
* @param lobHandler the {@link LobHandler} to set (defaults to {@link DefaultLobHandler}).
*/
public void setLobHandler(LobHandler lobHandler) {
@@ -106,25 +107,25 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
return null;
}
Object result = getJdbcTemplate().queryForObject("SELECT VALUE FROM BATCH_STAGING WHERE ID=?",
new Object[] { id }, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
byte[] blob = lobHandler.getBlobAsBytes(rs, 1);
return SerializationUtils.deserialize(blob);
}
});
new Object[] { id }, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
byte[] blob = lobHandler.getBlobAsBytes(rs, 1);
return SerializationUtils.deserialize(blob);
}
});
// Update now - changes will rollback if there is a problem later.
int count = getJdbcTemplate().update("UPDATE BATCH_STAGING SET PROCESSED=? WHERE ID=? AND PROCESSED=?",
new Object[] { StagingItemWriter.DONE, id, StagingItemWriter.NEW });
new Object[] { StagingItemWriter.DONE, id, StagingItemWriter.NEW });
if (count != 1) {
throw new OptimisticLockingFailureException("The staging record with ID=" + id
+ " was updated concurrently when trying to mark as complete (updated " + count + " records.");
+ " was updated concurrently when trying to mark as complete (updated " + count + " records.");
}
return result;
}
private Long doRead() {
if (!initialized) {
throw new StreamException("ItemStream must be open before it can be read.");
throw new ReaderNotOpenException("ItemStream must be open before it can be read.");
}
Long key = getBuffer().next();
@@ -132,15 +133,14 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
synchronized (lock) {
if (keys.hasNext()) {
Assert.state(TransactionSynchronizationManager.isActualTransactionActive(),
"Transaction not active for this thread.");
"Transaction not active for this thread.");
Long next = (Long) keys.next();
getBuffer().add(next);
key = next;
logger.debug("Retrieved key from list: " + key);
}
}
}
else {
} else {
logger.debug("Retrieved key from buffer: " + key);
}
return key;
@@ -192,12 +192,9 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
}
/**
* Mark is supported in a multi- as well as a single-threaded environment.
* The state backing the mark is a buffer, and access is synchronized, so
* multiple threads can be accommodated. Buffers are stored as transaction
* resources (using
* {@link TransactionSynchronizationManager#bindResource(Object, Object)}),
* so they are thread bound.
* Mark is supported in a multi- as well as a single-threaded environment. The state backing the mark is a buffer,
* and access is synchronized, so multiple threads can be accommodated. Buffers are stored as transaction resources
* (using {@link TransactionSynchronizationManager#bindResource(Object, Object)}), so they are thread bound.
*
* @see org.springframework.batch.item.ItemReader#mark()
*/
@@ -222,21 +219,27 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
public void update(ExecutionContext executionContext) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.domain.StepListener#afterStep(StepExecution)
*/
public ExitStatus afterStep(StepExecution stepExecution) {
return null;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution)
*/
public void beforeStep(StepExecution stepExecution) {
this.stepExecution = stepExecution;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable)
*/
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {

View File

@@ -3,9 +3,9 @@ package org.springframework.batch.sample.item.writer;
import java.math.BigDecimal;
import org.springframework.batch.io.support.BatchSqlUpdateItemWriter;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.sample.domain.CustomerCredit;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

View File

@@ -15,9 +15,9 @@
*/
package org.springframework.batch.sample.item.writer;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
/**
* @author Dave Syer

View File

@@ -7,9 +7,9 @@ import java.sql.SQLException;
import org.apache.commons.lang.SerializationUtils;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.item.ClearFailedException;
import org.springframework.batch.item.FlushFailedException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.exception.ClearFailedException;
import org.springframework.batch.item.exception.FlushFailedException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.sample.tasklet;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.sample.dao.TradeDao;
import org.springframework.batch.sample.domain.Trade;
@@ -67,7 +67,7 @@ public class SimpleTradeWriter extends AbstractItemWriter implements ItemStream
this.tradeDao = tradeDao;
}
public void open(ExecutionContext context) throws StreamException {
public void open(ExecutionContext context) throws ItemStreamException {
}
/* (non-Javadoc)
@@ -77,6 +77,6 @@ public class SimpleTradeWriter extends AbstractItemWriter implements ItemStream
executionContext.putLong("trade.count", tradeCount);
}
public void close(ExecutionContext executionContext) throws StreamException {
public void close(ExecutionContext executionContext) throws ItemStreamException {
}
}