[DATAMONGO-1920] Add support for transactions (sync). Created: 05/Apr/18  Updated: 07/Jun/18  Resolved: 09/May/18

Status: Closed
Project: Spring Data MongoDB
Component/s: Core
Affects Version/s: None
Fix Version/s: 2.1 M3 (Lovelace)

Type: New Feature Priority: Minor
Reporter: Christoph Strobl Assignee: Christoph Strobl
Resolution: Complete Votes: 0
Labels: lovelace
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relate
relates to DATAMONGO-2001 Count within session should return on... Closed
is related to DATAMONGO-1971 Install MongoDB on TravisCI ourselves Closed
Reference URL: https://www.mongodb.com/transactions
Last updater: Christoph Strobl
Pull Request URL: https://github.com/spring-projects/spring-data-mongodb/pull/554
Sprint: Lovelace M2 / M3

 Description   

Provide a MongoDB specific PlatformTransactionManager implementation.

The MongoTransactionManager should create and bind a ClientSession to the thread. Transactions are started, commited or aborted while MongoTemplate automatically detects existing ClientSessions and operates on them accordingly.

Without the presence of a MongoTransactionManager within the ApplicationContext the template should not participate in any what so ever ongoing transactions. Users have to actively opt in to transaction support. A flag on MongoTemplate should allow to enable transaction support for non native MongoDB transactions.

@Configuration
public class Config extends AbstractMongoConfiguration {

  @Bean
  MongoTransactionManager transactionManager(MongoDbFactory dbFactory) {
    return new MongoTransactionManager(dbFactory);
  }

  // ...
}

@Service
public class NightAngel {

  @Autowired PersonRepository repository;

  @Transactional
  public void trainAzoth() {

    Person durzo = repository.findByName("Durzo Blint");

    Person kylar = new Person("Kylar Stern");
    kylar.setMaster(durzo);

    repository.save(kylar);    
  }
}

Generated at Tue Feb 25 18:32:01 UTC 2020 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.