覆盖jOOQ的异常处理UpdatableRecords [英] Overriding jOOQ's exception handling for UpdatableRecords

查看:271
本文介绍了覆盖jOOQ的异常处理UpdatableRecords的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用jOOQ V2.6因为我使用SQL Server 2008 R2并没有导致code一代失败的jOOQ V3.1中的错误。 (我知道这将是固定在V3.2)。

I'm using jOOQ v2.6 as I'm using SQL Server 2008 R2 and there is a bug in jOOQ v3.1 which causes code generation to fail. (I'm aware this will be fixed in v3.2).

这本手册:

// Create a new record
BookRecord book1 = create.newRecord(BOOK);

// Insert the record: INSERT INTO BOOK (TITLE) VALUES ('1984');
book1.setTitle("1984");
book1.store();

如果存储()失败,DataAccessException的异常。在我来说,我只想进程睡眠,直到该CRUD操作的工作方式,或者我观察问题和干预。这意味着,我需要在一个try / catch包装BookRecord.store()的每个实例。然后,这适用于所有的CRUD操作,在所有UpdatableRecords。

If store() fails, a DataAccessException is thrown. In my case I would simply like the process to sleep until either the CRUD operation works, or I observe the issue and intervene. This means that I need to wrap every instance of BookRecord.store() in a try/catch. This then applies to all CRUD operations, across all UpdatableRecords.

有没有办法,我可以处理所有CRUD的DataAccessExceptions所有生成的记录类型,而不必记住一遍又一遍,以实现相同的异常处理程序的简单方法?

Is there a simple way that I can handle all CRUD DataAccessExceptions for all generated Record types, without having to remember to implement the same exception handler over and over again?

推荐答案

我不是100%肯定这是否会满足您的实际需求,但使用的 ExecuteListener ,你可以连接到jOOQ的一般查询执行的生命周期和注入一些行为到jOOQ的异常处理。一些实施例在这里给出:

I'm not 100% sure if this will meet your actual requirements, but using an ExecuteListener, you can hook into jOOQ's general query execution lifecycle and inject some behaviour into jOOQ's exception handling. Some examples are given here:

http://www.jooq.org/doc/ 3.1 /手动/ SQL-执行/执行-听众

在特定的,您的自定义 ExecuteListener 可能是这样的:

In particular, your custom ExecuteListener might look like this:

public class MyListener extends DefaultExecuteListener {

    @Override
    public void exception(ExecuteContext ctx) {
        // Put some logic here
    }
}

请注意,这个目前不会prevent的异常抛出,本身。

Note, this currently won't prevent the throwing of the exception, itself.

这篇关于覆盖jOOQ的异常处理UpdatableRecords的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆