From a7fe4db96e00c6aa1ea8a47dd7673ac1a4410907 Mon Sep 17 00:00:00 2001 From: lucasward Date: Tue, 4 Mar 2008 19:32:49 +0000 Subject: [PATCH] BATCH-413: Added a more specific exception type for when an item reader doesn't find any work. --- .../io/driving/DrivingQueryItemReader.java | 4 +-- .../item/exception/NoWorkFoundException.java | 30 +++++++++++++++++++ .../driving/DrivingQueryItemReaderTests.java | 6 ++-- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/NoWorkFoundException.java diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java index 0c49fc742..76b0d7e90 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java @@ -21,8 +21,8 @@ import java.util.List; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; +import org.springframework.batch.item.exception.NoWorkFoundException; import org.springframework.beans.factory.InitializingBean; -import org.springframework.dao.DataRetrievalFailureException; import org.springframework.util.Assert; /** @@ -141,7 +141,7 @@ public class DrivingQueryItemReader implements ItemReader, InitializingBean, + ", call close() first."); keys = keyGenerator.retrieveKeys(executionContext); if(keys == null || keys.size() == 0){ - throw new DataRetrievalFailureException("KeyGenerator must return at least 1 key"); + throw new NoWorkFoundException("KeyGenerator must return at least 1 key"); } keysIterator = keys.listIterator(); initialized = true; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/NoWorkFoundException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/NoWorkFoundException.java new file mode 100644 index 000000000..5640f94d4 --- /dev/null +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/NoWorkFoundException.java @@ -0,0 +1,30 @@ +/* + * 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.item.exception; + +/** + * Exception indicating that an {@link ItemReader} found + * no work to process while initializing. + * + * @author Lucas Ward + * + */ +public class NoWorkFoundException extends StreamException { + + public NoWorkFoundException(String msg) { + super(msg); + } +} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java index 8eeed6246..f7de972a0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java @@ -7,11 +7,11 @@ import java.util.Properties; import junit.framework.TestCase; import org.springframework.batch.io.sample.domain.Foo; +import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.ExecutionContext; +import org.springframework.batch.item.exception.NoWorkFoundException; import org.springframework.beans.factory.InitializingBean; -import org.springframework.dao.DataRetrievalFailureException; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -170,7 +170,7 @@ public class DrivingQueryItemReaderTests extends TestCase { itemReader.open(new ExecutionContext()); fail(); } - catch(DataRetrievalFailureException ex){ + catch(NoWorkFoundException ex){ //expected } }