Purge StreamContext
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>clover</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -121,7 +121,7 @@ public class StepSupport implements Step, BeanNameAware {
|
||||
this.allowStartIfComplete = allowStartIfComplete;
|
||||
}
|
||||
|
||||
public void setSaveStreamContext(boolean saveStreamContext) {
|
||||
public void setSaveExecutionAttributes(boolean saveStreamContext) {
|
||||
this.saveStreamContext = saveStreamContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class StepSupportTests extends TestCase {
|
||||
|
||||
public void testSaveRestartFlag() throws Exception {
|
||||
assertEquals(false, configuration.isSaveStreamContext());
|
||||
configuration.setSaveStreamContext(true);
|
||||
configuration.setSaveExecutionAttributes(true);
|
||||
assertEquals(true, configuration.isSaveStreamContext());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>clover</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -192,12 +192,11 @@ public class SimpleStepContext extends SynchronizedAttributeAccessor implements
|
||||
return stepExecution;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#getStreamContext()
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ExecutionAttributesProvider#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
return streamManager.getStreamContext(this);
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return streamManager.getExecutionAttributes(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.batch.execution.scope;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.StreamContextProvider;
|
||||
import org.springframework.batch.item.ExecutionAttributesProvider;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ import org.springframework.core.AttributeAccessor;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface StepContext extends AttributeAccessor, StreamContextProvider {
|
||||
public interface StepContext extends AttributeAccessor, ExecutionAttributesProvider {
|
||||
|
||||
/**
|
||||
* Accessor for the {@link StepExecution} associated with the currently
|
||||
|
||||
@@ -206,7 +206,7 @@ public class SimpleStepExecutor {
|
||||
// TODO: check that stepExecution can
|
||||
// aggregate these contributions if they
|
||||
// come in asynchronously.
|
||||
ExecutionAttributes statistics = stepContext.getStreamContext();
|
||||
ExecutionAttributes statistics = stepContext.getExecutionAttributes();
|
||||
contribution.setStreamContext(statistics);
|
||||
contribution.incrementCommitCount();
|
||||
|
||||
@@ -220,7 +220,7 @@ public class SimpleStepExecutor {
|
||||
stepExecution.apply(contribution);
|
||||
|
||||
if (saveStreamContext) {
|
||||
stepInstance.setStreamContext(stepContext.getStreamContext());
|
||||
stepInstance.setStreamContext(stepContext.getExecutionAttributes());
|
||||
jobRepository.update(stepInstance);
|
||||
}
|
||||
jobRepository.saveOrUpdate(stepExecution);
|
||||
|
||||
@@ -136,8 +136,8 @@ public class SimpleStepContextTests extends TestCase {
|
||||
public void testStreamContextWithNotNullService() throws Exception {
|
||||
Map map = new HashMap();
|
||||
context = new SimpleStepContext(null, null, new StubStreamManager(map));
|
||||
assertEquals(1, context.getStreamContext().getProperties().size());
|
||||
assertEquals("bar", context.getStreamContext().getProperties().getProperty("foo"));
|
||||
assertEquals(1, context.getExecutionAttributes().getProperties().size());
|
||||
assertEquals("bar", context.getExecutionAttributes().getProperties().getProperty("foo"));
|
||||
}
|
||||
|
||||
public void testStreamManagerRegistration() throws Exception {
|
||||
@@ -164,7 +164,7 @@ public class SimpleStepContextTests extends TestCase {
|
||||
public void close(Object key) {
|
||||
}
|
||||
|
||||
public ExecutionAttributes getStreamContext(Object key) {
|
||||
public ExecutionAttributes getExecutionAttributes(Object key) {
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public class SimpleStepConfigurationTests extends TestCase {
|
||||
*/
|
||||
public void testIsSaveStreamContext() {
|
||||
assertEquals(false, configuration.isSaveStreamContext());
|
||||
configuration.setSaveStreamContext(true);
|
||||
configuration.setSaveExecutionAttributes(true);
|
||||
assertEquals(true, configuration.isSaveStreamContext());
|
||||
}
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
StepInstance step = new StepInstance(new Long(1));
|
||||
MockRestartableTasklet tasklet = new MockRestartableTasklet();
|
||||
stepExecutor.setTasklet(tasklet);
|
||||
stepConfiguration.setSaveStreamContext(true);
|
||||
stepConfiguration.setSaveExecutionAttributes(true);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
|
||||
|
||||
@@ -309,7 +309,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
step.setStepExecutionCount(1);
|
||||
MockRestartableTasklet tasklet = new MockRestartableTasklet();
|
||||
stepExecutor.setTasklet(tasklet);
|
||||
stepConfiguration.setSaveStreamContext(true);
|
||||
stepConfiguration.setSaveExecutionAttributes(true);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
|
||||
|
||||
@@ -332,7 +332,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
step.setStepExecutionCount(1);
|
||||
MockRestartableTasklet tasklet = new MockRestartableTasklet();
|
||||
stepConfiguration.setTasklet(tasklet);
|
||||
stepConfiguration.setSaveStreamContext(false);
|
||||
stepConfiguration.setSaveExecutionAttributes(false);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
|
||||
|
||||
@@ -359,7 +359,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
stepConfiguration.setSaveStreamContext(true);
|
||||
stepConfiguration.setSaveExecutionAttributes(true);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step, jobExecution);
|
||||
|
||||
@@ -413,7 +413,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
stepConfiguration.setSaveStreamContext(true);
|
||||
stepConfiguration.setSaveExecutionAttributes(true);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step, jobExecution);
|
||||
|
||||
@@ -421,7 +421,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
|
||||
final Map map = new HashMap();
|
||||
stepExecutor.setStreamManager(new SimpleStreamManager(new ResourcelessTransactionManager()) {
|
||||
public ExecutionAttributes getStreamContext(Object key) {
|
||||
public ExecutionAttributes getExecutionAttributes(Object key) {
|
||||
// TODO Auto-generated method stub
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
}
|
||||
@@ -453,7 +453,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
return restoreFromCalledWithSomeContext;
|
||||
}
|
||||
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
getStreamContextCalled = true;
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("spam=bucket"));
|
||||
}
|
||||
|
||||
@@ -58,15 +58,15 @@ CREATE TABLE BATCH_STEP_EXECUTION_ATTRS (
|
||||
DOUBLE_VAL DOUBLE PRECISION ,
|
||||
OBJECT_VAL LONGVARBINARY);
|
||||
|
||||
CREATE TABLE BATCH_STEP_EXECUTION_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
CREATE TABLE BATCH_STEP_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
CREATE TABLE BATCH_JOB_EXECUTION_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
CREATE TABLE BATCH_JOB_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
CREATE TABLE BATCH_STEP_EXECUTION_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
CREATE TABLE BATCH_STEP_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
CREATE TABLE BATCH_JOB_EXECUTION_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
CREATE TABLE BATCH_JOB_SEQ (
|
||||
ID BIGINT IDENTITY
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
class="org.springframework.batch.execution.step.simple.SimpleStep"
|
||||
abstract="true">
|
||||
<property name="allowStartIfComplete" value="true" />
|
||||
<property name="saveStreamContext" value="false" />
|
||||
<property name="saveExecutionAttributes" value="false" />
|
||||
<property name="exceptionHandler">
|
||||
<bean
|
||||
class="org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler">
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>clover</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -174,7 +174,7 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl
|
||||
/**
|
||||
* @return the current row number wrapped as <code>StreamContext</code>
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(RESTART_DATA_ROW_NUMBER_KEY, "" + currentProcessedRow);
|
||||
|
||||
|
||||
@@ -390,7 +390,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
|
||||
*
|
||||
* @see org.springframework.batch.restart.Restartable#getStreamContext()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
String skipped = skippedRows.toString();
|
||||
ExecutionAttributes context = new ExecutionAttributes();
|
||||
context.putString(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1));
|
||||
|
||||
@@ -189,7 +189,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
}
|
||||
}
|
||||
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return keyGenerator.getKeyAsStreamContext(getCurrentKey());
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
|
||||
* current Line Count which can be used to re initialise the batch job in
|
||||
* case of restart.
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
if (reader == null) {
|
||||
throw new StreamException("ItemStream not open or already closed.");
|
||||
}
|
||||
|
||||
@@ -244,9 +244,9 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#getStreamContext()
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
if (state == null) {
|
||||
throw new StreamException("ItemStream not open or already closed.");
|
||||
}
|
||||
|
||||
@@ -174,9 +174,9 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade
|
||||
|
||||
/**
|
||||
* @return wrapped count of records read so far.
|
||||
* @see ItemStream#getStreamContext()
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
ExecutionAttributes restartData = new ExecutionAttributes();
|
||||
restartData.putLong(READ_COUNT_STATISTICS_NAME, currentRecordCount);
|
||||
return restartData;
|
||||
|
||||
@@ -361,9 +361,9 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
|
||||
/**
|
||||
* Get the restart data.
|
||||
* @return the restart data
|
||||
* @see org.springframework.batch.item.ItemStream#getStreamContext()
|
||||
* @see org.springframework.batch.item.ItemStream#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
if (!initialized) {
|
||||
throw new StreamException("ItemStream is not open, or may have been closed. Cannot access context.");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ package org.springframework.batch.item;
|
||||
* The state that is stored is represented as {@link ExecutionAttributes} 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 #getStreamContext()} method will be given
|
||||
* that is returned via the {@link #getExecutionAttributes()} method will be given
|
||||
* back to the {@link #restoreFrom(ExecutionAttributes)} method, exactly as it was
|
||||
* provided.
|
||||
* </p>
|
||||
@@ -34,7 +34,7 @@ package org.springframework.batch.item;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface ItemStream extends StreamContextProvider {
|
||||
public interface ItemStream extends ExecutionAttributesProvider {
|
||||
|
||||
/**
|
||||
* Restart state given the provided {@link ExecutionAttributes}.
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.item;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface StreamContextProvider {
|
||||
|
||||
/**
|
||||
* Get {@link ExecutionAttributes} representing this object's current state.
|
||||
* Should not return null even if there is no state.
|
||||
*
|
||||
* @return {@link ExecutionAttributes} representing current state.
|
||||
*/
|
||||
ExecutionAttributes getStreamContext();
|
||||
|
||||
}
|
||||
@@ -48,14 +48,14 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#getStreamContext()
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
* @throws IllegalStateException if the parent template is not itself
|
||||
* {@link ItemStream}.
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
// TODO: this is not necessary...
|
||||
Assert.state(inputSource instanceof ItemStream, "Input source is not ItemStream");
|
||||
return ((ItemStream) inputSource).getStreamContext();
|
||||
return ((ItemStream) inputSource).getExecutionAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,9 +48,9 @@ public class ItemStreamAdapter implements ItemStream {
|
||||
|
||||
/**
|
||||
* Return empty {@link ExecutionAttributes}.
|
||||
* @see org.springframework.batch.item.StreamContextProvider#getStreamContext()
|
||||
* @see org.springframework.batch.item.ExecutionAttributesProvider#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,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
|
||||
* {@link #getStreamContext(Object)}. The default value is true, which
|
||||
* {@link #getExecutionAttributes(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).
|
||||
@@ -88,13 +88,13 @@ public class SimpleStreamManager implements StreamManager {
|
||||
* Simple aggregate {@link StreamContext} provider for the contributions
|
||||
* registered under the given key.
|
||||
*
|
||||
* @see org.springframework.batch.item.stream.StreamManager#getStreamContext(java.lang.Object)
|
||||
* @see org.springframework.batch.item.stream.StreamManager#getExecutionAttributes(java.lang.Object)
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext(Object key) {
|
||||
public ExecutionAttributes getExecutionAttributes(Object key) {
|
||||
final ExecutionAttributes result = new ExecutionAttributes();
|
||||
iterate(key, new Callback() {
|
||||
public void execute(ItemStream stream) {
|
||||
ExecutionAttributes context = stream.getStreamContext();
|
||||
ExecutionAttributes context = stream.getExecutionAttributes();
|
||||
String prefix = ClassUtils.getQualifiedName(stream.getClass()) + ".";
|
||||
if (!useClassNameAsPrefix) {
|
||||
prefix = "";
|
||||
@@ -179,7 +179,7 @@ public class SimpleStreamManager implements StreamManager {
|
||||
iterate(key, new Callback() {
|
||||
public void execute(ItemStream stream) {
|
||||
if (stream.isMarkSupported()) {
|
||||
stream.mark(stream.getStreamContext());
|
||||
stream.mark(stream.getExecutionAttributes());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -188,7 +188,7 @@ public class SimpleStreamManager implements StreamManager {
|
||||
iterate(key, new Callback() {
|
||||
public void execute(ItemStream stream) {
|
||||
if (stream.isMarkSupported()) {
|
||||
stream.reset(stream.getStreamContext());
|
||||
stream.reset(stream.getExecutionAttributes());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ public interface StreamManager {
|
||||
* @return {@link ExecutionAttributes} aggregating the contexts of all providers
|
||||
* registered under this key, or empty otherwise.
|
||||
*/
|
||||
ExecutionAttributes getStreamContext(Object key);
|
||||
ExecutionAttributes getExecutionAttributes(Object key);
|
||||
|
||||
/**
|
||||
* If any resources are needed for the stream to operate they need to be
|
||||
|
||||
@@ -47,14 +47,14 @@ public class DelegatingItemWriter implements ItemWriter, Skippable, Initializing
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemStream#getStreamContext()
|
||||
* @see ItemStream#getExecutionAttributes()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
|
||||
Assert.state(writer != null, "Source must not be null.");
|
||||
|
||||
if (writer instanceof ItemStream) {
|
||||
return ((ItemStream) writer).getStreamContext();
|
||||
return ((ItemStream) writer).getExecutionAttributes();
|
||||
}
|
||||
else {
|
||||
return new ExecutionAttributes();
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext();
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -95,7 +95,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext();
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
@@ -27,8 +27,8 @@ class FooItemReader extends AbstractItemReader implements ItemStream, ItemReader
|
||||
}
|
||||
}
|
||||
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
return inputSource.getStreamContext();
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return inputSource.getExecutionAttributes();
|
||||
}
|
||||
|
||||
public void restoreFrom(ExecutionAttributes data) {
|
||||
|
||||
@@ -156,7 +156,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
// do not open the template...
|
||||
try {
|
||||
inputSource.restoreFrom(inputSource.getStreamContext());
|
||||
inputSource.restoreFrom(inputSource.getExecutionAttributes());
|
||||
} catch (StreamException e) {
|
||||
assertTrue("Message does not contain open: "+e.getMessage(), e.getMessage().contains("open"));
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
inputSource.read();
|
||||
|
||||
// get restart data
|
||||
ExecutionAttributes streamContext = inputSource.getStreamContext();
|
||||
ExecutionAttributes streamContext = inputSource.getExecutionAttributes();
|
||||
assertEquals("4", (String) streamContext.getProperties().getProperty(
|
||||
DefaultFlatFileItemReader.READ_STATISTICS_NAME));
|
||||
// close input
|
||||
@@ -195,7 +195,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
assertEquals("[testLine5]", inputSource.read().toString());
|
||||
assertEquals("[testLine6]", inputSource.read().toString());
|
||||
|
||||
ExecutionAttributes statistics = inputSource.getStreamContext();
|
||||
ExecutionAttributes statistics = inputSource.getExecutionAttributes();
|
||||
assertEquals(6, statistics.getLong(DefaultFlatFileItemReader.READ_STATISTICS_NAME));
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
commit();
|
||||
|
||||
// get restart data
|
||||
ExecutionAttributes streamContext = inputSource.getStreamContext();
|
||||
ExecutionAttributes streamContext = inputSource.getExecutionAttributes();
|
||||
// close template
|
||||
inputSource.close();
|
||||
|
||||
@@ -335,7 +335,7 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
inputSource.write("testLine8");
|
||||
|
||||
// get statistics
|
||||
ExecutionAttributes statistics = inputSource.getStreamContext();
|
||||
ExecutionAttributes statistics = inputSource.getExecutionAttributes();
|
||||
// close template
|
||||
inputSource.close();
|
||||
|
||||
@@ -363,7 +363,7 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
public void testDefaultStreamContext() throws Exception {
|
||||
inputSource = new FlatFileItemWriter();
|
||||
inputSource.open();
|
||||
ExecutionAttributes streamContext = inputSource.getStreamContext();
|
||||
ExecutionAttributes streamContext = inputSource.getExecutionAttributes();
|
||||
assertNotNull(streamContext);
|
||||
assertEquals(3, streamContext.getProperties().size());
|
||||
assertEquals(0, streamContext.getLong(FlatFileItemWriter.RESTART_DATA_NAME));
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext();
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -98,7 +98,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext();
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext();
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -105,7 +105,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext();
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -208,7 +208,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
|
||||
rollback();
|
||||
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext();
|
||||
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -221,11 +221,11 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
((ItemStream) source).mark(((ItemStream) source).getStreamContext());
|
||||
((ItemStream) source).mark(((ItemStream) source).getExecutionAttributes());
|
||||
}
|
||||
|
||||
private void rollback() {
|
||||
((ItemStream) source).reset(((ItemStream) source).getStreamContext());
|
||||
((ItemStream) source).reset(((ItemStream) source).getExecutionAttributes());
|
||||
}
|
||||
|
||||
private Skippable getAsSkippable(ItemReader source) {
|
||||
|
||||
@@ -112,7 +112,7 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
*/
|
||||
public void testRestart() {
|
||||
source.read();
|
||||
ExecutionAttributes streamContext = source.getStreamContext();
|
||||
ExecutionAttributes streamContext = source.getExecutionAttributes();
|
||||
assertEquals(1, streamContext.getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME));
|
||||
List expectedAfterRestart = (List) source.read();
|
||||
|
||||
@@ -208,7 +208,7 @@ public class StaxEventItemReaderTests extends TestCase {
|
||||
}
|
||||
|
||||
private long extractRecordCount() {
|
||||
return source.getStreamContext().getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME);
|
||||
return source.getExecutionAttributes().getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME);
|
||||
}
|
||||
|
||||
public void testCloseWithoutOpen() throws Exception {
|
||||
|
||||
@@ -88,7 +88,7 @@ public class StaxEventWriterItemWriterTests extends TestCase {
|
||||
// write records
|
||||
writer.write(record);
|
||||
writer.mark(null);
|
||||
ExecutionAttributes streamContext = writer.getStreamContext();
|
||||
ExecutionAttributes streamContext = writer.getExecutionAttributes();
|
||||
|
||||
// create new writer from saved restart data and continue writing
|
||||
writer = createItemWriter();
|
||||
@@ -116,7 +116,7 @@ public class StaxEventWriterItemWriterTests extends TestCase {
|
||||
for (int i = 1; i <= NUMBER_OF_RECORDS; i++) {
|
||||
writer.write(record);
|
||||
long writeStatistics =
|
||||
writer.getStreamContext().getLong(StaxEventItemWriter.WRITE_STATISTICS_NAME);
|
||||
writer.getExecutionAttributes().getLong(StaxEventItemWriter.WRITE_STATISTICS_NAME);
|
||||
|
||||
assertEquals(i, writeStatistics);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
* Gets restart data from the input template
|
||||
*/
|
||||
public void testGetStreamContext() {
|
||||
Properties props = itemProvider.getStreamContext().getProperties();
|
||||
Properties props = itemProvider.getExecutionAttributes().getProperties();
|
||||
assertEquals("foo", props.getProperty("value"));
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
return PropertiesConverter.stringToProperties("a=b");
|
||||
}
|
||||
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("value=foo"));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,31 +72,31 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}.
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
|
||||
*/
|
||||
public void testGetStreamContextEmpty() {
|
||||
ExecutionAttributes streamContext = manager.getStreamContext("foo");
|
||||
ExecutionAttributes streamContext = manager.getExecutionAttributes("foo");
|
||||
assertEquals(0, streamContext.entrySet().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}.
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
|
||||
*/
|
||||
public void testGetStreamContextNotEmpty() {
|
||||
manager.register("foo", stream, null);
|
||||
ExecutionAttributes streamContext = manager.getStreamContext("foo");
|
||||
ExecutionAttributes streamContext = manager.getExecutionAttributes("foo");
|
||||
assertEquals(1, streamContext.entrySet().size());
|
||||
assertEquals("bar", streamContext.getString(ClassUtils.getQualifiedName(stream.getClass()) + ".foo"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}.
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
|
||||
*/
|
||||
public void testGetStreamContextNotEmptyAndRestore() {
|
||||
testGetStreamContextNotEmpty();
|
||||
ExecutionAttributes context = manager.getStreamContext("foo");
|
||||
ExecutionAttributes context = manager.getExecutionAttributes("foo");
|
||||
// Register again, now with the context that was created from the same
|
||||
// stream...
|
||||
manager.register("foo", stream, context);
|
||||
@@ -107,7 +107,7 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}.
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
|
||||
*/
|
||||
public void testGetStreamContextNotEmptyAndRestoreWithNoPrefix() {
|
||||
ExecutionAttributes context = new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
@@ -120,12 +120,12 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}.
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
|
||||
*/
|
||||
public void testGetStreamContextWithNoPrefix() {
|
||||
manager.setUseClassNameAsPrefix(false);
|
||||
manager.register("foo", stream, null);
|
||||
ExecutionAttributes context = manager.getStreamContext("foo");
|
||||
ExecutionAttributes context = manager.getExecutionAttributes("foo");
|
||||
assertEquals(1, context.entrySet().size());
|
||||
// The list should have the foo= map value from the sub-context
|
||||
assertEquals("bar", context.getString("foo"));
|
||||
@@ -133,20 +133,20 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}.
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
|
||||
*/
|
||||
public void testGetStreamContextTwoRegistrations() {
|
||||
manager.register("foo", new ItemStreamAdapter() {
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
}
|
||||
}, null);
|
||||
manager.register("foo", new ItemStreamAdapter() {
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=spam"));
|
||||
}
|
||||
}, null);
|
||||
ExecutionAttributes streamContext = manager.getStreamContext("foo");
|
||||
ExecutionAttributes streamContext = manager.getExecutionAttributes("foo");
|
||||
assertEquals(2, streamContext.entrySet().size());
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
}
|
||||
|
||||
private final class ItemStreamAdapterExtension extends ItemStreamAdapter {
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
public void open() {
|
||||
}
|
||||
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("value=foo"));
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Key
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.StreamContextProvider#getStreamContext()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.StreamContextProvider;
|
||||
import org.springframework.batch.item.ExecutionAttributesProvider;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class InfiniteLoopTasklet implements Tasklet, StreamContextProvider {
|
||||
public class InfiniteLoopTasklet implements Tasklet, ExecutionAttributesProvider {
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class InfiniteLoopTasklet implements Tasklet, StreamContextProvider {
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.stream.ItemStreamAdapter#getStreamContext()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return new ExecutionAttributes(PropertiesConverter.stringToProperties("count=" + count));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.execution.tasklet.ItemOrientedTasklet;
|
||||
import org.springframework.batch.io.file.DefaultFlatFileItemReader;
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
import org.springframework.batch.item.StreamContextProvider;
|
||||
import org.springframework.batch.item.ExecutionAttributesProvider;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.sample.dao.TradeDao;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
@@ -39,7 +39,7 @@ import org.springframework.batch.sample.domain.Trade;
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SimpleTradeTasklet implements Tasklet, StreamContextProvider {
|
||||
public class SimpleTradeTasklet implements Tasklet, ExecutionAttributesProvider {
|
||||
|
||||
/*
|
||||
* reads the data from input file
|
||||
@@ -86,7 +86,7 @@ public class SimpleTradeTasklet implements Tasklet, StreamContextProvider {
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.StreamContextProvider#getStreamContext()
|
||||
*/
|
||||
public ExecutionAttributes getStreamContext() {
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
ExecutionAttributes statistics = new ExecutionAttributes();
|
||||
statistics.putLong("trade.count", tradeCount);
|
||||
return statistics;
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
</property>
|
||||
<property name="commitInterval" value="2" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="saveStreamContext" value="true" />
|
||||
<property name="saveExecutionAttributes" value="true" />
|
||||
<property name="allowStartIfComplete" value="false" />
|
||||
</bean>
|
||||
<bean id="loading" parent="repeatOperationsStep">
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="commitInterval" value="2" />
|
||||
<property name="saveStreamContext" value="true"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
<property name="allowStartIfComplete" value="true" />
|
||||
<property name="saveStreamContext" value="true" />
|
||||
<property name="saveExecutionAttributes" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="simpleStep" parent="abstractStep"
|
||||
|
||||
Reference in New Issue
Block a user