@groovy.transform.CompileStatic class GormSharedSessionMongoTransactionManager extends DatastoreTransactionManager
A org.springframework.transaction.PlatformTransactionManager that drives a single GORM
MongoDB transaction and additionally exposes its ClientSession to Spring Data MongoDB, so
that GORM operations and MongoTemplate/repository operations executed within one
@Transactional method participate in the same MongoDB transaction.
It extends DatastoreTransactionManager — inheriting GORM's begin/commit/rollback,
session binding and flushing — and, once GORM has started its ClientSession, binds a
Spring Data MongoResourceHolder referencing that same session, keyed by the
MongoDatabaseFactory. Spring Data's MongoTemplate discovers that holder via the
thread-bound resources and runs inside the session, so a single commit (or abort) — driven by
GORM — applies to both stacks atomically.
This requires GORM server-side transactions to be enabled
(grails.mongodb.transactional = true); without an active ClientSession there is
nothing to share and Spring Data operations run outside of a transaction as before.
Propagation: like GORM's DatastoreTransactionManager, this manager
supports a single flat transaction (PROPAGATION_REQUIRED); Spring-native suspension
propagations such as REQUIRES_NEW and NESTED are not supported and behave as
REQUIRED (they join the surrounding transaction rather than suspending it).
| Constructor and description |
|---|
GormSharedSessionMongoTransactionManager(MongoDatastore datastore, MongoDatabaseFactory databaseFactory) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
doBegin(java.lang.Object transaction, TransactionDefinition definition) |
|
protected void |
doCleanupAfterCompletion(java.lang.Object transaction) |
| Methods inherited from class | Name |
|---|---|
class DatastoreTransactionManager |
doBegin, doCleanupAfterCompletion, doCommit, doGetTransaction, doResume, doRollback, doSetRollbackOnly, doSuspend, getDatastore, setDatastore, setDatastoreManagedSession |