I've been looking at implementing Statement.cancel(), and later, Statement.setQueryTimeout().

My proposal is as follows:
* Add these two methods to org.apache.derby.iapi.sql.conn.StatementContext:
public boolean isCancelled();
public void cancel();
* Implement these in org.apache.derby.impl.sql.conn.GenericStatementContext, simply operating on a private boolean flag (with proper synchronization). Of course, clear it in the clearInUse() method.
* From the getNextRowCore() method of various "bottom-level" (referring to the ResultSet hierarchy) ResultSet implementations (such as [Bulk]TableScanResultSet), get the executing statement's StatementContext object (see below) and call its isCancelled() method. If it returns true, throw StandardException.newException(SQLState.LANG_STATEMENT_CLOSED).
* From EmbedStatement.cancel(), get the statement's StatementContext object (see below) and call its cancel() method. (First check the statement's active flag.)


I have tested this and it seems to work fine according to the semantics we discussed in earlier mails. However, I am unsure of the correct way to "get the executing statement's StatementContext object".

From the ResultSet side, the BasicNoPutResultSet class contains a declaration

  // set on demand during execution
  private StatementContext statementContext;

but this reference has the value null where I need it. There exists a method attachStatementContext(), but this does no assignment unless the isTopResultSet attribute is true - which it rarely is in my case.

From the EmbedStatement class, there is no direct reference to a StatementContext object.

What I have been testing so far is using the LanguageConnectionContext.getStatementContext() method through the lcc reference available to both EmbedStatement and BasicNoPutResultSet. However, it seems odd to me to go through a "connection context" object to get the statement context. I'm not sure this is the right way to do it. What if, for instance, there are multiple open statements on the same connection? What statement's context object is returned?

--
�yvind Bakksj�
Sun Microsystems, Web Services, Database Technology Group
Haakon VII gt. 7b, N-7485 Trondheim, Norway
Tel: x43419 / +47 73842119, Fax: +47 73842101

Reply via email to