You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by "Craig L Russell (JIRA)" <ji...@apache.org> on 2016/11/04 20:02:58 UTC

[jira] [Commented] (JDO-735) Make PersistenceManager and Query support AutoCloseable (JDK1.7+)

    [ https://issues.apache.org/jira/browse/JDO-735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15637513#comment-15637513 ] 

Craig L Russell commented on JDO-735:
-------------------------------------

There are several competing interests here:

1. Dissuade programmers from using close(). They should use closeAll() instead. With autocomplete in their Java IDE, when they start to type clos they should get javadoc which should say "don't use this method; use closeAll instead".

2. If programmers accidentally use close() they should have to catch Exception, which is the only method in JDO that throws Exception. So we need to either *not* declare close() in the interfaces or declare close() with the throws Exception clause.

3. If we declare void close() throws Exception and say its semantics are identical to closeAll(), users might think "If semantics are identical, why does close() throw Exception and closeAll() does not"?

The best solution seems to be:

Declare (override) void close() throws Exception in the Query and Extent interfaces. Provide javadoc that says "don't use this method. It is intended for use by try-with-resources. Use closeAll() instead."


> Make PersistenceManager and Query support AutoCloseable (JDK1.7+)
> -----------------------------------------------------------------
>
>                 Key: JDO-735
>                 URL: https://issues.apache.org/jira/browse/JDO-735
>             Project: JDO
>          Issue Type: New Feature
>          Components: api, specification, tck
>            Reporter: Andy Jefferson
>            Assignee: Michael Bouschen
>             Fix For: JDO 3.2
>
>         Attachments: CloseWithActiveTxRollsBack.java
>
>
> So then it can be used with JDK1.7+ try-with-resources, as per http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)