diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java index 2e80dea9c..3f16f995d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java @@ -35,6 +35,8 @@ import org.springframework.batch.io.support.AbstractTransactionalIoSource; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; import org.springframework.batch.item.exception.ResetFailedException; import org.springframework.batch.item.exception.StreamException; import org.springframework.beans.factory.InitializingBean; @@ -471,7 +473,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements } - public void clear() throws Exception { + public void clear() throws ClearFailedException { try { getOutputState().reset(); } @@ -480,7 +482,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements } } - public void flush() throws Exception { + public void flush() throws FlushFailedException { getOutputState().mark(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/HibernateAwareItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/HibernateAwareItemWriter.java index c92acd09d..f5087cf6d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/HibernateAwareItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/HibernateAwareItemWriter.java @@ -20,6 +20,8 @@ import java.util.Set; import org.hibernate.SessionFactory; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatListener; @@ -279,7 +281,7 @@ public class HibernateAwareItemWriter implements ItemWriter, RepeatListener, Ini * (non-Javadoc) * @see org.springframework.batch.item.ItemWriter#clear() */ - public void clear() throws Exception { + public void clear() throws ClearFailedException { if (delegate != null) { delegate.clear(); } @@ -290,7 +292,7 @@ public class HibernateAwareItemWriter implements ItemWriter, RepeatListener, Ini * Flush the Hibernate session. The delegate flush will also be called * before finishing. */ - public void flush() throws Exception { + public void flush() throws FlushFailedException { if (delegate != null) { delegate.flush(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java index d61fc86b4..0d6b3fd14 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java @@ -18,6 +18,8 @@ import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; import org.springframework.batch.item.exception.StreamException; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; @@ -422,12 +424,12 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing } - public void flush() throws Exception { + public void flush() throws FlushFailedException { lastCommitPointPosition = getPosition(); lastCommitPointRecordCount = currentRecordCount; } - public void clear() throws Exception { + public void clear() throws ClearFailedException { currentRecordCount = lastCommitPointRecordCount; // close output close(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java index 3086ebc2c..bd8b61ae0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java @@ -16,6 +16,9 @@ package org.springframework.batch.item; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; + /** *

Basic interface for generic output operations. Class implementing this * interface will be responsible for serializing objects as necessary. @@ -49,16 +52,14 @@ public interface ItemWriter { /** * Flush any buffers that are being held. This will usually be performed * prior to committing any transactions. - * - * @throws Exception + * @throws FlushFailedException TODO */ - public void flush() throws Exception; + public void flush() throws FlushFailedException; /** * Clear any buffers that are being held. This will usually be performed * prior to rolling back any transactions. - * - * @throws Exception + * @throws ClearFailedException TODO */ - public void clear() throws Exception; + public void clear() throws ClearFailedException; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/ClearFailedException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/ClearFailedException.java new file mode 100644 index 000000000..072a89b58 --- /dev/null +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/ClearFailedException.java @@ -0,0 +1,51 @@ +/* + * 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; + +import org.springframework.batch.item.ItemWriter; + +/** + * Unchecked exception indicating that an error has occured while + * trying to call {@link ItemWriter#clear()} + * + * @author Lucas Ward + * + */ +public class ClearFailedException extends StreamException { + + /** + * @param message + */ + public ClearFailedException(String message) { + super(message); + } + + /** + * @param msg + * @param nested + */ + public ClearFailedException(String msg, Throwable nested) { + super(msg, nested); + } + + /** + * @param msg + * @param nested + */ + public ClearFailedException(Throwable nested) { + super(nested); + } +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/FlushFailedException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/FlushFailedException.java new file mode 100644 index 000000000..2277b4026 --- /dev/null +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/FlushFailedException.java @@ -0,0 +1,50 @@ +/* + * 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; + +import org.springframework.batch.item.ItemWriter; + +/** + * Unchecked exception indicating that an error has occured while + * trying to call {@link ItemWriter#flush()} + * + * @author Lucas Ward + * + */ +public class FlushFailedException extends StreamException { + /** + * @param message + */ + public FlushFailedException(String message) { + super(message); + } + + /** + * @param msg + * @param nested + */ + public FlushFailedException(String msg, Throwable nested) { + super(msg, nested); + } + + /** + * @param msg + * @param nested + */ + public FlushFailedException(Throwable nested) { + super(nested); + } +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/AbstractItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/AbstractItemWriter.java index 876aac4b0..ec0d0e278 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/AbstractItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/AbstractItemWriter.java @@ -16,6 +16,8 @@ package org.springframework.batch.item.writer; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; /** * Abstract {@link ItemWriter} that allows for base classes to only @@ -27,9 +29,9 @@ import org.springframework.batch.item.ItemWriter; */ public abstract class AbstractItemWriter implements ItemWriter{ - public void flush() throws Exception { + public void flush() throws FlushFailedException { } - public void clear() throws Exception { + public void clear() throws ClearFailedException { } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java index 2525afcf0..7d1e1b514 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java @@ -3,6 +3,8 @@ package org.springframework.batch.item.writer; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; import org.springframework.batch.item.exception.StreamException; import org.springframework.batch.item.stream.ItemStreamSupport; import org.springframework.beans.factory.InitializingBean; @@ -60,14 +62,14 @@ public class DelegatingItemWriter implements ItemWriter, ItemStream, Initializin /** * Delegates to {@link ItemWriter#clear()} */ - public void clear() throws Exception { + public void clear() throws ClearFailedException { writer.clear(); } /** * Delegates to {@link ItemWriter#flush()} */ - public void flush() throws Exception { + public void flush() throws FlushFailedException { writer.flush(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/ItemWriterAdapter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/ItemWriterAdapter.java index 12560cf18..9d85ddd96 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/ItemWriterAdapter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/ItemWriterAdapter.java @@ -17,6 +17,8 @@ package org.springframework.batch.item.writer; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; import org.springframework.batch.support.AbstractMethodInvokingDelegator; @@ -38,14 +40,14 @@ public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implement * No-op, can't call more than one method. * */ - public void clear() throws Exception { + public void clear() throws ClearFailedException { } /* * No-op, can't call more than one method. * */ - public void flush() throws Exception { + public void flush() throws FlushFailedException { } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/PropertyExtractingDelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/PropertyExtractingDelegatingItemWriter.java index a0e9f1d1b..c06ac56bf 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/PropertyExtractingDelegatingItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/PropertyExtractingDelegatingItemWriter.java @@ -17,6 +17,8 @@ package org.springframework.batch.item.writer; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; import org.springframework.batch.support.AbstractMethodInvokingDelegator; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; @@ -67,10 +69,10 @@ public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvoki } - public void clear() throws Exception { + public void clear() throws ClearFailedException { } - public void flush() throws Exception { + public void flush() throws FlushFailedException { } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/HibernateAwareItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/HibernateAwareItemWriterTests.java index 3b66b8a35..ccabf4e70 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/HibernateAwareItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/HibernateAwareItemWriterTests.java @@ -23,6 +23,8 @@ import java.util.Map; import junit.framework.TestCase; import org.springframework.batch.item.ItemWriter; +import org.springframework.batch.item.exception.ClearFailedException; +import org.springframework.batch.item.exception.FlushFailedException; import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatListener; @@ -74,11 +76,11 @@ public class HibernateAwareItemWriterTests extends TestCase { public void close() throws Exception { } - public void clear() throws Exception { + public void clear() throws ClearFailedException { list.add("clear"); } - public void flush() throws Exception { + public void flush() throws FlushFailedException { list.add("flush"); } }