Good question... Cleanly canceling threads can be challenging.
There is a java.sql.Statement.cancel() method that, depending on a database, may or may not abort the query, but to get a hold of it in Cayenne, you may have to go pretty deep down the stack to customize query execution. A possible way of doing it is by overriding "createSQLAction" [1], and experimenting with subclassing standard SQLActions to expose active Statement to cancel by another thread. If you go this route, make sure first that DB2 driver provides a working "cancel" implementation.
Alternatively a normal way of canceling threads via Thread.interrupt() call is unlikely to work, but still worth a try.
Andrus
[1] http://cayenne.apache.org/doc30/customizing-queries.html
On Aug 18, 2010, at 10:54 PM, Nikolaos Paraschou wrote:
> Hello,
>
> I have written a small application in java that interacts with db2 using
> apache cayenne.
> The application sends a long running query to the db2 server and awaits
> response. The query starts executing from within SwingWorker's
> doInBackground() method. During the query's execution, a cancel button
> appears allowing the user to cancel the operation. When clicked,
> SwingWorker's cancel() is called and everything seems to work fine regarding
> java code. The SwingWorker thread is canceled (I can confirm that). But,
> unfortunately, the other thread running the query doesn't stop (or perhaps
> it stops but the query is already being processed by db2 until finished).
>
> Is there any way to stop the query using cayenne specific methods? I tried
> to create a new DataContext and bind it to the running thread (the following
> code is executed inside doInBackground():
>
> BaseContext.bindThreadObjectContext(DataContext.createDataContext());
> ObjectContext oc = BaseContext.getThreadObjectContext();
>
> return oc.performQuery(longRunQuery);
>
> No success.
>
> Thank you,
> Nikos
This archive was generated by hypermail 2.0.0 : Thu Aug 19 2010 - 07:34:03 UTC