[ 
https://issues.apache.org/jira/browse/TINKERPOP3-764?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

stephen mallette updated TINKERPOP3-764:
----------------------------------------
    Summary: Consider CLOSE_BEHAVIOR Operations   (was: Better Method for Close 
Operation)

I didn't change much code here yet, but I think I straightened out some 
confusing semantics.  {{CLOSE_BEHAVIOR}} had some mixed meaning in terms of 
documentation, usage and test cases.  Sometimes it referred to how a {{Graph}} 
should behave on {{close}} and sometimes it referred to closing the "active" 
transaction. 

I think that the original intention for {{Transaction.close}} was to supply 
configurable behavior to {{Graph.close}}.  I'm not sure I like that anymore for 
a couple reasons:

1. It's too easy for a user to call {{graph.tx().close()}} thinking of it as 
closing a transaction which it is doing in a {{ThreadLocal}} way, but that 
wasn't the intended purpose.
2. The {{CLOSE_BEHAVIOR}} isn't useful outside of the current thread, so 
calling {{Transaction.close}} from {{Graph.close}} doesn't really have the 
intended effect.

So, thus far, I've cleaned up the docs in 3.0.1 to indicate that the 
{{Transaction.close}} method is to "close the current transaction".  I've also 
altered the Gremlin Test Suite to stop enforcing {{CLOSE_BEHAVIOR}} from 
{{Graph.close}}. That change actually did something interesting in that I was 
able to remove the one {{OptOut}} from {{Neo4jGraph}} - all tests now pass.

So that leaves us with clear semantics, but more change might still be in 
order.  I'm of the opinion that we should deprecate {{Transaction.close}} and 
at some point remove {{Closeable}} as an interface it implements.  I don't 
think we want to encourage this style:

{code}
try (Transaction tx = graph.tx()) {
  ...
}
{code}

and then, why would anyone do:

{code}
graph.addVertex()
graph.tx().close()
{code}

They would be better served to do:

{code}
try {
  graph.addVertex()
  graph.tx().commit()
} catch (Exception ex) {
  graph.tx().rollback()
}
{code}


> Consider CLOSE_BEHAVIOR Operations 
> -----------------------------------
>
>                 Key: TINKERPOP3-764
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP3-764
>             Project: TinkerPop 3
>          Issue Type: Improvement
>          Components: structure
>    Affects Versions: 3.0.0-incubating
>            Reporter: stephen mallette
>            Assignee: stephen mallette
>             Fix For: 3.0.1-incubating
>
>
> {{CLOSE_BEHAVIOR}} implementations only close
> the transaction of the current thread that closed the graph which potentially 
> leaves open others.  Consider methods to improve on this.



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

Reply via email to