Class MongoDBTransaction
java.lang.Object
com.kingsrook.qqq.backend.core.actions.QBackendTransaction
com.kingsrook.qqq.backend.module.mongodb.actions.MongoDBTransaction
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
MongoDBConsistentReadTransaction
MongoDB implementation of backend transaction.
Stores a mongoClient and clientSession.
Also keeps track of if the specific mongo backend being used supports transactions,
as, it appears that single-node instances do not, and they throw errors if
you try to do transaction operations in them... This is configured by the
corresponding field in the backend metaData.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionMongoDBTransaction(MongoDBBackendMetaData backend, com.mongodb.client.MongoClient mongoClient) MongoDBTransaction(MongoDBBackendMetaData backend, com.mongodb.client.MongoClient mongoClient, com.mongodb.client.ClientSession clientSession) Adopt the client and its already-open session as one transaction owner.protectedMongoDBTransaction(MongoDBBackendMetaData backend, com.mongodb.client.MongoClient mongoClient, com.mongodb.client.ClientSession clientSession, boolean allowTransactions) As above - but with allowTransactions false, no mongo transaction is started (e.g., for a snapshot-read-concern session, which can't have one), whatever the backend's transactionsSupported says. -
Method Summary
Methods inherited from class com.kingsrook.qqq.backend.core.actions.QBackendTransaction
addAfterCommitCallback, discardAfterCommitCallbacks, getConsistencyGuarantee, getExportedSnapshotId, openConsistentReadFor, openFor, runAfterCommitCallbacks
-
Constructor Details
-
MongoDBTransaction
public MongoDBTransaction(MongoDBBackendMetaData backend, com.mongodb.client.MongoClient mongoClient) -
MongoDBTransaction
public MongoDBTransaction(MongoDBBackendMetaData backend, com.mongodb.client.MongoClient mongoClient, com.mongodb.client.ClientSession clientSession) Adopt the client and its already-open session as one transaction owner. -
MongoDBTransaction
protected MongoDBTransaction(MongoDBBackendMetaData backend, com.mongodb.client.MongoClient mongoClient, com.mongodb.client.ClientSession clientSession, boolean allowTransactions) As above - but with allowTransactions false, no mongo transaction is started (e.g., for a snapshot-read-concern session, which can't have one), whatever the backend's transactionsSupported says.
-
-
Method Details
-
commit
Description copied from class:QBackendTransactionCommit the transaction.- Overrides:
commitin classQBackendTransaction- Throws:
QException
-
rollback
Description copied from class:QBackendTransactionRollback the transaction.- Overrides:
rollbackin classQBackendTransaction- Throws:
QException
-
close
public void close()Description copied from class:QBackendTransactionClose any resources associated with the transaction. In theory, should only be called after a commit or rollback was done.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classQBackendTransaction
-
getMongoClient
public com.mongodb.client.MongoClient getMongoClient()Getter for mongoClient -
getClientSession
public com.mongodb.client.ClientSession getClientSession()Getter for clientSession
-