Purge StreamContext some more
This commit is contained in:
@@ -172,7 +172,7 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current row number wrapped as <code>StreamContext</code>
|
||||
* @return the current row number wrapped as {@link ExecutionAttributes}
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
Properties props = new Properties();
|
||||
@@ -232,22 +232,20 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
lastCommitRowNumber = currentProcessedRow;
|
||||
if (!useStatelessSession) {
|
||||
statefulSession.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
currentProcessedRow = lastCommitRowNumber;
|
||||
if (lastCommitRowNumber == 0) {
|
||||
cursor.beforeFirst();
|
||||
|
||||
@@ -232,7 +232,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
|
||||
* Mark the current row. Calling reset will cause the result set to be set
|
||||
* to the current row when mark was called.
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
lastCommittedRow = currentProcessedRow;
|
||||
skippedRows.clear();
|
||||
}
|
||||
@@ -242,7 +242,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
|
||||
*
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
try {
|
||||
currentProcessedRow = lastCommittedRow;
|
||||
if (currentProcessedRow > 0) {
|
||||
@@ -385,10 +385,8 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.restart.Restartable#getStreamContext()
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
String skipped = skippedRows.toString();
|
||||
@@ -399,9 +397,8 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
|
||||
return context;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#restoreFrom(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
Assert.state(!initialized);
|
||||
|
||||
@@ -170,9 +170,9 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
*/
|
||||
public final void restoreFrom(ExecutionAttributes data) {
|
||||
|
||||
Assert.notNull(data, "StreamContext must not be null.");
|
||||
Assert.notNull(data, "ExecutionAttributes must not be null.");
|
||||
Assert.notNull(data.getProperties(),
|
||||
"StreamContext properties must not be null.");
|
||||
"ExecutionAttributes properties must not be null.");
|
||||
Assert.state(!initialized,
|
||||
"Cannot restore when already intialized. Call"
|
||||
+ " close() first before restore()");
|
||||
@@ -190,7 +190,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
}
|
||||
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return keyGenerator.getKeyAsStreamContext(getCurrentKey());
|
||||
return keyGenerator.getKeyAsExecutionAttributes(getCurrentKey());
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@@ -235,16 +235,16 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
lastCommitIndex = currentIndex;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
keysIterator = keys.listIterator(lastCommitIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,19 +20,19 @@ public interface KeyGenerator {
|
||||
/**
|
||||
* Restore the keys list based on provided restart data.
|
||||
*
|
||||
* @param streamContext, the restart data to restore the keys list from.
|
||||
* @param executionAttributes, the restart data to restore the keys list from.
|
||||
* @return a list of keys.
|
||||
* @throws IllegalArgumentException is streamContext is null.
|
||||
* @throws IllegalArgumentException is executionAttributes is null.
|
||||
*/
|
||||
List restoreKeys(ExecutionAttributes streamContext);
|
||||
List restoreKeys(ExecutionAttributes executionAttributes);
|
||||
|
||||
/**
|
||||
* Return the provided key as restart data.
|
||||
*
|
||||
* @param key to be converted to restart data.
|
||||
* @return StreamContext representation of the key.
|
||||
* @return {@link ExecutionAttributes} representation of the key.
|
||||
* @throws IllegalArgumentException if key is null.
|
||||
* @throws IllegalArgumentException if key is an incompatible type.
|
||||
*/
|
||||
ExecutionAttributes getKeyAsStreamContext(Object key);
|
||||
ExecutionAttributes getKeyAsExecutionAttributes(Object key);
|
||||
}
|
||||
|
||||
@@ -32,15 +32,15 @@ import org.springframework.util.ClassUtils;
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
* @see StreamContextRowMapper
|
||||
* @see ExecutionAttributesRowMapper
|
||||
*/
|
||||
public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implements StreamContextRowMapper{
|
||||
public class ColumnMapExecutionAttributesRowMapper extends ColumnMapRowMapper implements ExecutionAttributesRowMapper {
|
||||
|
||||
public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapStreamContextRowMapper.class) + ".KEY.";
|
||||
public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapExecutionAttributesRowMapper.class) + ".KEY.";
|
||||
|
||||
public PreparedStatementSetter createSetter(ExecutionAttributes streamContext) {
|
||||
public PreparedStatementSetter createSetter(ExecutionAttributes executionAttributes) {
|
||||
|
||||
ColumnMapStreamContext columnData = new ColumnMapStreamContext(streamContext.getProperties());
|
||||
ColumnMapExecutionAttributes columnData = new ColumnMapExecutionAttributes(executionAttributes.getProperties());
|
||||
|
||||
List columns = new ArrayList();
|
||||
for (Iterator iterator = columnData.keys.entrySet().iterator(); iterator.hasNext();) {
|
||||
@@ -52,21 +52,21 @@ public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implemen
|
||||
return new ArgPreparedStatementSetter(columns.toArray());
|
||||
}
|
||||
|
||||
public ExecutionAttributes createStreamContext(Object key) {
|
||||
Assert.isInstanceOf(Map.class, key, "Input to create StreamContext must be of type Map.");
|
||||
public ExecutionAttributes createExecutionAttributes(Object key) {
|
||||
Assert.isInstanceOf(Map.class, key, "Input to create ExecutionAttributes must be of type Map.");
|
||||
Map keys = (Map) key;
|
||||
return new ColumnMapStreamContext(keys);
|
||||
return new ColumnMapExecutionAttributes(keys);
|
||||
}
|
||||
|
||||
private static class ColumnMapStreamContext extends ExecutionAttributes {
|
||||
private static class ColumnMapExecutionAttributes extends ExecutionAttributes {
|
||||
|
||||
private final Map keys;
|
||||
|
||||
public ColumnMapStreamContext(Map keys) {
|
||||
public ColumnMapExecutionAttributes(Map keys) {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public ColumnMapStreamContext(Properties props) {
|
||||
public ColumnMapExecutionAttributes(Properties props) {
|
||||
|
||||
keys = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(props.size());
|
||||
|
||||
@@ -31,23 +31,23 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
* @see RowMapper
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface StreamContextRowMapper extends RowMapper {
|
||||
public interface ExecutionAttributesRowMapper extends RowMapper {
|
||||
|
||||
/**
|
||||
* Given the provided composite key, return a RestartData representation.
|
||||
*
|
||||
* @param key
|
||||
* @return ResartData representing the composite key.
|
||||
* @return ExecutionAttributes representing the composite key.
|
||||
* @throws IllegalArgumentException if key is null or of an unsupported type.
|
||||
*/
|
||||
public ExecutionAttributes createStreamContext(Object key);
|
||||
public ExecutionAttributes createExecutionAttributes(Object key);
|
||||
|
||||
/**
|
||||
* Given the provided restart data, return a PreparedStatementSeter that can
|
||||
* be used as parameters to a JdbcTemplate.
|
||||
*
|
||||
* @param streamContext
|
||||
* @param executionAttributes
|
||||
* @return an array of objects that can be used as arguments to a JdbcTemplate.
|
||||
*/
|
||||
public PreparedStatementSetter createSetter(ExecutionAttributes streamContext);
|
||||
public PreparedStatementSetter createSetter(ExecutionAttributes executionAttributes);
|
||||
}
|
||||
@@ -39,11 +39,10 @@ public class IbatisKeyGenerator implements KeyGenerator {
|
||||
return sqlMapClientTemplate.queryForList(drivingQuery);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* @see org.springframework.batch.restart.Restartable#getRestartData()
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsExecutionAttributes(java.lang.Object)
|
||||
*/
|
||||
public ExecutionAttributes getKeyAsStreamContext(Object key) {
|
||||
public ExecutionAttributes getKeyAsExecutionAttributes(Object key) {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(RESTART_KEY, key.toString());
|
||||
ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* <p>Jdbc implementation of the {@link KeyGenerator} interface that works for composite keys.
|
||||
* (i.e. keys represented by multiple columns) A sql query to be used to return the keys and
|
||||
* a {@link StreamContextRowMapper} to map each row in the resultset to an Object must be set in
|
||||
* a {@link ExecutionAttributesRowMapper} to map each row in the resultset to an Object must be set in
|
||||
* order to work correctly.
|
||||
* </p>
|
||||
*
|
||||
@@ -43,7 +43,7 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private StreamContextRowMapper keyMapper = new ColumnMapStreamContextRowMapper();
|
||||
private ExecutionAttributesRowMapper keyMapper = new ColumnMapExecutionAttributesRowMapper();
|
||||
|
||||
private String sql;
|
||||
|
||||
@@ -78,27 +78,27 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#restoreKeys(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#restoreKeys(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public List restoreKeys(ExecutionAttributes streamContext) {
|
||||
public List restoreKeys(ExecutionAttributes executionAttributes) {
|
||||
|
||||
Assert.state(keyMapper != null, "KeyMapper must not be null.");
|
||||
Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty" +
|
||||
" in order to restart.");
|
||||
|
||||
if (streamContext.getProperties() != null) {
|
||||
return jdbcTemplate.query(restartSql, keyMapper.createSetter(streamContext), keyMapper);
|
||||
if (executionAttributes.getProperties() != null) {
|
||||
return jdbcTemplate.query(restartSql, keyMapper.createSetter(executionAttributes), keyMapper);
|
||||
}
|
||||
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsStreamContext(java.lang.Object)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsExecutionAttributes(java.lang.Object)
|
||||
*/
|
||||
public ExecutionAttributes getKeyAsStreamContext(Object key) {
|
||||
public ExecutionAttributes getKeyAsExecutionAttributes(Object key) {
|
||||
Assert.state(keyMapper != null, "Kye mapper must not be null.");
|
||||
return keyMapper.createStreamContext(key);
|
||||
return keyMapper.createExecutionAttributes(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,12 +121,12 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link StreamContextRowMapper} to be used to map a resultset
|
||||
* Set the {@link ExecutionAttributesRowMapper} to be used to map a resultset
|
||||
* to keys.
|
||||
*
|
||||
* @param keyMapper
|
||||
*/
|
||||
public void setKeyMapper(StreamContextRowMapper keyMapper) {
|
||||
public void setKeyMapper(ExecutionAttributesRowMapper keyMapper) {
|
||||
this.keyMapper = keyMapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,10 +95,10 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
|
||||
/**
|
||||
* Get the restart data representing the last processed key.
|
||||
*
|
||||
* @see KeyGenerator#getKeyAsStreamContext(Object)
|
||||
* @see KeyGenerator#getKeyAsExecutionAttributes(Object)
|
||||
* @throws IllegalArgumentException if key is null.
|
||||
*/
|
||||
public ExecutionAttributes getKeyAsStreamContext(Object key) {
|
||||
public ExecutionAttributes getKeyAsExecutionAttributes(Object key) {
|
||||
Assert.notNull(key, "The key must not be null.");
|
||||
ExecutionAttributes context = new ExecutionAttributes();
|
||||
context.putString(RESTART_KEY, key.toString());
|
||||
@@ -112,19 +112,19 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
|
||||
* KeyGenerationStrategy as the one being restored from</strong> otherwise
|
||||
* it is invalid.
|
||||
*
|
||||
* @param ExecutionAttributes obtained by calling
|
||||
* {@link #getKeyAsStreamContext(Object)} during a previous run.
|
||||
* @param executionAttributes {@link ExecutionAttributes} obtained by calling
|
||||
* {@link #getKeyAsExecutionAttributes(Object)} during a previous run.
|
||||
* @throws IllegalStateException if restart sql statement is null.
|
||||
* @throws IllegalArgumentException if restart data is null.
|
||||
* @see KeyGenerator#restoreKeys(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public List restoreKeys(ExecutionAttributes streamContext) {
|
||||
public List restoreKeys(ExecutionAttributes executionAttributes) {
|
||||
|
||||
Assert.notNull(streamContext, "The restart data must not be null.");
|
||||
Assert.notNull(executionAttributes, "The restart data must not be null.");
|
||||
Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty"
|
||||
+ " in order to restart.");
|
||||
|
||||
String lastProcessedKey = streamContext.getProperties().getProperty(RESTART_KEY);
|
||||
String lastProcessedKey = executionAttributes.getProperties().getProperty(RESTART_KEY);
|
||||
|
||||
if (lastProcessedKey != null) {
|
||||
return jdbcTemplate.query(restartSql, new Object[] { lastProcessedKey }, keyMapper);
|
||||
|
||||
@@ -94,10 +94,10 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
|
||||
if (reader == null) {
|
||||
throw new StreamException("ItemStream not open or already closed.");
|
||||
}
|
||||
ExecutionAttributes streamContext = new ExecutionAttributes();
|
||||
streamContext.putLong(READ_STATISTICS_NAME, reader.getCurrentLineCount());
|
||||
streamContext.putLong(SKIPPED_STATISTICS_NAME, skippedLines.size());
|
||||
return streamContext;
|
||||
ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
executionAttributes.putLong(READ_STATISTICS_NAME, reader.getCurrentLineCount());
|
||||
executionAttributes.putLong(SKIPPED_STATISTICS_NAME, skippedLines.size());
|
||||
return executionAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,19 +112,17 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
getReader().mark();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
getReader().reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
|
||||
private Resource resource;
|
||||
|
||||
private ExecutionAttributes streamContext = new ExecutionAttributes();
|
||||
private ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
|
||||
private OutputState state = null;
|
||||
|
||||
@@ -250,10 +250,10 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
if (state == null) {
|
||||
throw new StreamException("ItemStream not open or already closed.");
|
||||
}
|
||||
streamContext.putLong(RESTART_DATA_NAME, state.position());
|
||||
streamContext.putLong(WRITTEN_STATISTICS_NAME, state.linesWritten);
|
||||
streamContext.putLong(RESTART_COUNT_STATISTICS_NAME, state.restartCount);
|
||||
return streamContext;
|
||||
executionAttributes.putLong(RESTART_DATA_NAME, state.position());
|
||||
executionAttributes.putLong(WRITTEN_STATISTICS_NAME, state.linesWritten);
|
||||
executionAttributes.putLong(RESTART_COUNT_STATISTICS_NAME, state.restartCount);
|
||||
return executionAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -550,16 +550,16 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
getOutputState().mark();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
getOutputState().checkFileSize();
|
||||
resetPositionForRestart();
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ public abstract class AbstractTransactionalIoSource extends ItemStreamAdapter {
|
||||
*
|
||||
* @see TransactionSynchronization#afterCompletion
|
||||
*/
|
||||
public abstract void mark(ExecutionAttributes streamContext);
|
||||
public abstract void mark(ExecutionAttributes executionAttributes);
|
||||
|
||||
/*
|
||||
* Called when a transaction has been rolled back.
|
||||
*
|
||||
* @see TransactionSynchronization#afterCompletion
|
||||
*/
|
||||
public abstract void reset(ExecutionAttributes streamContext);
|
||||
public abstract void reset(ExecutionAttributes executionAttributes);
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#isMarkSupported()
|
||||
|
||||
@@ -264,18 +264,18 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
lastCommitPointRecordCount = currentRecordCount;
|
||||
txReader.onCommit();
|
||||
skipRecords = new ArrayList();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
currentRecordCount = lastCommitPointRecordCount;
|
||||
txReader.onRollback();
|
||||
fragmentReader.reset();
|
||||
|
||||
@@ -448,17 +448,17 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
lastCommitPointPosition = getPosition();
|
||||
lastCommitPointRecordCount = currentRecordCount;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
currentRecordCount = lastCommitPointRecordCount;
|
||||
// close output
|
||||
close();
|
||||
|
||||
@@ -75,7 +75,7 @@ public interface ItemStream extends ExecutionAttributesProvider {
|
||||
*
|
||||
* @throws UnsupportedOperationException if the operation is not supported
|
||||
*/
|
||||
void mark(ExecutionAttributes streamContext);
|
||||
void mark(ExecutionAttributes executionAttributes);
|
||||
|
||||
/**
|
||||
* Reset the stream to the last mark. After a reset the stream state will be
|
||||
@@ -84,5 +84,5 @@ public interface ItemStream extends ExecutionAttributesProvider {
|
||||
*
|
||||
* @throws UnsupportedOperationException if the operation is not supported
|
||||
*/
|
||||
void reset(ExecutionAttributes streamContext);
|
||||
void reset(ExecutionAttributes executionAttributes);
|
||||
}
|
||||
|
||||
@@ -117,20 +117,20 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
if (inputSource instanceof ItemStream) {
|
||||
((ItemStream) inputSource).mark(streamContext);
|
||||
((ItemStream) inputSource).mark(executionAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
if (inputSource instanceof ItemStream) {
|
||||
((ItemStream) inputSource).reset(streamContext);
|
||||
((ItemStream) inputSource).reset(executionAttributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,16 +62,16 @@ public class ItemStreamAdapter implements ItemStream {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void mark(ExecutionAttributes streamContext) {
|
||||
public void mark(ExecutionAttributes executionAttributes) {
|
||||
throw new UnsupportedOperationException("Mark operation not supported.");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
*/
|
||||
public void reset(ExecutionAttributes streamContext) {
|
||||
public void reset(ExecutionAttributes executionAttributes) {
|
||||
throw new UnsupportedOperationException("Reset operation not supported.");
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SimpleStreamManager implements StreamManager {
|
||||
|
||||
/**
|
||||
* Public setter for the flag. If this is true then the class name of the
|
||||
* streams will be used as a prefix in the {@link StreamContext} in
|
||||
* streams will be used as a prefix in the {@link ExecutionAttributes} in
|
||||
* {@link #getExecutionAttributes(Object)}. The default value is true, which
|
||||
* gives the best chance of unique key names in the context.
|
||||
*
|
||||
@@ -85,7 +85,7 @@ public class SimpleStreamManager implements StreamManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple aggregate {@link StreamContext} provider for the contributions
|
||||
* Simple aggregate {@link ExecutionAttributes} provider for the contributions
|
||||
* registered under the given key.
|
||||
*
|
||||
* @see org.springframework.batch.item.stream.StreamManager#getExecutionAttributes(java.lang.Object)
|
||||
@@ -114,9 +114,9 @@ public class SimpleStreamManager implements StreamManager {
|
||||
* the provided key.
|
||||
*
|
||||
* @see org.springframework.batch.item.stream.StreamManager#register(java.lang.Object,
|
||||
* org.springframework.batch.item.ItemStream, StreamContext)
|
||||
* org.springframework.batch.item.ItemStream, ExecutionAttributes)
|
||||
*/
|
||||
public void register(Object key, ItemStream stream, ExecutionAttributes streamContext) {
|
||||
public void register(Object key, ItemStream stream, ExecutionAttributes executionAttributes) {
|
||||
synchronized (registry) {
|
||||
Set set = (Set) registry.get(key);
|
||||
if (set == null) {
|
||||
@@ -125,23 +125,23 @@ public class SimpleStreamManager implements StreamManager {
|
||||
}
|
||||
set.add(stream);
|
||||
}
|
||||
if (streamContext != null) {
|
||||
stream.restoreFrom(extract(stream, streamContext));
|
||||
if (executionAttributes != null) {
|
||||
stream.restoreFrom(extract(stream, executionAttributes));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stream
|
||||
* @param streamContext
|
||||
* @param executionAttributes
|
||||
* @return
|
||||
*/
|
||||
private ExecutionAttributes extract(ItemStream stream, ExecutionAttributes context) {
|
||||
private ExecutionAttributes extract(ItemStream stream, ExecutionAttributes executionAttributes) {
|
||||
ExecutionAttributes result = new ExecutionAttributes();
|
||||
String prefix = ClassUtils.getQualifiedName(stream.getClass()) + ".";
|
||||
if (!useClassNameAsPrefix) {
|
||||
prefix = "";
|
||||
}
|
||||
for (Iterator iterator = context.entrySet().iterator(); iterator.hasNext();) {
|
||||
for (Iterator iterator = executionAttributes.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry entry = (Entry) iterator.next();
|
||||
String contextKey = (String) entry.getKey();
|
||||
if (contextKey.startsWith(prefix)) {
|
||||
@@ -152,10 +152,8 @@ public class SimpleStreamManager implements StreamManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast the call to close from this {@link StreamContext}.
|
||||
* Broadcast the call to close from this {@link StreamManager}.
|
||||
* @throws Exception
|
||||
*
|
||||
* @see StreamManager#restoreFrom(Object, StreamContext)
|
||||
*/
|
||||
public void close(Object key) throws StreamException {
|
||||
iterate(key, new Callback() {
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.batch.item.stream;
|
||||
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.StreamException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
@@ -37,9 +37,9 @@ public interface StreamManager {
|
||||
*
|
||||
* @param key the key under which to add the provider
|
||||
* @param stream an {@link ItemStream}
|
||||
* @param streamContext the context (may be null) to restore from on registration
|
||||
* @param executionAttributes the context (may be null) to restore from on registration
|
||||
*/
|
||||
void register(Object key, ItemStream stream, ExecutionAttributes streamContext);
|
||||
void register(Object key, ItemStream stream, ExecutionAttributes executionAttributes);
|
||||
|
||||
/**
|
||||
* Extract and aggregate the {@link ExecutionAttributes} from all streams under
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple wrapper around {@link ItemWriter} providing {@link ItemStream} where
|
||||
* the {@link ItemWriter} does. To make sure
|
||||
* Simple wrapper around {@link ItemWriter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
@@ -46,34 +43,6 @@ public class DelegatingItemWriter implements ItemWriter, Skippable, Initializing
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
|
||||
Assert.state(writer != null, "Source must not be null.");
|
||||
|
||||
if (writer instanceof ItemStream) {
|
||||
return ((ItemStream) writer).getExecutionAttributes();
|
||||
}
|
||||
else {
|
||||
return new ExecutionAttributes();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#restoreFrom(ExecutionAttributes)
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
|
||||
Assert.state(writer != null, "Source must not be null.");
|
||||
|
||||
if (writer instanceof ItemStream) {
|
||||
((ItemStream) writer).restoreFrom(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void skip() {
|
||||
if (writer instanceof Skippable) {
|
||||
((Skippable) writer).skip();
|
||||
|
||||
Reference in New Issue
Block a user