Aklakan commented on code in PR #3027:
URL: https://github.com/apache/jena/pull/3027#discussion_r2081643391


##########
jena-arq/src/main/java/org/apache/jena/system/Txn.java:
##########
@@ -137,4 +139,46 @@ private static <T extends Transactional> void 
onThrowable(Throwable th, T txn) {
             txn.end();
         } catch (Throwable th2) { th.addSuppressed(th2); }
     }
+
+    /**
+     * Begins a transaction and returns a transaction control instance suitable
+     * for use with try-with-resources blocks.
+     * See {@link #begin(Transactional, TxnType)}.
+     */
+    public static AutoTxn begin(Transactional txn, ReadWrite readWrite) {
+        return begin(txn, TxnType.convert(readWrite));
+    }
+
+    /**
+     * Begins a transaction and returns a transaction control instance suitable
+     * for use with try-with-resources blocks.
+     * Allows for raising checked exceptions in an idiomatic way.
+     * Closing the TxnCtl instance will abort the transaction unless it
+     * has been manually committed.
+     * <p>
+     *
+     * Usage example:
+     * <pre>
+     * public void myMethod() throws IOException {
+     *   try (AutoTxn txn = Txn.begin(dataset, TxnType.WRITE)) {

Review Comment:
   So in summary I tend towards to `Txn.autoTxn` solution.



##########
jena-arq/src/main/java/org/apache/jena/system/Txn.java:
##########
@@ -137,4 +139,46 @@ private static <T extends Transactional> void 
onThrowable(Throwable th, T txn) {
             txn.end();
         } catch (Throwable th2) { th.addSuppressed(th2); }
     }
+
+    /**
+     * Begins a transaction and returns a transaction control instance suitable
+     * for use with try-with-resources blocks.
+     * See {@link #begin(Transactional, TxnType)}.
+     */
+    public static AutoTxn begin(Transactional txn, ReadWrite readWrite) {
+        return begin(txn, TxnType.convert(readWrite));
+    }
+
+    /**
+     * Begins a transaction and returns a transaction control instance suitable
+     * for use with try-with-resources blocks.
+     * Allows for raising checked exceptions in an idiomatic way.
+     * Closing the TxnCtl instance will abort the transaction unless it
+     * has been manually committed.
+     * <p>
+     *
+     * Usage example:
+     * <pre>
+     * public void myMethod() throws IOException {
+     *   try (AutoTxn txn = Txn.begin(dataset, TxnType.WRITE)) {

Review Comment:
   So in summary I tend towards the `Txn.autoTxn` solution.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscr...@jena.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@jena.apache.org
For additional commands, e-mail: pr-h...@jena.apache.org

Reply via email to