Class SerializableTransactionRunner

  • All Implemented Interfaces:
    TransactionHandler

    public class SerializableTransactionRunner
    extends DelegatingTransactionHandler
    implements TransactionHandler
    A TransactionHandler that automatically retries transactions that fail due to serialization failures, which can generally be resolved by automatically retrying the transaction. Any HandleCallback used under this runner should be aware that it may be invoked multiple times and should be idempotent.
    • Field Detail

      • SQLSTATE_TXN_SERIALIZATION_FAILED

        private static final java.lang.String SQLSTATE_TXN_SERIALIZATION_FAILED
        See Also:
        Constant Field Values
    • Constructor Detail

      • SerializableTransactionRunner

        public SerializableTransactionRunner()
      • SerializableTransactionRunner

        public SerializableTransactionRunner​(TransactionHandler delegate)
    • Method Detail

      • inTransaction

        public <R,​X extends java.lang.Exception> R inTransaction​(Handle handle,
                                                                       HandleCallback<R,​X> callback)
                                                                throws X extends java.lang.Exception
        Description copied from interface: TransactionHandler
        Run a transaction.
        Specified by:
        inTransaction in interface TransactionHandler
        Overrides:
        inTransaction in class DelegatingTransactionHandler
        Type Parameters:
        R - the callback return type
        X - the exception type thrown by the callback, if any
        Parameters:
        handle - the handle to the database
        callback - a callback which will receive the open handle, in a transaction.
        Returns:
        the value returned by the callback.
        Throws:
        X - any exception thrown by the callback.
        X extends java.lang.Exception
        See Also:
        Handle.inTransaction(HandleCallback)
      • specialize

        public TransactionHandler specialize​(Handle handle)
                                      throws java.sql.SQLException
        Description copied from interface: TransactionHandler
        Bind a TransactionHandler to a Handle, to allow it to track handle-local state.
        Specified by:
        specialize in interface TransactionHandler
        Parameters:
        handle - the handle to bind to
        Returns:
        the bound TransactionHandler
        Throws:
        java.sql.SQLException - bad things happened
      • isSqlState

        protected boolean isSqlState​(java.lang.String expectedSqlState,
                                     java.lang.Throwable throwable)
        Checks whether a given exception is in a specific SQL state.
        Parameters:
        expectedSqlState - The expected SQL state.
        throwable - The Throwable to test.
        Returns:
        True if Throwable or one of its causes is an SQLException whose SQLState begins with the given state.