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

Tilmann Zäschke commented on JDO-735:
-------------------------------------

Apologies for commenting so late.
I see a small problem with making PersistenceManager auto-closeable:
If I understand the spec (12.6) correctly, PM.close() will throw an Exception 
if an transaction is active.
Since, in my experience, database exceptions mostly occur during open 
transactions, the auto-close will fail in most cases.
One problem with this is probably that this will always swallow the actual 
error, only the failed close()-exception will be reported.

A solution would be to change the spec such that calling close() on an open 
Transaction simply aborts() the transaction before closing it.
I would prefer that anyway, because it would solve a separate problem that I 
usually have to do if-pm-is-active-then-abort-before-close in many catch 
blocks, which feels a bit like unnecessary boilerplate code.

Any thoughts on this? 


I understand that this is a spec change, but I suppose it should be mostly 
backwards compatible. Also, I guess this should probably go into a separate 
issue.


> 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
>             Fix For: JDO 3.2
>
>
> 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)

Reply via email to