Class RootTransactionRunnable<T>

  • Type Parameters:
    T - see: TransactionRunnable

    public class RootTransactionRunnable<T>
    extends StartableTransactionRunnable<T>
    A TransactionRunnable which cannot be run inside of another runnable. A TransactionRunnable must extend this if it cannot safely rollback after committing.
    Since:
    3.0M2
    Version:
    $Id: 4fea91c881c7d8f506c924e25864310d3a424354 $
    • Constructor Detail

      • RootTransactionRunnable

        public RootTransactionRunnable()
    • Method Detail

      • runIn

        public <U extends TTransactionRunnable<U> runIn​(TransactionRunnable<U> parentRunnable)
        Run this TransactionRunnable inside of a "parent" runnable. This runnable will not be pre-run until after the parent is pre-run and this will not be run until after the parent runnable is run. This runnable will be committed before the parent and if something goes wrong, this runnable will be rolled back before it's parent. This runnable will have onComplete called after it's parent though. It is safe to have a parent runnable start a transaction inside of it's onRun() function and commit it inside of it's onCommit() function and allow that transaction to be used by the children of that runnable. If multiple runnables are run in a parent, they will be prerun, run, and onComplete'd in the order they were added and they will be committed and/or rolled back in reverse the order they were added. By using the return value of this function, it is possible to sandwich a TransactionRunnable which with few requirements between 2 runnables with many requirements. Normally you cannot run a TransactionRunnable<DatabaseTransaction> of a TransactionRunnable which does not offer database access. However, when you add a runnable which does not need or offer database access to one which does, this function returns that runnable casted to a type which does offer database access (since it is running in one which does). StartableTransactionRunnable<DbTransaction> transaction = new DbTransactionRunnable(); StartableTransactionRunnable<Standalone> standalone = new StandaloneTransactionRunnable(); TransactionRunnable<DbTransaction> runnableRequiringDb = new DbRequiringTransactionRunnable(); // This will not compile: runnableRequiringDb.runIn(standalone); // Because if it did, it would allow you to do this: standalone.start(); // Ut oh, using the database outside of a transaction! // This will work: TransactionRunnable<DbTransaction> castedStandalone = standalone.runIn(transaction); runnableRequiringDb.runIn(castedStandalone); transaction.start();

        This implementation throws an exception because it may not be used in a rootTR.

        Overrides:
        runIn in class TransactionRunnable<T>
        Type Parameters:
        U - The type of capabilities provided by the parent runnable. This defines the state which the state which the storage engine is guaranteed to be in when this runnable starts. It must extend the type of capabilities required by this runnable.
        Parameters:
        parentRunnable - the TransactionRunnable to run this runnable inside of.
        Returns:
        this runnable casted to a TransactionRunnable with the capabilities of it's parent.
        See Also:
        TransactionRunnable.runIn(TransactionRunnable)