Class QBackendTransaction
java.lang.Object
com.kingsrook.qqq.backend.core.actions.QBackendTransaction
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
MemoryConsistentReadTransaction,MongoDBTransaction,RDBMSTransaction
Container wherein backend modules can track data and/or objects that are
part of a transaction.
Most obvious use-case would be a JDBC Connection. See subclass in rdbms module.
Ditto MongoDB.
Also holds after-commit callbacks: work (e.g., publishing events about
changed records) that must only happen once the transaction's data is
committed, and never if it is rolled back. Subclasses that override commit()
must call runAfterCommitCallbacks() once their commit succeeds, and
discardAfterCommitCallbacks() if it fails. Subclasses that override
rollback() must call super.rollback(), which discards them.
Note: One would imagine that this class shouldn't ever implement Serializable...
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAfterCommitCallback(Runnable callback) Register a callback to run after this transaction's next successful commit.voidclose()Close any resources associated with the transaction.voidcommit()Commit the transaction.protected voidForget all after-commit callbacks, without running them - their work will not be committed.What a transaction from openConsistentReadTransaction guarantees.For a transaction from openConsistentReadTransaction, the id of a snapshot that other transactions can attach to (via ConsistentReadInput .importSnapshotId) - for backends that support sharing one (e.g., postgres).static QBackendTransactionOpen a consistent-read transaction (see QBackendModuleInterface .openConsistentReadTransaction) on the named backend.static QBackendTransactionopenFor(AbstractTableActionInput input) voidrollback()Rollback the transaction.protected voidRun (and then forget) all after-commit callbacks, in the order they were added, catching and logging any Exception or LinkageError from each.
-
Constructor Details
-
QBackendTransaction
public QBackendTransaction()
-
-
Method Details
-
openFor
- Throws:
QException
-
openConsistentReadFor
public static QBackendTransaction openConsistentReadFor(ConsistentReadInput input) throws QException Open a consistent-read transaction (see QBackendModuleInterface .openConsistentReadTransaction) on the named backend.- Throws:
QException- if the backend's module doesn't support them.
-
getExportedSnapshotId
-
getConsistencyGuarantee
What a transaction from openConsistentReadTransaction guarantees. Callers should record this, rather than assume ONE_INSTANT. -
commit
-
rollback
-
addAfterCommitCallback
Register a callback to run after this transaction's next successful commit. Callbacks run in the order they were added, and each runs at most once. If the transaction is rolled back instead, they are discarded without running. A callback that throws (an Exception, or a LinkageError, such as a NoClassDefFoundError from an optional library that isn't on the classpath) is logged, and does not fail the commit - whose data is already committed - nor stop later callbacks from running. -
runAfterCommitCallbacks
protected void runAfterCommitCallbacks()Run (and then forget) all after-commit callbacks, in the order they were added, catching and logging any Exception or LinkageError from each. For subclasses to call once their commit has succeeded. -
discardAfterCommitCallbacks
protected void discardAfterCommitCallbacks()Forget all after-commit callbacks, without running them - their work will not be committed. For rollback, and for subclasses to call when their commit fails (so a later commit on this transaction doesn't run them). -
close
public void close()Close any resources associated with the transaction. In theory, should only be called after a commit or rollback was done.- Specified by:
closein interfaceAutoCloseable
-