IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)

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

Remove references to RestartData
This commit is contained in:
dsyer
2008-01-31 13:41:37 +00:00
parent 8b6aad9d82
commit acc1460fb8
17 changed files with 94 additions and 99 deletions

View File

@@ -184,7 +184,7 @@ public class HibernateCursorItemReader extends AbstractItemReader implements Ite
}
/**
* @return the current row number wrapped as <code>RestartData</code>
* @return the current row number wrapped as <code>StreamContext</code>
*/
public StreamContext getStreamContext() {
Properties props = new Properties();

View File

@@ -394,7 +394,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
/*
* (non-Javadoc)
*
* @see org.springframework.batch.restart.Restartable#getRestartData()
* @see org.springframework.batch.restart.Restartable#getStreamContext()
*/
public StreamContext getStreamContext() {
String skipped = skippedRows.toString();
@@ -405,10 +405,9 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
return context;
}
/*
* (non-Javadoc)
*
* @see org.springframework.batch.restart.Restartable#restoreFrom(org.springframework.batch.restart.RestartData)
/* (non-Javadoc)
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext)
*/
public void restoreFrom(StreamContext data) {
Assert.state(!initialized);

View File

@@ -161,7 +161,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
* 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 RestartData attempting to be restored from
* data could be returned. The {@link StreamContext} 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.
*
@@ -172,9 +172,9 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
*/
public final void restoreFrom(StreamContext data) {
Assert.notNull(data, "RestartData must not be null.");
Assert.notNull(data, "StreamContext must not be null.");
Assert.notNull(data.getProperties(),
"RestartData properties must not be null.");
"StreamContext properties must not be null.");
Assert.state(!initialized,
"Cannot restore when already intialized. Call"
+ " close() first before restore()");

View File

@@ -20,9 +20,9 @@ public interface KeyGenerator {
/**
* Restore the keys list based on provided restart data.
*
* @param restartData, the restart data to restore the keys list from.
* @param streamContext, the restart data to restore the keys list from.
* @return a list of keys.
* @throws IllegalArgumentException is restartData is null.
* @throws IllegalArgumentException is streamContext is null.
*/
List restoreKeys(StreamContext streamContext);
@@ -30,7 +30,7 @@ public interface KeyGenerator {
* Return the provided key as restart data.
*
* @param key to be converted to restart data.
* @return RestartData representation of the key.
* @return StreamContext representation of the key.
* @throws IllegalArgumentException if key is null.
* @throws IllegalArgumentException if key is an incompatible type.
*/

View File

@@ -33,15 +33,15 @@ import org.springframework.util.ClassUtils;
*
* @author Lucas Ward
* @author Dave Syer
* @see RestartDataRowMapper
* @see StreamContextRowMapper
*/
public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implements RestartDataRowMapper{
public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implements StreamContextRowMapper{
public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapStreamContextRowMapper.class) + ".KEY.";
public PreparedStatementSetter createSetter(StreamContext streamContext) {
ColumnMapRestartData columnData = new ColumnMapRestartData(streamContext.getProperties());
ColumnMapStreamContext columnData = new ColumnMapStreamContext(streamContext.getProperties());
List columns = new ArrayList();
for (Iterator iterator = columnData.keys.entrySet().iterator(); iterator.hasNext();) {
@@ -56,19 +56,19 @@ public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implemen
public StreamContext createStreamContext(Object key) {
Assert.isInstanceOf(Map.class, key, "Input to create StreamContext must be of type Map.");
Map keys = (Map)key;
return new ColumnMapRestartData(keys);
return new ColumnMapStreamContext(keys);
}
private static class ColumnMapRestartData extends GenericStreamContext {
private static class ColumnMapStreamContext extends GenericStreamContext {
private final Map keys;
public ColumnMapRestartData(Map keys) {
public ColumnMapStreamContext(Map keys) {
this.keys = keys;
}
public ColumnMapRestartData(Properties props) {
public ColumnMapStreamContext(Properties props) {
keys = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(props.size());

View File

@@ -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 RestartDataRowMapper} to map each row in the resultset to an Object must be set in
* a {@link StreamContextRowMapper} 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 RestartDataRowMapper keyMapper = new ColumnMapStreamContextRowMapper();
private StreamContextRowMapper keyMapper = new ColumnMapStreamContextRowMapper();
private String sql;
@@ -78,7 +78,7 @@ public class MultipleColumnJdbcKeyGenerator implements
}
/* (non-Javadoc)
* @see org.springframework.batch.io.sql.scratch.AbstractDrivingQueryItemReader#restoreKeys(org.springframework.batch.restart.RestartData)
* @see org.springframework.batch.io.driving.KeyGenerator#restoreKeys(org.springframework.batch.item.StreamContext)
*/
public List restoreKeys(StreamContext streamContext) {
@@ -94,10 +94,10 @@ public class MultipleColumnJdbcKeyGenerator implements
}
/* (non-Javadoc)
* @see org.springframework.batch.restart.Restartable#getRestartData()
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsStreamContext(java.lang.Object)
*/
public StreamContext getKeyAsStreamContext(Object key) {
Assert.state(keyMapper != null, "RestartDataConverter must not be null.");
Assert.state(keyMapper != null, "Kye mapper must not be null.");
return keyMapper.createStreamContext(key);
}
@@ -121,12 +121,12 @@ public class MultipleColumnJdbcKeyGenerator implements
}
/**
* Set the {@link RestartDataRowMapper} to be used to map a resultset
* Set the {@link StreamContextRowMapper} to be used to map a resultset
* to keys.
*
* @param keyMapper
*/
public void setKeyMapper(RestartDataRowMapper keyMapper) {
public void setKeyMapper(StreamContextRowMapper keyMapper) {
this.keyMapper = keyMapper;
}

View File

@@ -30,21 +30,26 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* <p>Jdbc {@link KeyGenerator} implementation that only works for a single column key. A sql
* query must be passed in which will be used to return a list of keys. Each key will be mapped
* by a {@link RowMapper} that returns a mapped key. By default, the {@link SingleColumnRowMapper}
* is used, and will convert keys into well known types at runtime. It is extremely important to
* note that only one column should be mapped to an object and returned as a key. If multiple
* columns are returned as a key in this strategy, then restart will not function properly. Instead
* a strategy that supports keys comprised of multiple columns should be used.
*
* <p>Restartability: Because the key is only one column, restart is made much more simple. Before
* each commit, the last processed key is returned to be stored as restart data. Upon restart, that
* same key is given back to restore from, using a separate 'RestartQuery'. This means that only the
* keys remaining to be processed are returned, rather than returning the original list of keys and
* iterating forward to that last committed point.
* <p>
* Jdbc {@link KeyGenerator} implementation that only works for a single column
* key. A sql query must be passed in which will be used to return a list of
* keys. Each key will be mapped by a {@link RowMapper} that returns a mapped
* key. By default, the {@link SingleColumnRowMapper} is used, and will convert
* keys into well known types at runtime. It is extremely important to note that
* only one column should be mapped to an object and returned as a key. If
* multiple columns are returned as a key in this strategy, then restart will
* not function properly. Instead a strategy that supports keys comprised of
* multiple columns should be used.
*
* <p>
* Restartability: Because the key is only one column, restart is made much more
* simple. Before each commit, the last processed key is returned to be stored
* as restart data. Upon restart, that same key is given back to restore from,
* using a separate 'RestartQuery'. This means that only the keys remaining to
* be processed are returned, rather than returning the original list of keys
* and iterating forward to that last committed point.
* </p>
*
*
* @author Lucas Ward
* @since 1.0
*/
@@ -63,10 +68,10 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
public SingleColumnJdbcKeyGenerator() {
super();
}
/**
* Constructs a new instance using the provided jdbcTemplate and string representing
* the sql statement that should be used to retrieve keys.
* Constructs a new instance using the provided jdbcTemplate and string
* representing the sql statement that should be used to retrieve keys.
*
* @param jdbcTemplate
* @param sql
@@ -81,7 +86,8 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
this.sql = sql;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.batch.io.driving.KeyGenerationStrategy#retrieveKeys()
*/
public List retrieveKeys() {
@@ -90,27 +96,28 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
/**
* Get the restart data representing the last processed key.
*
* @see KeyGenerator#getKeyAsRestartData()
*
* @see KeyGenerator#getKeyAsStreamContext(Object)
* @throws IllegalArgumentException if key is null.
*/
public StreamContext getKeyAsStreamContext(Object key) {
Assert.notNull(key, "The key must not be null.");
Properties props = new Properties();
props.setProperty(RESTART_KEY, key.toString());
return new GenericStreamContext(props);
}
/**
* Return the remaining to be processed for the provided {@link StreamContext}.
* The RestartData 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 StreamContext obtained by calling getRestartData during a previous
* run.
* Return the remaining to be processed for the provided
* {@link StreamContext}. The {@link StreamContext} 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 StreamContext obtained by calling
* {@link #getKeyAsStreamContext(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.StreamContext)
@@ -118,8 +125,8 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
public List restoreKeys(StreamContext streamContext) {
Assert.notNull(streamContext, "The restart data must not be null.");
Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty" +
" in order to restart.");
Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty"
+ " in order to restart.");
String lastProcessedKey = streamContext.getProperties().getProperty(RESTART_KEY);
@@ -130,18 +137,18 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
return new ArrayList();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(jdbcTemplate, "JdbcTemplate must not be null.");
Assert.hasText(sql, "The DrivingQuery must not be null or empty.");
}
/**
* Set the {@link RowMapper} to be used to map each key to an object.
*
*
* @param keyMapper
*/
public void setKeyMapper(RowMapper keyMapper) {
@@ -149,14 +156,15 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
}
/**
* Set the SQL query to be used to return the remaining keys to be processed.
*
* Set the SQL query to be used to return the remaining keys to be
* processed.
*
* @param restartSql
*/
public void setRestartSql(String restartSql) {
this.restartSql = restartSql;
}
/**
* Set the SQL statement to be used to return the keys to be processed.
*

View File

@@ -31,7 +31,7 @@ import org.springframework.jdbc.core.RowMapper;
* @see RowMapper
* @since 1.0
*/
public interface RestartDataRowMapper extends RowMapper {
public interface StreamContextRowMapper extends RowMapper {
/**
* Given the provided composite key, return a RestartData representation.

View File

@@ -74,7 +74,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
* file and position the buffer reader according to information provided by
* the restart data
*
* @param restartData restartData information
* @param data {@link StreamContext} information
*/
public void restoreFrom(StreamContext data) {