DATAMONGO-1997 - Polishing.

Tweak documentation. Reformat code. Remove commented code.

Original pull request: #826.
This commit is contained in:
Mark Paluch
2020-01-29 10:25:28 +01:00
parent c56a13ad00
commit 44017485fc
4 changed files with 8 additions and 22 deletions

View File

@@ -37,9 +37,9 @@ import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.repository.support.PageableExecutionUtils;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ClassUtils;
import com.mongodb.client.result.DeleteResult;
import org.springframework.util.ClassUtils;
/**
* Set of classes to contain query execution strategies. Depending (mostly) on the return type of a
@@ -256,7 +256,7 @@ interface MongoQueryExecution {
return operations.findAllAndRemove(query, type, collectionName);
}
if(method.isQueryForEntity() && !ClassUtils.isPrimitiveOrWrapper(method.getReturnedObjectType())) {
if (method.isQueryForEntity() && !ClassUtils.isPrimitiveOrWrapper(method.getReturnedObjectType())) {
return operations.findAndRemove(query, type, collectionName);
}

View File

@@ -129,7 +129,7 @@ interface ReactiveMongoQueryExecution {
return operations.findAllAndRemove(query, type, collection);
}
if(method.isQueryForEntity() && !ClassUtils.isPrimitiveOrWrapper(method.getReturnedObjectType())) {
if (method.isQueryForEntity() && !ClassUtils.isPrimitiveOrWrapper(method.getReturnedObjectType())) {
return operations.findAndRemove(query, type, collection);
}

View File

@@ -22,13 +22,13 @@ import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.geo.Distance;
@@ -215,18 +215,6 @@ public class MongoQueryExecutionUnitTests {
assertThat(new DeleteExecution(mongoOperationsMock, queryMethod).execute(new Query())).isEqualTo(person);
}
// @Test // DATAMONGO-1997
// public void deleteExecutionWrapsEmptyResultInOptionalCorrectly() {
//
// Method method = ReflectionUtils.findMethod(PersonRepository.class, "deleteByLastname", String.class);
// MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, factory, context);
//
// Person person = new Person();
//
// when(mongoOperationsMock.findAndRemove(any(Query.class), any(Class.class), anyString())).thenReturn(null);
//
// assertThat(new DeleteExecution(mongoOperationsMock, queryMethod).execute(new Query())).isEqualTo(Optional.empty());
// }
interface PersonRepository extends Repository<Person, Long> {
@@ -235,7 +223,5 @@ public class MongoQueryExecutionUnitTests {
Long deleteAllByLastname(String lastname);
Person deleteByLastname(String lastname);
Optional<Person> deletePersonByLastname(String lastname);
}
}

View File

@@ -301,14 +301,14 @@ The keywords in the preceding table can be used in conjunction with `delete…By
----
public interface PersonRepository extends MongoRepository<Person, String> {
List <Person> deleteByLastname(String lastname); <1>
List <Person> deleteByLastname(String lastname); <1>
Long deletePersonByLastname(String lastname); <2>
Long deletePersonByLastname(String lastname); <2>
@Nullable
Person deleteSingleByLastname(String lastname); <3>
Person deleteSingleByLastname(String lastname); <3>
Optional<Person> deleteByBirthdate(Date birthdate); <4>
Optional<Person> deleteByBirthdate(Date birthdate); <4>
}
----
<1> Using a return type of `List` retrieves and returns all matching documents before actually deleting them.