BATCH-220:Added the 'Dechunker', as the opposite of Chunker. It assumes that some higher level class will be managing transactions. Also renamed ReadFailurePolicy to ItemSkipPolicy (Same name used by Ben in the Sandbox) once I realized that a 'ReadFailurePolicy' and 'WriteFailurePolicy' would have pretty much the same interface.

This commit is contained in:
lucasward
2008-02-12 06:07:40 +00:00
parent 10e7514290
commit 1871df0539
3 changed files with 100 additions and 3 deletions

View File

@@ -0,0 +1,64 @@
/*
* 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.core.domain;
import java.util.ArrayList;
import java.util.List;
import org.springframework.core.enums.ShortCodedLabeledEnum;
/**
*
* @author Ben Hale
*/
public class ChunkResult {
public static final ChunkResultType SUCCESS = new ChunkResultType(0, "Success");
public static final ChunkResultType FAILURE = new ChunkResultType(1, "Failure");
private final ChunkResultType resultType;
private final Long chunkId;
private final List skippedItems;
public ChunkResult(ChunkResultType resultType, Long chunkId, List skippedItems) {
this.resultType = resultType;
this.chunkId = chunkId;
this.skippedItems = skippedItems;
}
public ChunkResultType getResultType() {
return resultType;
}
public Long getChunkId() {
return chunkId;
}
public List getSkippedItems() {
return new ArrayList(skippedItems);
}
private static class ChunkResultType extends ShortCodedLabeledEnum {
public ChunkResultType(int code, String label) {
super(code, label);
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2006-2008 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.core.domain;
import org.springframework.batch.item.ItemReader;
/**
* Interface defining the contract for dechunking a {@link Chunk}. Similar
* to the differences between an {@link ItemReader} and an {@link ItemWriter},
* a dechunker is the polar oposite of a {@link Chunker}. A {@link Chunker} creates
* a chunk from a stream of items, wheras a Dechunker removes each item from the
* {@link Chunk} and adds it to an outgoing stream of items.
*
* @author Lucas Ward
*
*/
public interface Dechunker {
ChunkResult dechunk(Chunk chunk) throws Exception;
}

View File

@@ -18,11 +18,11 @@ package org.springframework.batch.core.domain;
import org.springframework.batch.core.domain.StepExecution;
/**
* Policy for determining whether or not reading should continue.
* Policy for determining whether or not an item should be skipped.
*
* @author Lucas Ward
*/
public interface ReadFailurePolicy {
public interface ItemSkipPolicy {
/**
* Returns true or false, indicating whether or not reading should
@@ -33,5 +33,5 @@ public interface ReadFailurePolicy {
* @return true if reading should continue, false otherwise.
* @throws IllegalArgumentException if t or stepExecution is null
*/
boolean shouldContinue(Exception ex, StepExecution stepExecution);
boolean shouldSkip(Exception ex, StepExecution stepExecution);
}