我不明白为什么抛出运行时异常时调用after()
函数。DBConnectionFilter
我期待onException()
调用函数并回滚事务。但真正发生的是该after()
函数将被调用以提交事务并关闭数据库连接,然后 onException
调用来自 CatchAllFilter/kind of global filter/ 的该函数。
AppControllerConfig 类:
public class AppControllerConfig extends AbstractControllerConfig{
public void init(AppContext context) {
add(new CatchAllFilter(), new DBConnectionFilter("default",true));
}
}
PeopleController 创建函数:
@POST
public void create() throws IOException {
String incomingPost = Util.read(getRequestInputStream());
Map[] people = JsonHelper.toMaps(incomingPost);
Person newPerson = new Person();
newPerson.fromMap(people[0]);
boolean response = newPerson.save();
//Making sure person info is persisted so that it can be Rolled back
if (response == true) {
throw new InitException("Rollback Transaction");
}
render("/system/RestIndex").noLayout().contentType("application/json");
view("jsonResponse", Person.findAll().toJson(true));
}