Re: Interrupting a fetch that is taking too long
Re: Interrupting a fetch that is taking too long
- Subject: Re: Interrupting a fetch that is taking too long
- From: Patrick Middleton <email@hidden>
- Date: Wed, 16 May 2007 10:24:58 +0100
On 15 May 2007, at 21:34, Ricardo Parada wrote:
Hi All,
Let's say I have a GUI that lets users build queries to be used for
a report. Then another process generates a report by applying
this user defined query. However, if the query takes too long I
would like to interrupt the query and then flag query for special
handling.
Has anybody figured out a way to interrupt a fetch in EOF?
On 16 May 2007, at 00:23, Art Isbell wrote:
On May 15, 2007, at 12:04 PM, John Huss wrote:
Actually terminating a query in progress is database-specific, so
there is no EOF way to do it.
EOAdaptor's cancelFetch() should do what the method name implies.
Each database plugin includes an EOAdaptor subclass that overrides
cancelFetch() to do the database-specific mojo necessary to cancel
a fetch in progress.
You'd probably need to write your own fetchRow() loop checking at
each iteration whether to cancel the fetch. But doing so isn't as
easy in a WO app with its very long event loop compared with the
desktop environment with its short event loop. Maybe you could
have a timer running in one thread set a "cancelFetch" variable to
true while the fetch loop in a different thread could check the
value of "cancelFetch" during each iteration. But then you'd need
to turn this array of fetched dictionaries into EO's in an editing
context in the same way as using an editing context to fetch which
isn't something that I'd like to mimic.
Aloha,
Art
My experience of EOAdaptor's cancelFetch() began with an AppKit app
using EOF 2.x.
GUI app Ricardo? Want kind of GUI app? Critically, are you doing
doing something like an isql client (one user, one database
connection, two-tier architecture) or classic WebObjects application
(many users, one pooled database connection, three-tier architecture)?
Whichever -- and I'm sure you're already on top of this -- you will
need to have the fetch build+execute run in one thread, and some sort
of monitoring facility with a cancel button available to the user in
another thread. EOF either uses locking or assumes locking will be
used on its behalf to ensure that database i/o will be threadsafe.
You cannot call EOAdaptor's cancelFetch() from another thread.
Instead, use EOAdaptorChannel delegate API so that the build/fetch
thread can tell whether or not it should continue fetching (because
your cancel button leads to a flag being changed somewhere; this is
much as Art suggests, except that there are hooks available to do
what he suggests with a reduced need for rewriting or subclassing).
If your app is an application server, this approach works well with
WOLongResponse page.
Moreover: when I last used the JavaJDBCAdaptor to do something like
this with Sybase, EOAdaptor's cancelFetch() did not work. There were
reasons why it did not work. If you cancelled a fetch after x rows
and there were x+y rows to be returned, the adaptor would clear the
reuslts set by fetching the other y rows, and so cancelling the fetch
wouldn't help because it doesn't reduce the amount of database i/o
that occurs. I found a workaround; if the problem is still present,
you should be able to exploit the workaround I found.
http://www.wodeveloper.com/omniLists/ webobjects-dev/2003/July/
msg00300.html
http://www.wodeveloper.com/omniLists/ webobjects-dev/2003/July/
msg00470.html
--
Patrick Middleton
OneStep Solutions plc
351 London Road Phone: +44 (0)1702 426400
Hadleigh Fax: +44 (0)1702 556855
Essex. SS7 2BT Email: email@hidden
England (MIME welcome)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden