Hi,
I've played around with query cancellation a couple of years ago (on
Oracle btw), the strategy I found to be least intrusive was to wrap the
JDBC connection/statements in my own Connection/*Statement classes and
let statements register themselves somewhere accessible from other
threads on creation and unregister on .close() before delegating to the
inner instance.
How you glue in the wrapped JDBC objects depends on your setup - you
could create your own wrapping Driver or DataSource/DataSourceFactory.
On my part it was an attempt to isolate the query cancellation stuff
from an old webapp framework in order to be able to eliminate lots of
home rolled jdbc/transaction handling and make it easier to integrate
things like spring and cayenne, while maintaining the original
feature-set (which included query cancellation). In the end it turned
out that query cancellation wasn't really necessary and it was replaced
by a fixed transaction timeout instead. (Simple cancellation was a
breeze, but allowing the user to choose whether he would cancel or force
a long-running query turned out to be a mess in our case)
Hth!
-- ChrisOn 18-08-2010 21:54, 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 - 15:43:06 UTC