use of org.springframework.data.mongodb.MongoTransactionManager in project spring-data-mongodb by spring-projects.
the class SimpleMongoRepositoryVersionedEntityTests method initTxTemplate.
TransactionTemplate initTxTemplate() {
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
TransactionTemplate tt = new TransactionTemplate(txmgr);
tt.afterPropertiesSet();
return tt;
}
use of org.springframework.data.mongodb.MongoTransactionManager in project spring-data-mongodb by spring-projects.
the class SimpleMongoRepositoryTests method existsShouldBePossibleInTransaction.
// DATAMONGO-2130
@Test
@EnableIfReplicaSetAvailable
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
void existsShouldBePossibleInTransaction() {
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
TransactionTemplate tt = new TransactionTemplate(txmgr);
tt.afterPropertiesSet();
boolean exists = tt.execute(status -> {
Person sample = new Person();
sample.setLastname("Matthews");
repository.save(sample);
return repository.existsById(sample.getId());
});
assertThat(exists).isTrue();
}
use of org.springframework.data.mongodb.MongoTransactionManager in project spring-data-mongodb by spring-projects.
the class SimpleMongoRepositoryTests method countShouldBePossibleInTransaction.
// DATAMONGO-2130
@Test
@EnableIfReplicaSetAvailable
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
void countShouldBePossibleInTransaction() {
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
TransactionTemplate tt = new TransactionTemplate(txmgr);
tt.afterPropertiesSet();
long countPreTx = repository.count();
long count = tt.execute(status -> {
Person sample = new Person();
sample.setLastname("Matthews");
repository.save(sample);
return repository.count();
});
assertThat(count).isEqualTo(countPreTx + 1);
}
Aggregations