Cancelling/Interrupting long queries

25 views
Skip to first unread message

spiel.c...@gmail.com

unread,
Mar 9, 2015, 10:50:33 AM3/9/15
to jooq...@googlegroups.com
Dear all,

Currently I am programming a database app using JOOQ where most of the queries are performed within SwingWorkers (i.e. in a thread different from the EDT).

What is the preferred way to cancel a (long running) query such as the following within a SwingWorker:

class Worker extends SwingWorker...
{
protected Void doInBackground() 
{
//this takes a long time
Result<Record> data = create.fetch(Query);

//this is rather quick
for (Record r : data) {
     publish(r);
}
}
}
checking for SwingWorker.isCancelled() in the for loop does not make sense as the most time is spend in the query itself. How can I programmatically abort the query execution?

Thanks and best regards

Christian

Lukas Eder

unread,
Mar 9, 2015, 10:55:48 AM3/9/15
to jooq...@googlegroups.com
jOOQ supports Query.cancel(), which calls through to JDBC's Statement.cancel(). If your database can cancel statements, this might be the way to go if the database takes long to respond.

If, however, the problem is the fetching itself, then you should probably use fetchLazy() instead of fetch():

fetchLazy() will keep an open JDBC ResultSet and consume one record at a time. Since you call publish record by record, this is probably a good idea anyway.

Hope this helps,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages