Aklakan commented on code in PR #3027: URL: https://github.com/apache/jena/pull/3027#discussion_r2081631101
########## 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: Alternatively, the AutoTxn-related begin methods could be moved to the AutoTxn class. The main disadvantage might be that it is harder to find if someone is already familiar with Txn - as Txn is so far pretty much the starting point for all transaction-related helper methods. `try (AutoTxn txn = AutoTxn.begin(transactional, TxnType.WRITE)) {` -- 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