Class ReadOnlyAndReadWriteTransactionConversionTemplate<T>

  • Type Parameters:
    T -

    public class ReadOnlyAndReadWriteTransactionConversionTemplate<T>
    extends Object
    Provides methods for changing between read/write and readonly transactions.
    Since:
    5.10
    • Constructor Detail

      • ReadOnlyAndReadWriteTransactionConversionTemplate

        public ReadOnlyAndReadWriteTransactionConversionTemplate​(org.springframework.transaction.PlatformTransactionManager transactionManager)
    • Method Detail

      • executeInReadOnly

        public T executeInReadOnly​(Supplier<T> inReadOnlyCallback,
                                   Supplier<T> notInReadOnlyCallback)
        Checks if the current transaction is in readonly mode, and creates a new transaction in readonly mode if not.
        Parameters:
        inReadOnlyCallback - To be executed if the current transaction is in readonly mode.
        notInReadOnlyCallback - To be executed in a new read only transaction if the current transaction is not in readonly mode.
        Returns:
        the result of the callback.
      • executeInReadWrite

        public T executeInReadWrite​(Supplier<T> callback)
        Checks if the current transaction is in read/write mode, and creates a new transaction in read/write mode if not.
        Parameters:
        callback - to be executed in the transaction.
        Returns:
        the result of the callback.