/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.seaborne.dboe.jenax;

import java.util.function.Supplier ;

import org.apache.jena.sparql.core.Transactional ;

/** Indirection to allow for modifcation for TDB2 capabilities */
public class Txn {
    public static <T extends Transactional> void execRead(T txn, Runnable r) {
        org.apache.jena.system.Txn.execRead(txn, r);
    }

    public static <T extends Transactional, X> X execReadRtn(T txn, Supplier<X> r) {
        return org.apache.jena.system.Txn.execReadRtn(txn, r);
    }

    public static <T extends Transactional> void execWrite(T txn, Runnable r) {
        org.apache.jena.system.Txn.execWrite(txn, r);
    }

    public static <T extends Transactional, X> X execWriteRtn(Transactional txn, Supplier<X> r) {
        return org.apache.jena.system.Txn.execWriteRtn(txn, r);
    }
}

//// **** THIS IS A COPY OF WHAT WILL BE IN JENA 3.1.1 ****
//
///** Application utilities for transactions.
// *  <ul> 
// *  <li>"Autocommit" provided. 
// *  <li>Nested transaction are not supported but calling inside an existing transaction, 
// *      which must be compatible, (i.e. a write needs a WRITE transaction).
// *      causes the transaction to be used.
// *  </ul>  
// */
//
//public class Txn {
//    /** Execute the Runnable in a read transaction. */
//    public static <T extends Transactional> void execRead(T txn, Runnable r) {
//        boolean b = txn.isInTransaction() ;
//        if ( !b )
//            txn.begin(ReadWrite.READ) ;
//        try { r.run() ; }
//        catch (Throwable th) {
//            onThrowable(th, txn);
//            throw th ;
//        }
//        if ( ! b )
//            txn.end() ;
//    }
//    
//    /** Execute and return a value in a read transaction */
//    public static <T extends Transactional, X> X execReadRtn(T txn, Supplier<X> r) {
//        boolean b = txn.isInTransaction() ;
//        if ( !b )
//            txn.begin(ReadWrite.READ) ;
//        try {
//            X x = r.get() ;
//            if ( !b )
//                txn.end() ;
//            return x ;
//        } catch (Throwable th) {
//            onThrowable(th, txn);
//            throw th ;
//        }
//    }
//
//    /** Execute the Runnable in a write transaction */
//    public static <T extends Transactional> void execWrite(T txn, Runnable r) {
//        boolean b = txn.isInTransaction() ;
//        if ( !b )
//            txn.begin(ReadWrite.WRITE) ;
//        try { r.run() ; }
//        catch (Throwable th) {
//            onThrowable(th, txn);
//            throw th ;
//        }
//        if ( !b ) {
//            if ( txn.isInTransaction() )
//                // May have been explicit commit or abort.
//                txn.commit() ;
//            txn.end() ;
//        }
//    }
//
//    /** Execute and return a value in a write transaction. */
//    public static <T extends Transactional, X> X execWriteRtn(Transactional txn, Supplier<X> r) {
//        boolean b = txn.isInTransaction() ;
//        if ( !b )
//            txn.begin(ReadWrite.WRITE) ;
//        X x = null ;
//        try { x = r.get() ; } 
//        catch (Throwable th) {
//            onThrowable(th, txn);
//            throw th ;
//        }
//        if ( !b ) {
//            if ( txn.isInTransaction() )
//                // May have been explicit commit or abort.
//                txn.commit() ;
//            txn.end() ;
//        }
//        return x ;
//    }
//    
//    // Attempt some kind of cleanup.
//    private static <T extends Transactional> void onThrowable(Throwable th, T txn) {
//        try {
//            txn.abort() ;
//            txn.end() ;
//        } catch (Throwable th2) { th.addSuppressed(th2); }
//    }
//}

@@ -1618,2889 +1618,4 @@
 %7D%0A%7D%0A
-%0A//// **** THIS IS A COPY OF WHAT WILL BE IN JENA 3.1.1 ****%0A//%0A///** Application utilities for transactions.%0A// *  %3Cul%3E %0A// *  %3Cli%3E%22Autocommit%22 provided. %0A// *  %3Cli%3ENested transaction are not supported but calling inside an existing transaction, %0A// *      which must be compatible, (i.e. a write needs a WRITE transaction).%0A// *      causes the transaction to be used.%0A// *  %3C/ul%3E  %0A// */%0A//%0A//public class Txn %7B%0A//    /** Execute the Runnable in a read transaction. */%0A//    public static %3CT extends Transactional%3E void execRead(T txn, Runnable r) %7B%0A//        boolean b = txn.isInTransaction() ;%0A//        if ( !b )%0A//            txn.begin(ReadWrite.READ) ;%0A//        try %7B r.run() ; %7D%0A//        catch (Throwable th) %7B%0A//            onThrowable(th, txn);%0A//            throw th ;%0A//        %7D%0A//        if ( ! b )%0A//            txn.end() ;%0A//    %7D%0A//    %0A//    /** Execute and return a value in a read transaction */%0A//    public static %3CT extends Transactional, X%3E X execReadRtn(T txn, Supplier%3CX%3E r) %7B%0A//        boolean b = txn.isInTransaction() ;%0A//        if ( !b )%0A//            txn.begin(ReadWrite.READ) ;%0A//        try %7B%0A//            X x = r.get() ;%0A//            if ( !b )%0A//                txn.end() ;%0A//            return x ;%0A//        %7D catch (Throwable th) %7B%0A//            onThrowable(th, txn);%0A//            throw th ;%0A//        %7D%0A//    %7D%0A//%0A//    /** Execute the Runnable in a write transaction */%0A//    public static %3CT extends Transactional%3E void execWrite(T txn, Runnable r) %7B%0A//        boolean b = txn.isInTransaction() ;%0A//        if ( !b )%0A//            txn.begin(ReadWrite.WRITE) ;%0A//        try %7B r.run() ; %7D%0A//        catch (Throwable th) %7B%0A//            onThrowable(th, txn);%0A//            throw th ;%0A//        %7D%0A//        if ( !b ) %7B%0A//            if ( txn.isInTransaction() )%0A//                // May have been explicit commit or abort.%0A//                txn.commit() ;%0A//            txn.end() ;%0A//        %7D%0A//    %7D%0A//%0A//    /** Execute and return a value in a write transaction. */%0A//    public static %3CT extends Transactional, X%3E X execWriteRtn(Transactional txn, Supplier%3CX%3E r) %7B%0A//        boolean b = txn.isInTransaction() ;%0A//        if ( !b )%0A//            txn.begin(ReadWrite.WRITE) ;%0A//        X x = null ;%0A//        try %7B x = r.get() ; %7D %0A//        catch (Throwable th) %7B%0A//            onThrowable(th, txn);%0A//            throw th ;%0A//        %7D%0A//        if ( !b ) %7B%0A//            if ( txn.isInTransaction() )%0A//                // May have been explicit commit or abort.%0A//                txn.commit() ;%0A//            txn.end() ;%0A//        %7D%0A//        return x ;%0A//    %7D%0A//    %0A//    // Attempt some kind of cleanup.%0A//    private static %3CT extends Transactional%3E void onThrowable(Throwable th, T txn) %7B%0A//        try %7B%0A//            txn.abort() ;%0A//            txn.end() ;%0A//        %7D catch (Throwable th2) %7B th.addSuppressed(th2); %7D%0A//    %7D%0A//%7D%0A

Use Jena code - retain a point of indirection for development assist.