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).
我正在使用jOOQ v2.6,因為我正在使用SQL Server 2008 R2,並且jOOQ v3.1中存在一個錯誤導致代碼生成失敗。 (我知道這將在v3.2中修復)。
From the manual:
從手冊:
// Create a new record
BookRecord book1 = create.newRecord(BOOK);
// Insert the record: INSERT INTO BOOK (TITLE) VALUES ('1984');
book1.setTitle("1984");
book1.store();
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.
如果store()失敗,則拋出DataAccessException。在我的情況下,我只是喜歡睡眠過程,直到CRUD操作工作,或者我觀察問題並進行干預。這意味着我需要在try / catch中包裝BookRecord.store()的每個實例。這適用於所有UpdatableRecords中的所有CRUD操作。
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?
有沒有一種簡單的方法可以處理所有生成的Record類型的所有CRUD DataAccessExceptions,而不必記得一遍又一遍地實現相同的異常處理程序?
3
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:
我不是100%確定這是否符合您的實際要求,但是使用ExecuteListener,您可以掛鈎到jOOQ的一般查詢執行生命周期並將一些行為注入到jOOQ的異常處理中。這里給出了一些例子:
http://www.jooq.org/doc/3.1/manual/sql-execution/execute-listeners
In particular, your custom ExecuteListener
might look like this:
特別是,您的自定義ExecuteListener可能如下所示:
public class MyListener extends DefaultExecuteListener {
@Override
public void exception(ExecuteContext ctx) {
// Put some logic here
}
}
Note, this currently won't prevent the throwing of the exception, itself.
注意,這當前不會阻止拋出異常本身。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/09/21/72536fdc061ea27a223b4b66dbd63d6f.html。