How "cancel query" works in SQL Developer

In SQL Developer, clicking the Cancel Task button stops the execution of the query. I have to implement the same functionality in our project.

cancel query iamge

I am using BC4J as an ORM tool to execute queries. I need to reverse the execution of a search query called thorugh view objects that calls multiple database functions / procedures to get the result.

I've tried using it viewObject.cancelQuery();

, but it has no effect; the request continues to execute until the end.

I am connecting through a JDBC connection pool handled by BC4J.

+3


source to share


1 answer


My suggestion

  • When the request is sent
    • block any UI command accept "undo" (easiest way: use a modal dialog for this, more user-friendly: block only local view commands)
    • Run the request on a separate thread other than the UI thread, use an implementation Runnable

      that
      • has its own method cancel()

        which
        • calls cancelQuery

          accordingly. cancel

          your request
        • pass this event to your runnable request with <query thread>.interrupt()

          ; for this you need to save the link to your request flow in <query thread>

          . Active I / O operations are sometimes interrupted by this signal!
      • can handle InterruptedException

        and SQLException

        in run()

        : if these exceptions are executed by a rollback transaction (if at all triggered for a read-only request)
      • If this runnable has multiple long statements then check Thread.currentThread().isInterrupted()

        after each statement cancel()

        if the result is correct.
  • when the query completes, sync your results with your UI
  • on cancel:
    • calling cancel()

      your query runnable
    • forget the thread (but don't forget to exhaust system resources or connection pool if too many canceled threads are not finished yet)
    • unlock your user interface


Swing has helper classes as well as Eclipse RCP that support this design.

+2


source







All Articles