DATAJDBC-150 - Provides better error message when execution of a DbAction fails.
This commit is contained in:
committed by
Greg Turnquist
parent
0ef1a63bda
commit
0b2708ff9a
@@ -86,7 +86,26 @@ public abstract class DbAction<T> {
|
||||
return new DeleteAll<>(type, propertyPath, dependingOn);
|
||||
}
|
||||
|
||||
abstract void executeWith(Interpreter interpreter);
|
||||
/**
|
||||
* Executing this DbAction with the given {@link Interpreter}.
|
||||
*
|
||||
* @param interpreter the {@link Interpreter} responsible for actually executing the {@link DbAction}.
|
||||
*/
|
||||
void executeWith(Interpreter interpreter) {
|
||||
|
||||
try {
|
||||
doExecuteWith(interpreter);
|
||||
} catch (Exception e) {
|
||||
throw new DbActionExecutionException(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executing this DbAction with the given {@link Interpreter} without any exception handling.
|
||||
*
|
||||
* @param interpreter the {@link Interpreter} responsible for actually executing the {@link DbAction}.
|
||||
*/
|
||||
protected abstract void doExecuteWith(Interpreter interpreter);
|
||||
|
||||
/**
|
||||
* {@link InsertOrUpdate} must reference an entity.
|
||||
@@ -113,7 +132,7 @@ public abstract class DbAction<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
void executeWith(Interpreter interpreter) {
|
||||
protected void doExecuteWith(Interpreter interpreter) {
|
||||
interpreter.interpret(this);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +149,7 @@ public abstract class DbAction<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
void executeWith(Interpreter interpreter) {
|
||||
protected void doExecuteWith(Interpreter interpreter) {
|
||||
interpreter.interpret(this);
|
||||
}
|
||||
}
|
||||
@@ -159,7 +178,7 @@ public abstract class DbAction<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
void executeWith(Interpreter interpreter) {
|
||||
protected void doExecuteWith(Interpreter interpreter) {
|
||||
interpreter.interpret(this);
|
||||
}
|
||||
}
|
||||
@@ -176,7 +195,7 @@ public abstract class DbAction<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
void executeWith(Interpreter interpreter) {
|
||||
protected void doExecuteWith(Interpreter interpreter) {
|
||||
interpreter.interpret(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 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.data.jdbc.core.conversion;
|
||||
|
||||
/**
|
||||
* Exception thrown when during the execution of a {@link DbAction} an exception gets thrown. Provides additional
|
||||
* context information about the action and the entity.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class DbActionExecutionException extends RuntimeException {
|
||||
public DbActionExecutionException(DbAction<?> action, Throwable cause) {
|
||||
super( //
|
||||
String.format("Failed to execute %s for instance %s of type %s with path %s", //
|
||||
action.getClass().getSimpleName(), //
|
||||
action.getEntity(), //
|
||||
action.getEntityType(), //
|
||||
action.getPropertyPath().toDotPath() //
|
||||
), //
|
||||
cause);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user