Class Txn

java.lang.Object
org.apache.jena.system.Txn

public class Txn extends Object
Application utilities for executing code in transactions.

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 existing transaction to be used.

  • Constructor Details

    • Txn

      public Txn()
  • Method Details

    • execute

      public static <T extends Transactional> void execute(T txn, Runnable r)
      Execute in a "read" transaction that can promote to "write".

      Such a transaction may abort if an update is executed by another thread before this one is promoted to "write" mode. If so, the data protected by txn is unchanged.

      If the application knows updates will be needed, consider using executeWrite(T, java.lang.Runnable) which starts in "write" mode.

      The application code can call Transactional.promote() to attempt to change from "read" to "write"; the promote method returns a boolean indicating whether the promotion was possible or not.

    • calculate

      public static <T extends Transactional, X> X calculate(T txn, Supplier<X> r)
      Execute in a "read" transaction that can promote to "write" and return some calculated value.

      Such a transaction may abort if an update is executed by another thread before this one is promoted to "write" mode. If so, the data protected by txn is unchanged.

      If the application knows updates will be needed, consider using executeWrite(T, java.lang.Runnable) which starts in "write" mode.

      The application code can call Transactional.promote() to attempt to change from "read" to "write"; the promote method returns a boolean indicating whether the promotion was possible or not.

    • exec

      public static <T extends Transactional> void exec(T txn, TxnType txnType, Runnable r)
      Execute application code in a transaction with the given transaction type.
    • calc

      public static <T extends Transactional, X> X calc(T txn, TxnType txnType, Supplier<X> r)
      Execute and return a value in a transaction with the given transaction type.
    • executeRead

      public static <T extends Transactional> void executeRead(T txn, Runnable r)
      Execute in a read transaction
    • calculateRead

      public static <T extends Transactional, X> X calculateRead(T txn, Supplier<X> r)
      Execute and return a value in a read transaction
    • executeWrite

      public static <T extends Transactional> void executeWrite(T txn, Runnable r)
      Execute the Runnable in a write transaction
    • calculateWrite

      public static <T extends Transactional, X> X calculateWrite(T txn, Supplier<X> r)
      Execute and return a value in a write transaction.