use of com.mongodb.client.result.DeleteResult in project spring-data-mongodb by spring-projects.
the class SimpleMongoRepository method delete.
/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object)
*/
@Override
public void delete(T entity) {
Assert.notNull(entity, "The given entity must not be null!");
DeleteResult deleteResult = mongoOperations.remove(entity, entityInformation.getCollectionName());
if (entityInformation.isVersioned() && deleteResult.wasAcknowledged() && deleteResult.getDeletedCount() == 0) {
throw new OptimisticLockingFailureException(String.format("The entity with id %s with version %s in %s cannot be deleted! Was it modified or deleted in the meantime?", entityInformation.getId(entity), entityInformation.getVersion(entity), entityInformation.getCollectionName()));
}
}
use of com.mongodb.client.result.DeleteResult in project spring-data-mongodb by spring-projects.
the class ExecutableRemoveOperationSupportTests method removeAllMatchingWithAlternateDomainTypeAndCollection.
// DATAMONGO-1563
@Test
void removeAllMatchingWithAlternateDomainTypeAndCollection() {
DeleteResult result = template.remove(Jedi.class).inCollection(STAR_WARS).matching(query(where("name").is("luke"))).all();
assertThat(result.getDeletedCount()).isEqualTo(1L);
}
use of com.mongodb.client.result.DeleteResult in project spring-data-mongodb by spring-projects.
the class ExecutableRemoveOperationSupportTests method removeAllMatchingCriteria.
// DATAMONGO-2416
@Test
void removeAllMatchingCriteria() {
DeleteResult result = template.remove(Person.class).matching(where("firstname").is("han")).all();
assertThat(result.getDeletedCount()).isEqualTo(1L);
}
use of com.mongodb.client.result.DeleteResult in project spring-data-mongodb by spring-projects.
the class ExecutableRemoveOperationSupportTests method removeAll.
// DATAMONGO-1563
@Test
void removeAll() {
DeleteResult result = template.remove(Person.class).all();
assertThat(result.getDeletedCount()).isEqualTo(2L);
}
use of com.mongodb.client.result.DeleteResult in project spring-data-mongodb by spring-projects.
the class MongoTemplateTests method removeShouldConsiderLimit.
// DATAMONGO-1870
@Test
public void removeShouldConsiderLimit() {
List<Sample> samples = //
IntStream.range(0, 100).mapToObj(//
i -> new Sample("id-" + i, i % 2 == 0 ? "stark" : "lannister")).collect(Collectors.toList());
template.insertAll(samples);
DeleteResult wr = template.remove(query(where("field").is("lannister")).limit(25), Sample.class);
assertThat(wr.getDeletedCount()).isEqualTo(25L);
assertThat(template.count(new Query(), Sample.class)).isEqualTo(75L);
}
Aggregations