Interface PreCommitCondition

  • Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface PreCommitCondition
    General condition that is checked before a transaction commits for validity. All conditions associated with a transaction must be true for that transaction to commit successfully. If a given condition is valid at commit time, it must also be true that it was valid throughout the lifetime of the transaction. This is not explicitly checked, so care must be taken in designing appropriate conditions that satisfy this constraint. As an example, advisory locks are a common pre-commit condition and one that is built into the TransactionManager API. These locks are granted before the transaction starts and cannot be refreshed once they lapse, so they provide the necessary invariant. If they are valid at commit time, they were valid for the entire lifetime of the transaction. Conditions are associated with a transaction, but should not interfere with the transaction locks (non-advisory) used by the transaction. The validity of those locks is controlled separately from any pre-commit conditions, and they follow different constraints - transaction locks are only acquired at commit time, for example, rather than at the beginning of a transaction.
    • Method Detail

      • throwIfConditionInvalid

        void throwIfConditionInvalid​(long timestamp)
        Checks that the condition is valid at the given timestamp, otherwise throws a TransactionFailedException. If the condition is not valid, the transaction will not be committed.
      • cleanup

        default void cleanup()
        Cleans up any state managed by this condition, e.g. a lock that should be held for the lifetime of the transaction. Conditions last the lifetime of a particular transaction and will be cleaned up on each retry. The cleanup method should not throw any exceptions - it should be best effort. When this method is called, the transaction has already failed or committed.