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

ASF GitHub Bot commented on JENA-1090:
--------------------------------------

Github user ajs6f commented on the issue:

    https://github.com/apache/jena/pull/153
  
    We usually use `try-finally` for the transaction cycle, i.e.
    ```
    try {
        transactionalThing.begin(readWrite);
        //do some stuff
        transactionalThing.commit(); // if a write transaction
    }
    finally {
        transactionalThing.end();
    }
    ```
    Looking at `onThrowable` it looks like if the `Transactional txn` throws 
anything other than a `JenaTransactionException` out of `txn.abort()`, then 
`txn.end()` will never get called. Does that open a whole for `txn` to never 
actually finish aborting/ending?


> Add transaction handling convenience code
> -----------------------------------------
>
>                 Key: JENA-1090
>                 URL: https://issues.apache.org/jira/browse/JENA-1090
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: ARQ
>            Reporter: Andy Seaborne
>
> The code 
> [Txn|https://github.com/afs/jena-rdfconnection/blob/master/src/main/java/rdfconnection/Txn.java]
>  provides a convenient way to write common patterns of transaction usage 
> including 
> {noformat}
>  Txn.executeWrite(conn, () ->{
>        ... write transaction code ...
>         }) ;
> {noformat}
> which provides the pattern:
> {noformat}
> txn.begin(ReadWrite.WRITE) ;
> try {
>     ... write transaction code ...
>     txn.commit() ;
> }
>  finally { txn.end() ; }
> {noformat}
> {{Txn}} also checks for being in a transaction already.
> There are forms to return a value from the code inside the transaction block 
> as well.



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

Reply via email to