Changed the exception being thrown in the ChunkListenerAdatper from BatchRuntimeExcpetion to UncheckedTransactionException so it will be unwrapped by TaskletStep
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user