diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/ChunkListenerAdapter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/ChunkListenerAdapter.java index bfae4112a..caca45527 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/ChunkListenerAdapter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/ChunkListenerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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. @@ -19,6 +19,7 @@ import javax.batch.operations.BatchRuntimeException; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.scope.context.ChunkContext; +import org.springframework.batch.core.step.tasklet.UncheckedTransactionException; import org.springframework.util.Assert; /** @@ -45,7 +46,7 @@ public class ChunkListenerAdapter implements ChunkListener { try { delegate.beforeChunk(); } catch (Exception e) { - throw new BatchRuntimeException(e); + throw new UncheckedTransactionException(e); } } @@ -54,7 +55,7 @@ public class ChunkListenerAdapter implements ChunkListener { try { delegate.afterChunk(); } catch (Exception e) { - throw new BatchRuntimeException(e); + throw new UncheckedTransactionException(e); } } @@ -64,7 +65,7 @@ public class ChunkListenerAdapter implements ChunkListener { try { delegate.onError((Exception) context.getAttribute(ChunkListener.ROLLBACK_EXCEPTION_KEY)); } catch (Exception e) { - throw new BatchRuntimeException(e); + throw new UncheckedTransactionException(e); } } else { throw new BatchRuntimeException("Unable to retrieve causing exception due to null ChunkContext"); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java index 7cca3e0af..15752c377 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2014 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. @@ -496,20 +496,4 @@ public class TaskletStep extends AbstractStep { } } - - /** - * Convenience wrapper for a checked exception so that it can cause a - * rollback and be extracted afterwards. - * - * @author Dave Syer - * - */ - private static class UncheckedTransactionException extends RuntimeException { - - public UncheckedTransactionException(Exception e) { - super(e); - } - - } - } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/UncheckedTransactionException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/UncheckedTransactionException.java new file mode 100644 index 000000000..189ea2985 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/UncheckedTransactionException.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 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.step.tasklet; + +/** + * Convenience wrapper for a checked exception so that it can cause a + * rollback and be extracted afterwards. + * + * @author Dave Syer + * + */ +@SuppressWarnings("serial") +public class UncheckedTransactionException extends RuntimeException { + + public UncheckedTransactionException(Exception e) { + super(e); + } +} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java index dabfbd213..1a0d1c415 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013-2014 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.jsr; import static org.mockito.Mockito.doThrow; @@ -12,6 +27,7 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.batch.core.scope.context.ChunkContext; +import org.springframework.batch.core.step.tasklet.UncheckedTransactionException; public class ChunkListenerAdapterTests { @@ -39,7 +55,7 @@ public class ChunkListenerAdapterTests { verify(delegate).beforeChunk(); } - @Test(expected=BatchRuntimeException.class) + @Test(expected=UncheckedTransactionException.class) public void testBeforeChunkException() throws Exception { doThrow(new Exception("This is expected")).when(delegate).beforeChunk(); adapter.beforeChunk(null); @@ -52,7 +68,7 @@ public class ChunkListenerAdapterTests { verify(delegate).afterChunk(); } - @Test(expected=BatchRuntimeException.class) + @Test(expected=UncheckedTransactionException.class) public void testAfterChunkException() throws Exception { doThrow(new Exception("This is expected")).when(delegate).afterChunk(); adapter.afterChunk(null); @@ -63,7 +79,7 @@ public class ChunkListenerAdapterTests { adapter.afterChunkError(null); } - @Test(expected=BatchRuntimeException.class) + @Test(expected=UncheckedTransactionException.class) public void testAfterChunkErrorException() throws Exception { doThrow(new Exception("This is expected")).when(delegate).afterChunk(); adapter.afterChunk(null);