[
https://issues.apache.org/jira/browse/JENA-1231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15474988#comment-15474988
]
ASF GitHub Bot commented on JENA-1231:
--------------------------------------
Github user afs commented on a diff in the pull request:
https://github.com/apache/jena/pull/168#discussion_r78088121
--- Diff:
jena-core/src/main/java/org/apache/jena/graph/impl/TransactionHandlerBase.java
---
@@ -36,21 +40,45 @@ public TransactionHandlerBase() {
*/
@Override
public Object executeInTransaction(Command c) {
+ return executeRtn( () -> c.execute() ) ;
+ }
+
+ /* Abort but don't let problems with the transaction system itself
cause loss of the exception */
+ private void abort(Throwable e) {
+ try { abort() ; }
+ catch (Throwable th) { e.addSuppressed(th); }
+ }
+
+ /**
+ * Execute the runnable <code>action</code> within a transaction. If
it completes normally,
+ * commit the transaction, otherwise abort the transaction.
+ */
+ @Override
+ public void execute( Runnable action ) {
begin() ;
- Object result ;
try {
- result = c.execute() ;
+ action.run();
commit() ;
- return result ;
}
catch (JenaException e) { abort(e) ; throw e ; }
catch (Throwable e) { abort(e) ; throw new JenaException(e) ; }
}
-
- /* Abort but don't let problems with the transaction system itself
cause loss of the exception */
- private void abort(Throwable e) {
- try { abort() ; }
- catch (Throwable th) { e.addSuppressed(th); }
+
+ /**
+ * Execute the supplier <code>action</code> within a transaction. If
it completes normally,
+ * commit the transaction and return the result, otherwise abort the
transaction.
+ */
+ @Override
+ public <T> T executeRtn( Supplier<T> action ) {
+ begin() ;
+ T result ;
--- End diff --
Yes - that would be better. It was just old stuff, continued.
> Update "executeInTransaction" to Java8 style (Model, TransactionHandler).
> -------------------------------------------------------------------------
>
> Key: JENA-1231
> URL: https://issues.apache.org/jira/browse/JENA-1231
> Project: Apache Jena
> Issue Type: Bug
> Affects Versions: Jena 3.1.0
> Reporter: Andy Seaborne
> Assignee: Andy Seaborne
> Priority: Minor
>
> The proposal is to deprecate {{executeInTransaction}}, which returns "Object"
> and have operations:
> {noformat}
> <T> T executeRtn( Supplier<T> action ) ;
> {noformat}
> and the non-result version:
> {noformat}
> void execute( Runnable action );
> {noformat}
> It helps in the IDE to have different names because they both start
> "{{()\->...}}". In my experience (Eclipse) completion and error messages are
> not good when there is the same name and ambiguity over the inferred type.
> Using the {{()->methodresultsvalue()}} form is ambiguous.
> For model, call them {{executeInTxnRtn}} and {{executeInTxn}}.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)