RESOLVED - issue BATCH-362: Rename ExecutionAttributes to ExecutionContext
http://jira.springframework.org/browse/BATCH-362
This commit is contained in:
@@ -24,7 +24,7 @@ import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.reader.AbstractItemStreamItemReader;
|
||||
@@ -167,23 +167,23 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current row number wrapped as {@link ExecutionAttributes}
|
||||
* @return the current row number wrapped as {@link ExecutionContext}
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
public ExecutionContext getExecutionContext() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(RESTART_DATA_ROW_NUMBER_KEY, "" + currentProcessedRow);
|
||||
|
||||
ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
executionAttributes.putString(RESTART_DATA_ROW_NUMBER_KEY, "" + currentProcessedRow);
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.putString(RESTART_DATA_ROW_NUMBER_KEY, "" + currentProcessedRow);
|
||||
String skipped = skippedRows.toString();
|
||||
executionAttributes.putString(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1));
|
||||
return executionAttributes;
|
||||
executionContext.putString(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1));
|
||||
return executionContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cursor to the received row number.
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
public void restoreFrom(ExecutionContext data) {
|
||||
Assert.state(!initialized, "Cannot restore when already intialized. Call close() first before restore()");
|
||||
|
||||
Properties props = data.getProperties();
|
||||
@@ -229,7 +229,7 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
lastCommitRowNumber = currentProcessedRow;
|
||||
@@ -240,7 +240,7 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
currentProcessedRow = lastCommitRowNumber;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.KeyedItemReader;
|
||||
import org.springframework.batch.item.exception.ResetFailedException;
|
||||
@@ -71,7 +71,7 @@ import org.springframework.util.StringUtils;
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* {@link ExecutionAttributes}: The current row is returned as restart data,
|
||||
* {@link ExecutionContext}: The current row is returned as restart data,
|
||||
* and when restored from that same data, the cursor is opened and the current
|
||||
* row set to the value within the restart data. There are also two statistics
|
||||
* returned by this input source: the current line being processed and the
|
||||
@@ -378,11 +378,11 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#getExecutionAttributes()
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#getExecutionContext()
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
public ExecutionContext getExecutionContext() {
|
||||
String skipped = skippedRows.toString();
|
||||
ExecutionAttributes context = new ExecutionAttributes();
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.putString(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1));
|
||||
context.putLong(CURRENT_PROCESSED_ROW, currentProcessedRow);
|
||||
context.putLong(SKIP_COUNT, skipCount);
|
||||
@@ -391,9 +391,9 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#restoreFrom(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#restoreFrom(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
public void restoreFrom(ExecutionContext data) {
|
||||
Assert.state(!initialized);
|
||||
|
||||
if (data == null)
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.KeyedItemReader;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -147,7 +147,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource implem
|
||||
* been initialized before calling restore (meaning, read has been called)
|
||||
* then an IllegalStateException will be thrown, since all input sources
|
||||
* should be restored before being read from, otherwise already processed
|
||||
* data could be returned. The {@link ExecutionAttributes} attempting to be
|
||||
* data could be returned. The {@link ExecutionContext} attempting to be
|
||||
* restored from must have been obtained from the <strong>same input source
|
||||
* as the one being restored from</strong> otherwise it is invalid.
|
||||
*
|
||||
@@ -156,10 +156,10 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource implem
|
||||
* @throws IllegalStateException if the input source has already been
|
||||
* initialized.
|
||||
*/
|
||||
public final void restoreFrom(ExecutionAttributes data) {
|
||||
public final void restoreFrom(ExecutionContext data) {
|
||||
|
||||
Assert.notNull(data, "ExecutionAttributes must not be null.");
|
||||
Assert.notNull(data.getProperties(), "ExecutionAttributes properties must not be null.");
|
||||
Assert.notNull(data, "ExecutionContext must not be null.");
|
||||
Assert.notNull(data.getProperties(), "ExecutionContext properties must not be null.");
|
||||
Assert.state(!initialized, "Cannot restore when already intialized. Call" + " close() first before restore()");
|
||||
|
||||
if (data.getProperties().size() == 0) {
|
||||
@@ -174,8 +174,8 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource implem
|
||||
}
|
||||
}
|
||||
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return keyGenerator.getKeyAsExecutionAttributes(getCurrentKey());
|
||||
public ExecutionContext getExecutionContext() {
|
||||
return keyGenerator.getKeyAsExecutionContext(getCurrentKey());
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@@ -223,7 +223,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource implem
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
lastCommitIndex = currentIndex;
|
||||
@@ -232,7 +232,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource implem
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
keysIterator = keys.listIterator(lastCommitIndex);
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.springframework.batch.io.driving;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
/**
|
||||
* Strategy interface used to generate keys in driving query input.
|
||||
@@ -20,19 +20,19 @@ public interface KeyGenerator {
|
||||
/**
|
||||
* Restore the keys list based on provided restart data.
|
||||
*
|
||||
* @param executionAttributes, the restart data to restore the keys list from.
|
||||
* @param executionContext, the restart data to restore the keys list from.
|
||||
* @return a list of keys.
|
||||
* @throws IllegalArgumentException is executionAttributes is null.
|
||||
* @throws IllegalArgumentException if executionContext is null.
|
||||
*/
|
||||
List restoreKeys(ExecutionAttributes executionAttributes);
|
||||
List restoreKeys(ExecutionContext executionContext);
|
||||
|
||||
/**
|
||||
* Return the provided key as restart data.
|
||||
*
|
||||
* @param key to be converted to restart data.
|
||||
* @return {@link ExecutionAttributes} representation of the key.
|
||||
* @return {@link ExecutionContext} representation of the key.
|
||||
* @throws IllegalArgumentException if key is null.
|
||||
* @throws IllegalArgumentException if key is an incompatible type.
|
||||
*/
|
||||
ExecutionAttributes getKeyAsExecutionAttributes(Object key);
|
||||
ExecutionContext getKeyAsExecutionContext(Object key);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.jdbc.core.ColumnMapRowMapper;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
@@ -23,8 +23,8 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* </p>Extension of the ColumnMapRowMapper that converts a column map to {@link ExecutionAttributes} and allows
|
||||
* {@link ExecutionAttributes} to be converted back as a PreparedStatementSetter. This is useful in a restart
|
||||
* </p>Extension of the ColumnMapRowMapper that converts a column map to {@link ExecutionContext} and allows
|
||||
* {@link ExecutionContext} to be converted back as a PreparedStatementSetter. This is useful in a restart
|
||||
* scenario, as it allows for the standard functionality of the ColumnMapRowMapper to be used to
|
||||
* create a map representing the columns returned by a query. It should be noted that this column ordering
|
||||
* is preserved in the map using a link list version of Map.
|
||||
@@ -32,15 +32,15 @@ import org.springframework.util.ClassUtils;
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
* @see ExecutionAttributesRowMapper
|
||||
* @see ExecutionContextRowMapper
|
||||
*/
|
||||
public class ColumnMapExecutionAttributesRowMapper extends ColumnMapRowMapper implements ExecutionAttributesRowMapper {
|
||||
public class ColumnMapExecutionContextRowMapper extends ColumnMapRowMapper implements ExecutionContextRowMapper {
|
||||
|
||||
public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapExecutionAttributesRowMapper.class) + ".KEY.";
|
||||
public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapExecutionContextRowMapper.class) + ".KEY.";
|
||||
|
||||
public PreparedStatementSetter createSetter(ExecutionAttributes executionAttributes) {
|
||||
public PreparedStatementSetter createSetter(ExecutionContext executionContext) {
|
||||
|
||||
ColumnMapExecutionAttributes columnData = new ColumnMapExecutionAttributes(executionAttributes.getProperties());
|
||||
ColumnMapExecutionContext columnData = new ColumnMapExecutionContext(executionContext.getProperties());
|
||||
|
||||
List columns = new ArrayList();
|
||||
for (Iterator iterator = columnData.keys.entrySet().iterator(); iterator.hasNext();) {
|
||||
@@ -52,21 +52,21 @@ public class ColumnMapExecutionAttributesRowMapper extends ColumnMapRowMapper im
|
||||
return new ArgPreparedStatementSetter(columns.toArray());
|
||||
}
|
||||
|
||||
public ExecutionAttributes createExecutionAttributes(Object key) {
|
||||
Assert.isInstanceOf(Map.class, key, "Input to create ExecutionAttributes must be of type Map.");
|
||||
public ExecutionContext createExecutionContext(Object key) {
|
||||
Assert.isInstanceOf(Map.class, key, "Input to create ExecutionContext must be of type Map.");
|
||||
Map keys = (Map) key;
|
||||
return new ColumnMapExecutionAttributes(keys);
|
||||
return new ColumnMapExecutionContext(keys);
|
||||
}
|
||||
|
||||
private static class ColumnMapExecutionAttributes extends ExecutionAttributes {
|
||||
private static class ColumnMapExecutionContext extends ExecutionContext {
|
||||
|
||||
private final Map keys;
|
||||
|
||||
public ColumnMapExecutionAttributes(Map keys) {
|
||||
public ColumnMapExecutionContext(Map keys) {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public ColumnMapExecutionAttributes(Properties props) {
|
||||
public ColumnMapExecutionContext(Properties props) {
|
||||
|
||||
keys = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(props.size());
|
||||
|
||||
@@ -15,39 +15,39 @@
|
||||
*/
|
||||
package org.springframework.batch.io.driving.support;
|
||||
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* {@link ExecutionAttributesRowMapper} extends the standard {@link RowMapper} interface to provide for
|
||||
* converting an object returned from a RowMapper to {@link ExecutionAttributes} and back again. One
|
||||
* {@link ExecutionContextRowMapper} extends the standard {@link RowMapper} interface to provide for
|
||||
* converting an object returned from a RowMapper to {@link ExecutionContext} and back again. One
|
||||
* of the most common use cases for this type of functionality is the DrivingQuery approach
|
||||
* to sql processing. Using a {@link ExecutionAttributesRowMapper}, developers can create each unique key
|
||||
* to sql processing. Using a {@link ExecutionContextRowMapper}, developers can create each unique key
|
||||
* to suite their specific needs, and also describe how such a key would be converted to
|
||||
* {@link ExecutionAttributes}, so that it can be serialized and stored.
|
||||
* {@link ExecutionContext}, so that it can be serialized and stored.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @see RowMapper
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface ExecutionAttributesRowMapper extends RowMapper {
|
||||
public interface ExecutionContextRowMapper extends RowMapper {
|
||||
|
||||
/**
|
||||
* Given the provided composite key, return a {@link ExecutionAttributes} representation.
|
||||
* Given the provided composite key, return a {@link ExecutionContext} representation.
|
||||
*
|
||||
* @param key
|
||||
* @return ExecutionAttributes representing the composite key.
|
||||
* @return ExecutionContext representing the composite key.
|
||||
* @throws IllegalArgumentException if key is null or of an unsupported type.
|
||||
*/
|
||||
public ExecutionAttributes createExecutionAttributes(Object key);
|
||||
public ExecutionContext createExecutionContext(Object key);
|
||||
|
||||
/**
|
||||
* Given the provided restart data, return a PreparedStatementSeter that can
|
||||
* be used as parameters to a JdbcTemplate.
|
||||
*
|
||||
* @param executionAttributes
|
||||
* @param executionContext
|
||||
* @return an array of objects that can be used as arguments to a JdbcTemplate.
|
||||
*/
|
||||
public PreparedStatementSetter createSetter(ExecutionAttributes executionAttributes);
|
||||
public PreparedStatementSetter createSetter(ExecutionContext executionContext);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.driving.DrivingQueryItemReader;
|
||||
import org.springframework.batch.io.driving.KeyGenerator;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -40,22 +40,22 @@ public class IbatisKeyGenerator implements KeyGenerator {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsExecutionAttributes(java.lang.Object)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsExecutionContext(java.lang.Object)
|
||||
*/
|
||||
public ExecutionAttributes getKeyAsExecutionAttributes(Object key) {
|
||||
public ExecutionContext getKeyAsExecutionContext(Object key) {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(RESTART_KEY, key.toString());
|
||||
ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
executionAttributes.putString(RESTART_KEY, key.toString());
|
||||
return executionAttributes;
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.putString(RESTART_KEY, key.toString());
|
||||
return executionContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the keys list given the provided restart data.
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#restoreKeys(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#restoreKeys(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public List restoreKeys(ExecutionAttributes data) {
|
||||
public List restoreKeys(ExecutionContext data) {
|
||||
|
||||
Properties props = data.getProperties();
|
||||
Object key = props.getProperty(RESTART_KEY);
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.driving.DrivingQueryItemReader;
|
||||
import org.springframework.batch.io.driving.KeyGenerator;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -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 ExecutionAttributesRowMapper} to map each row in the resultset to an Object must be set in
|
||||
* a {@link ExecutionContextRowMapper} 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 ExecutionAttributesRowMapper keyMapper = new ColumnMapExecutionAttributesRowMapper();
|
||||
private ExecutionContextRowMapper keyMapper = new ColumnMapExecutionContextRowMapper();
|
||||
|
||||
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.ExecutionAttributes)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#restoreKeys(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public List restoreKeys(ExecutionAttributes executionAttributes) {
|
||||
public List restoreKeys(ExecutionContext executionContext) {
|
||||
|
||||
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 (executionAttributes.getProperties() != null) {
|
||||
return jdbcTemplate.query(restartSql, keyMapper.createSetter(executionAttributes), keyMapper);
|
||||
if (executionContext.getProperties() != null) {
|
||||
return jdbcTemplate.query(restartSql, keyMapper.createSetter(executionContext), keyMapper);
|
||||
}
|
||||
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsExecutionAttributes(java.lang.Object)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsExecutionContext(java.lang.Object)
|
||||
*/
|
||||
public ExecutionAttributes getKeyAsExecutionAttributes(Object key) {
|
||||
public ExecutionContext getKeyAsExecutionContext(Object key) {
|
||||
Assert.state(keyMapper != null, "Kye mapper must not be null.");
|
||||
return keyMapper.createExecutionAttributes(key);
|
||||
return keyMapper.createExecutionContext(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,12 +121,12 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link ExecutionAttributesRowMapper} to be used to map a resultset
|
||||
* Set the {@link ExecutionContextRowMapper} to be used to map a resultset
|
||||
* to keys.
|
||||
*
|
||||
* @param keyMapper
|
||||
*/
|
||||
public void setKeyMapper(ExecutionAttributesRowMapper keyMapper) {
|
||||
public void setKeyMapper(ExecutionContextRowMapper keyMapper) {
|
||||
this.keyMapper = keyMapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.ClassUtils;
|
||||
import org.springframework.batch.io.driving.KeyGenerator;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.SingleColumnRowMapper;
|
||||
@@ -95,36 +95,36 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
|
||||
/**
|
||||
* Get the restart data representing the last processed key.
|
||||
*
|
||||
* @see KeyGenerator#getKeyAsExecutionAttributes(Object)
|
||||
* @see KeyGenerator#getKeyAsExecutionContext(Object)
|
||||
* @throws IllegalArgumentException if key is null.
|
||||
*/
|
||||
public ExecutionAttributes getKeyAsExecutionAttributes(Object key) {
|
||||
public ExecutionContext getKeyAsExecutionContext(Object key) {
|
||||
Assert.notNull(key, "The key must not be null.");
|
||||
ExecutionAttributes context = new ExecutionAttributes();
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.putString(RESTART_KEY, key.toString());
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the remaining to be processed for the provided
|
||||
* {@link ExecutionAttributes}. The {@link ExecutionAttributes} attempting to be
|
||||
* {@link ExecutionContext}. The {@link ExecutionContext} attempting to be
|
||||
* restored from must have been obtained from the <strong>same
|
||||
* KeyGenerationStrategy as the one being restored from</strong> otherwise
|
||||
* it is invalid.
|
||||
*
|
||||
* @param executionAttributes {@link ExecutionAttributes} obtained by calling
|
||||
* {@link #getKeyAsExecutionAttributes(Object)} during a previous run.
|
||||
* @param executionContext {@link ExecutionContext} obtained by calling
|
||||
* {@link #getKeyAsExecutionContext(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)
|
||||
* @see KeyGenerator#restoreKeys(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public List restoreKeys(ExecutionAttributes executionAttributes) {
|
||||
public List restoreKeys(ExecutionContext executionContext) {
|
||||
|
||||
Assert.notNull(executionAttributes, "The restart data must not be null.");
|
||||
Assert.notNull(executionContext, "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 = executionAttributes.getProperties().getProperty(RESTART_KEY);
|
||||
String lastProcessedKey = executionContext.getProperties().getProperty(RESTART_KEY);
|
||||
|
||||
if (lastProcessedKey != null) {
|
||||
return jdbcTemplate.query(restartSql, new Object[] { lastProcessedKey }, keyMapper);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.batch.io.file.separator.ResourceLineReader;
|
||||
import org.springframework.batch.io.file.transform.AbstractLineTokenizer;
|
||||
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;
|
||||
import org.springframework.batch.io.file.transform.LineTokenizer;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
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;
|
||||
@@ -184,9 +184,9 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In
|
||||
* and position the buffer reader according to information provided by the
|
||||
* restart data
|
||||
*
|
||||
* @param data {@link ExecutionAttributes} information
|
||||
* @param data {@link ExecutionContext} information
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
public void restoreFrom(ExecutionContext data) {
|
||||
|
||||
if (data == null || data.getProperties() == null
|
||||
|| data.getProperties().getProperty(READ_STATISTICS_NAME) == null || getReader() == null) {
|
||||
@@ -213,14 +213,14 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In
|
||||
* the current Line Count which can be used to reinitialise the batch job in
|
||||
* case of restart.
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
public ExecutionContext getExecutionContext() {
|
||||
if (reader == null) {
|
||||
throw new StreamException("ItemStream not open or already closed.");
|
||||
}
|
||||
ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
executionAttributes.putLong(READ_STATISTICS_NAME, reader.getPosition());
|
||||
executionAttributes.putLong(SKIPPED_STATISTICS_NAME, skippedLines.size());
|
||||
return executionAttributes;
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.putLong(READ_STATISTICS_NAME, reader.getPosition());
|
||||
executionContext.putLong(SKIPPED_STATISTICS_NAME, skippedLines.size());
|
||||
return executionContext;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +237,7 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
getReader().mark();
|
||||
@@ -245,7 +245,7 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
getReader().reset();
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Properties;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.io.exception.BatchEnvironmentException;
|
||||
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.ResetFailedException;
|
||||
@@ -71,7 +71,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
|
||||
private Resource resource;
|
||||
|
||||
private ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
private ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
private OutputState state = null;
|
||||
|
||||
@@ -215,22 +215,22 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
* @see ItemStream#getExecutionContext()
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
public ExecutionContext getExecutionContext() {
|
||||
if (state == null) {
|
||||
throw new StreamException("ItemStream not open or already closed.");
|
||||
}
|
||||
executionAttributes.putLong(RESTART_DATA_NAME, state.position());
|
||||
executionAttributes.putLong(WRITTEN_STATISTICS_NAME, state.linesWritten);
|
||||
executionAttributes.putLong(RESTART_COUNT_STATISTICS_NAME, state.restartCount);
|
||||
return executionAttributes;
|
||||
executionContext.putLong(RESTART_DATA_NAME, state.position());
|
||||
executionContext.putLong(WRITTEN_STATISTICS_NAME, state.linesWritten);
|
||||
executionContext.putLong(RESTART_COUNT_STATISTICS_NAME, state.restartCount);
|
||||
return executionContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#restoreFrom(ExecutionAttributes)
|
||||
* @see ItemStream#restoreFrom(ExecutionContext)
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
public void restoreFrom(ExecutionContext data) {
|
||||
if (data == null)
|
||||
return;
|
||||
getOutputState().restoreFrom(data.getProperties());
|
||||
@@ -520,7 +520,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
getOutputState().mark();
|
||||
@@ -528,7 +528,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.io.support.AbstractTransactionalIoSource#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() throws ResetFailedException {
|
||||
try {
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.springframework.batch.io.xml.stax.DefaultFragmentEventReader;
|
||||
import org.springframework.batch.io.xml.stax.DefaultTransactionalEventReader;
|
||||
import org.springframework.batch.io.xml.stax.FragmentEventReader;
|
||||
import org.springframework.batch.io.xml.stax.TransactionalEventReader;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
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;
|
||||
@@ -174,25 +174,25 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade
|
||||
|
||||
/**
|
||||
* @return wrapped count of records read so far.
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
* @see ItemStream#getExecutionContext()
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
ExecutionAttributes executionAttributes = new ExecutionAttributes();
|
||||
executionAttributes.putLong(READ_COUNT_STATISTICS_NAME, currentRecordCount);
|
||||
return executionAttributes;
|
||||
public ExecutionContext getExecutionContext() {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.putLong(READ_COUNT_STATISTICS_NAME, currentRecordCount);
|
||||
return executionContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the input source for the given restart data by rereading and
|
||||
* skipping the number of records stored in the {@link ExecutionAttributes}.
|
||||
* skipping the number of records stored in the {@link ExecutionContext}.
|
||||
*
|
||||
* @param ExecutionAttributes that holds the line count from the last
|
||||
* @param ExecutionContext that holds the line count from the last
|
||||
* commit.
|
||||
* @throws IllegalStateException if the ItemReader has already been
|
||||
* initialized or if the number of records to read and skip exceeds the
|
||||
* available records.
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
public void restoreFrom(ExecutionContext data) {
|
||||
|
||||
if (data == null || data.getProperties() == null || !data.containsKey(READ_COUNT_STATISTICS_NAME)) {
|
||||
return;
|
||||
@@ -263,7 +263,7 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
lastCommitPointRecordCount = currentRecordCount;
|
||||
@@ -273,7 +273,7 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
currentRecordCount = lastCommitPointRecordCount;
|
||||
|
||||
@@ -15,7 +15,7 @@ import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.springframework.batch.io.support.FileUtils;
|
||||
import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
@@ -352,13 +352,13 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
|
||||
/**
|
||||
* Get the restart data.
|
||||
* @return the restart data
|
||||
* @see org.springframework.batch.item.ItemStream#getExecutionAttributes()
|
||||
* @see org.springframework.batch.item.ItemStream#getExecutionContext()
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
public ExecutionContext getExecutionContext() {
|
||||
if (!initialized) {
|
||||
throw new StreamException("ItemStream is not open, or may have been closed. Cannot access context.");
|
||||
}
|
||||
ExecutionAttributes context = new ExecutionAttributes();
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.putLong(RESTART_DATA_NAME, getPosition());
|
||||
context.putLong(WRITE_STATISTICS_NAME, currentRecordCount);
|
||||
return context;
|
||||
@@ -367,9 +367,9 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
|
||||
/**
|
||||
* Restore processing from provided restart data.
|
||||
* @param data the restart data
|
||||
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
public void restoreFrom(ExecutionContext data) {
|
||||
|
||||
long startAtPosition = 0;
|
||||
|
||||
@@ -440,7 +440,7 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
lastCommitPointPosition = getPosition();
|
||||
@@ -449,7 +449,7 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
currentRecordCount = lastCommitPointRecordCount;
|
||||
|
||||
@@ -34,17 +34,17 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class ExecutionAttributes {
|
||||
public class ExecutionContext {
|
||||
|
||||
private boolean dirty = false;
|
||||
|
||||
private final Map map;
|
||||
|
||||
public ExecutionAttributes() {
|
||||
public ExecutionContext() {
|
||||
map = new HashMap();
|
||||
}
|
||||
|
||||
public ExecutionAttributes(Map map){
|
||||
public ExecutionContext(Map map){
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@@ -137,13 +137,13 @@ public class ExecutionAttributes {
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof ExecutionAttributes == false){
|
||||
if(obj instanceof ExecutionContext == false){
|
||||
return false;
|
||||
}
|
||||
if(this == obj){
|
||||
return true;
|
||||
}
|
||||
ExecutionAttributes rhs = (ExecutionAttributes)obj;
|
||||
ExecutionContext rhs = (ExecutionContext)obj;
|
||||
return this.entrySet().equals(rhs.entrySet());
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ package org.springframework.batch.item;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface ExecutionAttributesProvider {
|
||||
public interface ExecutionContextProvider {
|
||||
|
||||
/**
|
||||
* Get {@link ExecutionAttributes} representing this object's current state.
|
||||
* Get {@link ExecutionContext} representing this object's current state.
|
||||
* Should not return null even if there is no state.
|
||||
*
|
||||
* @return {@link ExecutionAttributes} representing current state.
|
||||
* @return {@link ExecutionContext} representing current state.
|
||||
*/
|
||||
ExecutionAttributes getExecutionAttributes();
|
||||
ExecutionContext getExecutionContext();
|
||||
|
||||
}
|
||||
@@ -27,27 +27,27 @@ import org.springframework.batch.item.exception.StreamException;
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* The state that is stored is represented as {@link ExecutionAttributes} which
|
||||
* The state that is stored is represented as {@link ExecutionContext} which
|
||||
* enforces a requirement that any restart data can be represented by a
|
||||
* Properties object. In general, the contract is that
|
||||
* {@link ExecutionAttributes} that is returned via the
|
||||
* {@link #getExecutionAttributes()} method will be given back to the
|
||||
* {@link #restoreFrom(ExecutionAttributes)} method, exactly as it was provided.
|
||||
* {@link ExecutionContext} that is returned via the
|
||||
* {@link #getExecutionContext()} method will be given back to the
|
||||
* {@link #restoreFrom(ExecutionContext)} method, exactly as it was provided.
|
||||
* </p>
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface ItemStream extends ExecutionAttributesProvider {
|
||||
public interface ItemStream extends ExecutionContextProvider {
|
||||
|
||||
/**
|
||||
* Restore to the state given the provided {@link ExecutionAttributes}.
|
||||
* Restore to the state given the provided {@link ExecutionContext}.
|
||||
* This can be used to restart after a failure - hence not normally used
|
||||
* more than once per call to {@link #open()}.
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
void restoreFrom(ExecutionAttributes context);
|
||||
void restoreFrom(ExecutionContext context);
|
||||
|
||||
/**
|
||||
* If any resources are needed for the stream to operate they need to be
|
||||
@@ -70,7 +70,7 @@ public interface ItemStream extends ExecutionAttributesProvider {
|
||||
* stream is being accessed from multiple threads concurrently, it will have
|
||||
* to manage that internally, and also reflect only the completed marks
|
||||
* (independent of the order they happen) when
|
||||
* {@link ExecutionAttributesProvider#getExecutionAttributes()} is called.
|
||||
* {@link ExecutionContextProvider#getExecutionContext()} is called.
|
||||
*
|
||||
* @return true if mark and reset are supported by the {@link ItemStream}
|
||||
*/
|
||||
@@ -79,7 +79,7 @@ public interface ItemStream extends ExecutionAttributesProvider {
|
||||
/**
|
||||
* Mark the stream so that it can be reset later and the items backed out.
|
||||
* After this method is called the result will be reflected in subsequent
|
||||
* calls to {@link ExecutionAttributesProvider#getExecutionAttributes()}.<br/>
|
||||
* calls to {@link ExecutionContextProvider#getExecutionContext()}.<br/>
|
||||
*
|
||||
* In a multi-threaded setting implementations have to ensure that only the
|
||||
* state from the current thread is saved.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.item.reader;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
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;
|
||||
@@ -48,22 +48,22 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
* @see ItemStream#getExecutionContext()
|
||||
* @throws IllegalStateException if the parent template is not itself
|
||||
* {@link ItemStream}.
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
public ExecutionContext getExecutionContext() {
|
||||
// TODO: this is not necessary...
|
||||
Assert.state(inputSource instanceof ItemStream, "Input source is not ItemStream");
|
||||
return ((ItemStream) inputSource).getExecutionAttributes();
|
||||
return ((ItemStream) inputSource).getExecutionContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#restoreFrom(ExecutionAttributes)
|
||||
* @see ItemStream#restoreFrom(ExecutionContext)
|
||||
* @throws IllegalStateException if the parent template is not itself
|
||||
* {@link ItemStream}.
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
public void restoreFrom(ExecutionContext data) {
|
||||
Assert.state(inputSource instanceof ItemStream, "Input source is not ItemStream");
|
||||
((ItemStream) inputSource).restoreFrom(data);
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
if (inputSource instanceof ItemStream) {
|
||||
@@ -126,7 +126,7 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
if (inputSource instanceof ItemStream) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.item.stream;
|
||||
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
|
||||
@@ -41,17 +41,17 @@ public class ItemStreamAdapter implements ItemStream {
|
||||
|
||||
/**
|
||||
* No-op.
|
||||
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void restoreFrom(ExecutionAttributes context) {
|
||||
public void restoreFrom(ExecutionContext context) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return empty {@link ExecutionAttributes}.
|
||||
* @see org.springframework.batch.item.ExecutionAttributesProvider#getExecutionAttributes()
|
||||
* Return empty {@link ExecutionContext}.
|
||||
* @see org.springframework.batch.item.ExecutionContextProvider#getExecutionContext()
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes();
|
||||
public ExecutionContext getExecutionContext() {
|
||||
return new ExecutionContext();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -62,14 +62,14 @@ public class ItemStreamAdapter implements ItemStream {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void mark() {
|
||||
throw new UnsupportedOperationException("Mark operation not supported.");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionAttributes)
|
||||
* @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.ExecutionContext)
|
||||
*/
|
||||
public void reset() {
|
||||
throw new UnsupportedOperationException("Reset operation not supported.");
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -66,8 +66,8 @@ 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 ExecutionAttributes} in
|
||||
* {@link #getExecutionAttributes(Object)}. The default value is true, which
|
||||
* streams will be used as a prefix in the {@link ExecutionContext} in
|
||||
* {@link #getExecutionContext(Object)}. The default value is true, which
|
||||
* gives the best chance of unique key names in the context.
|
||||
*
|
||||
* @param useClassNameAsPrefix the flag to set (default true).
|
||||
@@ -85,16 +85,16 @@ public class SimpleStreamManager implements StreamManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple aggregate {@link ExecutionAttributes} provider for the contributions
|
||||
* Simple aggregate {@link ExecutionContext} provider for the contributions
|
||||
* registered under the given key.
|
||||
*
|
||||
* @see org.springframework.batch.item.stream.StreamManager#getExecutionAttributes(java.lang.Object)
|
||||
* @see org.springframework.batch.item.stream.StreamManager#getExecutionContext(java.lang.Object)
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes(Object key) {
|
||||
final ExecutionAttributes result = new ExecutionAttributes();
|
||||
public ExecutionContext getExecutionContext(Object key) {
|
||||
final ExecutionContext result = new ExecutionContext();
|
||||
iterate(key, new Callback() {
|
||||
public void execute(ItemStream stream) {
|
||||
ExecutionAttributes context = stream.getExecutionAttributes();
|
||||
ExecutionContext context = stream.getExecutionContext();
|
||||
String prefix = ClassUtils.getQualifiedName(stream.getClass()) + ".";
|
||||
if (!useClassNameAsPrefix) {
|
||||
prefix = "";
|
||||
@@ -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, ExecutionAttributes)
|
||||
* org.springframework.batch.item.ItemStream, ExecutionContext)
|
||||
*/
|
||||
public void register(Object key, ItemStream stream, ExecutionAttributes executionAttributes) {
|
||||
public void register(Object key, ItemStream stream, ExecutionContext executionContext) {
|
||||
synchronized (registry) {
|
||||
Set set = (Set) registry.get(key);
|
||||
if (set == null) {
|
||||
@@ -125,23 +125,23 @@ public class SimpleStreamManager implements StreamManager {
|
||||
}
|
||||
set.add(stream);
|
||||
}
|
||||
if (executionAttributes != null) {
|
||||
stream.restoreFrom(extract(stream, executionAttributes));
|
||||
if (executionContext != null) {
|
||||
stream.restoreFrom(extract(stream, executionContext));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stream
|
||||
* @param executionAttributes
|
||||
* @param executionContext
|
||||
* @return
|
||||
*/
|
||||
private ExecutionAttributes extract(ItemStream stream, ExecutionAttributes executionAttributes) {
|
||||
ExecutionAttributes result = new ExecutionAttributes();
|
||||
private ExecutionContext extract(ItemStream stream, ExecutionContext executionContext) {
|
||||
ExecutionContext result = new ExecutionContext();
|
||||
String prefix = ClassUtils.getQualifiedName(stream.getClass()) + ".";
|
||||
if (!useClassNameAsPrefix) {
|
||||
prefix = "";
|
||||
}
|
||||
for (Iterator iterator = executionAttributes.entrySet().iterator(); iterator.hasNext();) {
|
||||
for (Iterator iterator = executionContext.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry entry = (Entry) iterator.next();
|
||||
String contextKey = (String) entry.getKey();
|
||||
if (contextKey.startsWith(prefix)) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.item.stream;
|
||||
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
@@ -37,20 +37,20 @@ public interface StreamManager {
|
||||
*
|
||||
* @param key the key under which to add the provider
|
||||
* @param stream an {@link ItemStream}
|
||||
* @param executionAttributes the context (may be null) to restore from on registration
|
||||
* @param executionContext the context (may be null) to restore from on registration
|
||||
*/
|
||||
void register(Object key, ItemStream stream, ExecutionAttributes executionAttributes);
|
||||
void register(Object key, ItemStream stream, ExecutionContext executionContext);
|
||||
|
||||
/**
|
||||
* Extract and aggregate the {@link ExecutionAttributes} from all streams under
|
||||
* Extract and aggregate the {@link ExecutionContext} from all streams under
|
||||
* this key.
|
||||
*
|
||||
* @param key the key under which {@link ItemStream} instances might have
|
||||
* been registered.
|
||||
* @return {@link ExecutionAttributes} aggregating the contexts of all providers
|
||||
* @return {@link ExecutionContext} aggregating the contexts of all providers
|
||||
* registered under this key, or empty otherwise.
|
||||
*/
|
||||
ExecutionAttributes getExecutionAttributes(Object key);
|
||||
ExecutionContext getExecutionContext(Object key);
|
||||
|
||||
/**
|
||||
* If any resources are needed for the stream to operate they need to be
|
||||
|
||||
Reference in New Issue
Block a user