public class MongoTransaction extends java.lang.Object implements org.grails.datastore.mapping.transactions.Transaction
A org.grails.datastore.mapping.transactions.Transaction backed by a real MongoDB multi-document transaction on a com.mongodb.client.ClientSession. Unlike the legacy org.grails.datastore.mapping.transactions.SessionOnlyTransaction (which only flushes the GORM session), this commits or aborts a server-side transaction so multiple writes are atomic.
The com.mongodb.client.ClientSession is started with an active transaction before this object is constructed; commit() flushes the GORM session (a no-op when the org.grails.datastore.mapping.transactions.DatastoreTransactionManager already flushed) and commits the server transaction, while rollback() aborts it. Both close the com.mongodb.client.ClientSession and detach it from the owning session.
Commit is retried on an UnknownTransactionCommitResult error label. Whole-transaction
retry on a TransientTransactionError is intentionally not handled here: it requires
re-executing the transaction body, which the
org.grails.datastore.mapping.transactions.DatastoreTransactionManager — a Spring
PlatformTransactionManager — cannot do (it only begins, commits and rolls back; the
application code between those is not re-runnable at this layer). Such retry is left to the
application (as Spring Data MongoDB's own MongoTransactionManager does), since re-running
the body would repeat its side effects.
| Constructor and description |
|---|
MongoTransaction(AbstractMongoSession session, com.mongodb.client.ClientSession clientSession) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
commit() |
|
public com.mongodb.client.ClientSession |
getNativeTransaction() |
|
public boolean |
isActive() |
|
public void |
rollback() |
|
public void |
setTimeout(int timeout) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |