BATCH-2004: Added basic wrappers for the the majority of batch artifacts.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package org.springframework.batch.jsr.item;
|
||||
|
||||
import javax.batch.api.chunk.ItemProcessor;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ItemProcessorAdapter implements org.springframework.batch.item.ItemProcessor {
|
||||
|
||||
private ItemProcessor delegate;
|
||||
|
||||
public ItemProcessorAdapter(ItemProcessor processor) {
|
||||
Assert.notNull(processor, "An ItemProcessor implementation is required");
|
||||
this.delegate = processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object process(Object item) throws Exception {
|
||||
return delegate.processItem(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.springframework.batch.jsr.item;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.batch.api.chunk.ItemReader;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ItemStreamSupport;
|
||||
import org.springframework.batch.item.NonTransientResourceException;
|
||||
import org.springframework.batch.item.ParseException;
|
||||
import org.springframework.batch.item.UnexpectedInputException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ItemReaderAdapter extends ItemStreamSupport implements org.springframework.batch.item.ItemReader {
|
||||
|
||||
private static final String CHECKPOINT_KEY = "reader.checkpoint";
|
||||
|
||||
private ItemReader delegate;
|
||||
|
||||
public ItemReaderAdapter(ItemReader reader) {
|
||||
Assert.notNull(reader, "An ItemReader implementation is required");
|
||||
this.delegate = reader;
|
||||
setExecutionContextName(ClassUtils.getShortName(delegate.getClass()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(ExecutionContext executionContext)
|
||||
throws ItemStreamException {
|
||||
try {
|
||||
delegate.open((Serializable) executionContext.get(getExecutionContextKey(CHECKPOINT_KEY)));
|
||||
} catch (Exception e) {
|
||||
throw new ItemStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ExecutionContext executionContext)
|
||||
throws ItemStreamException {
|
||||
try {
|
||||
Serializable checkpoint = delegate.checkpointInfo();
|
||||
executionContext.put(getExecutionContextKey(CHECKPOINT_KEY), checkpoint);
|
||||
} catch (Exception e) {
|
||||
throw new ItemStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ItemStreamException {
|
||||
try {
|
||||
delegate.close();
|
||||
} catch (Exception e) {
|
||||
throw new ItemStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read() throws Exception, UnexpectedInputException, ParseException,
|
||||
NonTransientResourceException {
|
||||
return delegate.readItem();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.springframework.batch.jsr.item;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.batch.api.chunk.ItemWriter;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ItemStreamSupport;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ItemWriterAdapter extends ItemStreamSupport implements org.springframework.batch.item.ItemWriter {
|
||||
|
||||
private static final String CHECKPOINT_KEY = "writer.checkpoint";
|
||||
|
||||
private ItemWriter delegate;
|
||||
|
||||
public ItemWriterAdapter(ItemWriter writer) {
|
||||
Assert.notNull(writer, "An ItemWriter implementation is required");
|
||||
this.delegate = writer;
|
||||
super.setExecutionContextName(ClassUtils.getShortName(delegate.getClass()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(ExecutionContext executionContext)
|
||||
throws ItemStreamException {
|
||||
try {
|
||||
delegate.open((Serializable) executionContext.get(getExecutionContextKey(CHECKPOINT_KEY)));
|
||||
} catch (Exception e) {
|
||||
throw new ItemStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ExecutionContext executionContext)
|
||||
throws ItemStreamException {
|
||||
try {
|
||||
Serializable checkpoint = delegate.checkpointInfo();
|
||||
executionContext.put(getExecutionContextKey(CHECKPOINT_KEY), checkpoint);
|
||||
} catch (Exception e) {
|
||||
throw new ItemStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ItemStreamException {
|
||||
try {
|
||||
delegate.close();
|
||||
} catch (Exception e) {
|
||||
throw new ItemStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void write(List items) throws Exception {
|
||||
delegate.writeItems(items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.springframework.batch.jsr.repeat;
|
||||
|
||||
import javax.batch.api.chunk.CheckpointAlgorithm;
|
||||
|
||||
import org.springframework.batch.repeat.CompletionPolicy;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class CheckpointAlgorithmAdapter implements CompletionPolicy {
|
||||
|
||||
private CheckpointAlgorithm policy;
|
||||
|
||||
public CheckpointAlgorithmAdapter(CheckpointAlgorithm policy) {
|
||||
Assert.notNull(policy, "A CheckpointAlgorithm is required");
|
||||
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete(RepeatContext context, RepeatStatus result) {
|
||||
try {
|
||||
return policy.isReadyToCheckpoint();
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete(RepeatContext context) {
|
||||
try {
|
||||
return policy.isReadyToCheckpoint();
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepeatContext start(RepeatContext parent) {
|
||||
try {
|
||||
policy.beginCheckpoint();
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(RepeatContext context) {
|
||||
try {
|
||||
if(policy.isReadyToCheckpoint()) {
|
||||
policy.endCheckpoint();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user