closeOnCompletion

Filipe Silva filipe.silva at oracle.com
Wed Feb 17 19:14:42 UTC 2021


Hi Douglas,


Wait, this is not the question here, there is no doubt that closing the 
result sets closes the statement. The question is whether a statement 
with `closeOnCompletion` and an active results set (not closed yet) can 
be re-executed or not. In different words, implicit closing of open 
result sets on next statement execution triggers `closeOnCompletion` and 
closes the statement or should it execute?


Regards,
Filipe



On 17/02/21 19:03, Douglas Surber wrote:
> As I said I wrote the original proposal and what I intended and what 
> the EG discussed at the time at least implicitly was that closing the 
> open ResultSet would close the Statement and that no subsequent 
> execution was possible. No this wasn't spelled out in the discussion. 
> It was clearly the intent as the purpose of the method was to handle 
> the case Lance described.
>
> Maybe the language is unclear but I don't think that would justify 
> expanding the behavior of the method to cover your use case. The goal 
> is to support a specific use case. Any change to the spec should be to 
> more clearly state how that use case is supported, not to expand the 
> meaning to support additional use cases, especially a use case that 
> has never come up in practice.
>
> Douglas
> ------------------------------------------------------------------------
> *From:* Filipe Silva <filipe.silva at oracle.com>
> *Sent:* Wednesday, February 17, 2021 10:55 AM
> *To:* Dave Cramer <davecramer at gmail.com>; Douglas Surber 
> <douglas.surber at oracle.com>
> *Cc:* Lance Andersen <lance.andersen at oracle.com>; 
> jdbc-spec-discuss at openjdk.java.net <jdbc-spec-discuss at openjdk.java.net>
> *Subject:* Re: closeOnCompletion
>
> Well, looks strange to me. I explain why in the an answer I wrote in 
> StackOverflow 
> (https://stackoverflow.com/questions/66241480/jdbc-statement-closeoncompletion-should-close-statement-on-next-execution/66248074#66248074).
>
> Moreover, IMO, allowing re-executions doesn't conflict with the use 
> case below and it allows more.
>
> Regards,
> Filipe
>
> On 17/02/21 18:38, Dave Cramer wrote:
>>
>>
>> On Wed, 17 Feb 2021 at 13:33, Douglas Surber 
>> <douglas.surber at oracle.com <mailto:douglas.surber at oracle.com>> wrote:
>>
>>     I wrote the original proposal. The intent was to handle the case
>>     Lance described. It was not intended to allow multiple executions
>>     of the Statement. So while the language may not be as clear as it
>>     needs to be, the case Filipe described should throw on the second
>>     execution of the Statement. At least that was my intent.
>>
>>
>> Well there's enough hints in the wording to figure that out, but they 
>> are just hints.
>> We (postgres) are going to implement it in such a way that the 
>> statement will not be executed twice
>>
>> Dave
>>
>>     Douglas
>>     ------------------------------------------------------------------------
>>     *From:* jdbc-spec-discuss
>>     <jdbc-spec-discuss-retn at openjdk.java.net
>>     <mailto:jdbc-spec-discuss-retn at openjdk.java.net>> on behalf of
>>     Lance Andersen <lance.andersen at oracle.com
>>     <mailto:lance.andersen at oracle.com>>
>>     *Sent:* Wednesday, February 17, 2021 9:52 AM
>>     *To:* Dave Cramer <davecramer at gmail.com
>>     <mailto:davecramer at gmail.com>>
>>     *Cc:* Filipe Silva <filipe.silva at oracle.com
>>     <mailto:filipe.silva at oracle.com>>;
>>     jdbc-spec-discuss at openjdk.java.net
>>     <mailto:jdbc-spec-discuss at openjdk.java.net>
>>     <jdbc-spec-discuss at openjdk.java.net
>>     <mailto:jdbc-spec-discuss at openjdk.java.net>>
>>     *Subject:* Re: closeOnCompletion
>>     I will have to go dig back through my email archive as this was
>>     first discussed in 2009.
>>
>>
>>     The overall intent was to deal with code similar to:
>>
>>     ----------------------
>>     ResultSet rs = foo();
>>      while(rs.next() {
>>          /*do something */
>>     }
>>     rs.close();
>>
>>     public ResultSet foo() {
>>
>>        Statement stmt = con.createStatement();
>>        stmt.closeOnCompletion();
>>        ResultSet rs = stmt.executeQuery(aQuery);
>>        return rs
>>
>>     }
>>     ------------------
>>
>>
>>     We did spend a lot of time on this back in 2009 and took quite a
>>     bit of time to reach agreement on the current wording.  However,
>>     it does  look like there is the potential for some additional
>>     word smithing.
>>
>>     Best
>>     Lance
>>
>>
>>
>>     On Feb 17, 2021, at 12:34 PM, Dave Cramer <davecramer at gmail.com
>>     <mailto:davecramer at gmail.com><mailto:davecramer at gmail.com
>>     <mailto:davecramer at gmail.com>>> wrote:
>>
>>     On Wed, 17 Feb 2021 at 12:13, Filipe Silva
>>     <filipe.silva at oracle.com
>>     <mailto:filipe.silva at oracle.com><mailto:filipe.silva at oracle.com
>>     <mailto:filipe.silva at oracle.com>>> wrote:
>>
>>     On 17/02/21 10:53, Dave Cramer wrote:
>>     Interesting situation.
>>
>>     If we have an open statement with open resultsets and call
>>     closeOnCompletion and then execute the statement a second time the
>>     statement will throw an already closed exception since the spec
>>     says that
>>     executing a statement a second time closes any open resultsets.
>>     Closing
>>     said resultsets ends up closing the statement.
>>
>>     I'm just confirming that this is the intended behaviour. Seems about
>>     right
>>     since if you set closeOnCompletion you would not expect to re-use the
>>     statement.
>>
>>     Dave Cramer
>>     No, I don't think it is supposed to work like this. "Completion"
>>     means
>>     that the user is done with the ResultSet(s) and explicitely calls
>>     close() on it/them.
>>
>>     Successive executions do close previously opened ResultSets but
>>     closing
>>     those ResultSets implicitely (by re-executing) do not close the
>>     Statement. The documentation makes it clear when it says "a call to
>>     |closeOnCompletion| does effect both the *subsequent execution of
>>     statements*, (...)". There would be no "subsequent execution of
>>     statements" if the behavior was the one you described.
>>
>>
>>     Well interestingly I'm told that the Oracle driver does close the
>>     statement
>>     on subsequent execution.
>>
>>     Either way I'm not sure I agree with the inference. Now we have
>>     to debate
>>     the word execution. Is calling the method an execution or is
>>     completing the
>>     call an execution ?
>>
>>     Dave Cramer
>>
> -- 
>
> Oracle <http://www.oracle.com>
> Filipe Silva, Senior Software Developer
> Mobile: +351.91.009.2110
> MySQL Middleware and Clients
> Oracle Portugal, Lagoas Park, Edifício N.º 8, 2740-244 Porto Salvo
>
>
-- 

Oracle <http://www.oracle.com>
Filipe Silva, Senior Software Developer
Mobile: +351.91.009.2110
MySQL Middleware and Clients
Oracle Portugal, Lagoas Park, Edifício N.º 8, 2740-244 Porto Salvo




More information about the jdbc-spec-discuss mailing list