Skip to content

Commit 6a5d96b

Browse files
committed
DATAMONGO-1444 - Cleanups.
1 parent 65f8fc7 commit 6a5d96b

10 files changed

+40
-39
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/ReactiveMongoRepository.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030
* Mongo specific {@link org.springframework.data.repository.Repository} interface with reactive support.
3131
*
3232
* @author Mark Paluch
33+
* @since 2.0
3334
*/
3435
@NoRepositoryBean
3536
public interface ReactiveMongoRepository<T, ID extends Serializable> extends ReactivePagingAndSortingRepository<T, ID> {
3637

37-
<S extends T> Flux<S> save(Iterable<S> entites);
38-
3938
/**
40-
* Inserts the given a given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use
39+
* Inserts the given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use
4140
* the returned instance for further operations as the save operation might have changed the entity instance
4241
* completely. Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
4342
*
@@ -47,17 +46,17 @@ public interface ReactiveMongoRepository<T, ID extends Serializable> extends Rea
4746
<S extends T> Mono<S> insert(S entity);
4847

4948
/**
50-
* Inserts the given a given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use
49+
* Inserts the given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use
5150
* the returned instance for further operations as the save operation might have changed the entity instance
5251
* completely. Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
5352
*
54-
* @param entity must not be {@literal null}.
53+
* @param entities must not be {@literal null}.
5554
* @return the saved entity
5655
*/
57-
<S extends T> Flux<S> insert(Iterable<S> entity);
56+
<S extends T> Flux<S> insert(Iterable<S> entities);
5857

5958
/**
60-
* Inserts the given a given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use
59+
* Inserts the given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use
6160
* the returned instance for further operations as the save operation might have changed the entity instance
6261
* completely. Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
6362
*

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQuery.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,25 @@ public Object execute(Object[] parameters) {
9696
@SuppressWarnings("unchecked")
9797
private Object executeDeferred(Object[] parameters) {
9898

99+
ReactiveMongoParameterAccessor parameterAccessor = new ReactiveMongoParameterAccessor(method, parameters);
100+
99101
if (getQueryMethod().isCollectionQuery()) {
100-
return Flux.defer(() -> (Publisher<Object>) execute(new ReactiveMongoParameterAccessor(method, parameters)));
102+
return Flux.defer(() -> (Publisher<Object>) execute(parameterAccessor));
101103
}
102104

103-
return Mono.defer(() -> (Mono<Object>) execute(new ReactiveMongoParameterAccessor(method, parameters)));
105+
return Mono.defer(() -> (Mono<Object>) execute(parameterAccessor));
104106
}
105107

106-
private Object execute(MongoParameterAccessor accessor) {
107-
Query query = createQuery(new ConvertingParameterAccessor(operations.getConverter(), accessor));
108+
private Object execute(MongoParameterAccessor parameterAccessor) {
109+
110+
Query query = createQuery(new ConvertingParameterAccessor(operations.getConverter(), parameterAccessor));
108111

109112
applyQueryMetaAttributesWhenPresent(query);
110113

111-
ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor);
114+
ResultProcessor processor = method.getResultProcessor().withDynamicProjection(parameterAccessor);
112115
String collection = method.getEntityInformation().getCollectionName();
113116

114-
ReactiveMongoQueryExecution execution = getExecution(query, accessor,
117+
ReactiveMongoQueryExecution execution = getExecution(query, parameterAccessor,
115118
new ResultProcessingConverter(processor, operations, instantiators));
116119

117120
return execution.execute(query, processor.getReturnedType().getDomainType(), collection);

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecution.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import reactor.core.publisher.Flux;
4040
import reactor.core.publisher.Mono;
4141

42+
import com.mongodb.client.result.DeleteResult;
43+
4244
/**
4345
* Set of classes to contain query execution strategies. Depending (mostly) on the return type of a
4446
* {@link org.springframework.data.repository.query.QueryMethod} a {@link AbstractReactiveMongoQuery} can be executed in various
@@ -245,7 +247,7 @@ public Object execute(Query query, Class<?> type, String collection) {
245247
return operations.findAllAndRemove(query, type, collection);
246248
}
247249

248-
return operations.remove(query, type, collection).map(deleteResult -> deleteResult.getDeletedCount());
250+
return operations.remove(query, type, collection).map(DeleteResult::getDeletedCount);
249251
}
250252
}
251253

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveMongoRepositoryFactory.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
*/
5656
public class ReactiveMongoRepositoryFactory extends RepositoryFactorySupport {
5757

58-
@SuppressWarnings("unchecked") private static final List<Class<? extends Serializable>> GEO_NEAR_RESULTS = Arrays
59-
.asList(GeoResult.class);
60-
6158
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
6259

6360
private final ReactiveMongoOperations operations;
@@ -138,8 +135,7 @@ private <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInfo
138135
/**
139136
* {@link QueryLookupStrategy} to create {@link PartTreeMongoQuery} instances.
140137
*
141-
* @author Oliver Gierke
142-
* @author Thomas Darimont
138+
* @author Mark Paluch
143139
*/
144140
private static class MongoQueryLookupStrategy implements QueryLookupStrategy {
145141

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveMongoRepositoryFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected RepositoryFactorySupport getFactoryInstance(ReactiveMongoOperations op
111111
public void afterPropertiesSet() {
112112

113113
super.afterPropertiesSet();
114-
Assert.notNull(operations, "ReactiveMongoTemplate must not be null!");
114+
Assert.notNull(operations, "ReactiveMongoOperations must not be null!");
115115

116116
if (!mappingContextConfigured) {
117117
setMappingContext(operations.getConverter().getMappingContext());

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* Reactive repository base implementation for Mongo.
4545
*
4646
* @author Mark Paluch
47+
* @since 2.0
4748
*/
4849
public class SimpleReactiveMongoRepository<T, ID extends Serializable> implements ReactiveMongoRepository<T, ID> {
4950

@@ -136,9 +137,9 @@ public Flux<T> findAll(Iterable<ID> ids) {
136137
@Override
137138
public Flux<T> findAll(Publisher<ID> idStream) {
138139

139-
Assert.notNull(idStream, "The given Publisher of entities must not be null!");
140+
Assert.notNull(idStream, "The given Publisher of Id's must not be null!");
140141

141-
return Flux.from(idStream).buffer().flatMap(ids -> findAll(ids));
142+
return Flux.from(idStream).buffer().flatMap(this::findAll);
142143
}
143144

144145
@Override
@@ -277,7 +278,7 @@ public Mono<Void> delete(ID id) {
277278

278279
return mongoOperations
279280
.remove(getIdQuery(id), entityInformation.getJavaType(), entityInformation.getCollectionName())
280-
.then(deleteResult -> Mono.empty());
281+
.then();
281282
}
282283

283284
public Mono<Void> delete(T entity) {

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ConvertingReactiveMongoRepositoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void mixedRepositoryShouldWork() throws Exception {
204204
* @see DATAMONGO-1444
205205
*/
206206
@Test
207-
public void shouldFindOneByPublisherOfLastName() throws Exception {
207+
public void shouldFindOneBySingleOfLastName() throws Exception {
208208

209209
ReactivePerson carter = reactiveRepository.findByLastname(Single.just("Beauford")).block();
210210

@@ -215,7 +215,7 @@ public void shouldFindOneByPublisherOfLastName() throws Exception {
215215
* @see DATAMONGO-1444
216216
*/
217217
@Test
218-
public void shouldFindByPublisherOfLastNameIn() throws Exception {
218+
public void shouldFindByObservableOfLastNameIn() throws Exception {
219219

220220
List<ReactivePerson> persons = reactiveRepository.findByLastnameIn(Observable.just("Beauford", "Matthews"))
221221
.collectList().block();

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void setUp() throws Exception {
127127
* @see DATAMONGO-1444
128128
*/
129129
@Test
130-
public void shouldFindByLastName() throws Exception {
130+
public void shouldFindByLastName() {
131131

132132
List<Person> list = repository.findByLastname("Matthews").collectList().block();
133133

@@ -138,7 +138,7 @@ public void shouldFindByLastName() throws Exception {
138138
* @see DATAMONGO-1444
139139
*/
140140
@Test
141-
public void shouldFindMonoOfPage() throws Exception {
141+
public void shouldFindMonoOfPage() {
142142

143143
Mono<Page<Person>> pageMono = repository.findMonoPageByLastname("Matthews", new PageRequest(0, 1));
144144

@@ -159,7 +159,7 @@ public void shouldFindMonoOfPage() throws Exception {
159159
* @see DATAMONGO-1444
160160
*/
161161
@Test
162-
public void shouldFindMonoOfSlice() throws Exception {
162+
public void shouldFindMonoOfSlice() {
163163

164164
Mono<Slice<Person>> pageMono = repository.findMonoSliceByLastname("Matthews", new PageRequest(0, 1));
165165

@@ -180,7 +180,7 @@ public void shouldFindMonoOfSlice() throws Exception {
180180
* @see DATAMONGO-1444
181181
*/
182182
@Test
183-
public void shouldFindOneByLastName() throws Exception {
183+
public void shouldFindOneByLastName() {
184184

185185
Person carter = repository.findOneByLastname("Beauford").block();
186186

@@ -191,7 +191,7 @@ public void shouldFindOneByLastName() throws Exception {
191191
* @see DATAMONGO-1444
192192
*/
193193
@Test
194-
public void shouldFindOneByPublisherOfLastName() throws Exception {
194+
public void shouldFindOneByPublisherOfLastName() {
195195

196196
Person carter = repository.findByLastname(Mono.just("Beauford")).block();
197197

@@ -202,7 +202,7 @@ public void shouldFindOneByPublisherOfLastName() throws Exception {
202202
* @see DATAMONGO-1444
203203
*/
204204
@Test
205-
public void shouldFindByPublisherOfLastNameIn() throws Exception {
205+
public void shouldFindByPublisherOfLastNameIn() {
206206

207207
List<Person> persons = repository.findByLastnameIn(Flux.just("Beauford", "Matthews")).collectList().block();
208208

@@ -213,7 +213,7 @@ public void shouldFindByPublisherOfLastNameIn() throws Exception {
213213
* @see DATAMONGO-1444
214214
*/
215215
@Test
216-
public void shouldFindByPublisherOfLastNameInAndAgeGreater() throws Exception {
216+
public void shouldFindByPublisherOfLastNameInAndAgeGreater() {
217217

218218
List<Person> persons = repository.findByLastnameInAndAgeGreaterThan(Flux.just("Beauford", "Matthews"), 41)
219219
.collectList().block();
@@ -225,7 +225,7 @@ public void shouldFindByPublisherOfLastNameInAndAgeGreater() throws Exception {
225225
* @see DATAMONGO-1444
226226
*/
227227
@Test
228-
public void shouldFindUsingPublishersInStringQuery() throws Exception {
228+
public void shouldFindUsingPublishersInStringQuery() {
229229

230230
List<Person> persons = repository.findStringQuery(Flux.just("Beauford", "Matthews"), Mono.just(41)).collectList()
231231
.block();
@@ -237,7 +237,7 @@ public void shouldFindUsingPublishersInStringQuery() throws Exception {
237237
* @see DATAMONGO-1444
238238
*/
239239
@Test
240-
public void shouldFindByLastNameAndSort() throws Exception {
240+
public void shouldFindByLastNameAndSort() {
241241

242242
List<Person> persons = repository.findByLastname("Matthews", new Sort(new Order(ASC, "age"))).collectList().block();
243243
assertThat(persons, contains(oliver, dave));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
@ContextConfiguration("classpath:reactive-infrastructure.xml")
6060
public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware, BeanFactoryAware {
6161

62-
@Autowired ReactiveMongoTemplate template;
62+
@Autowired private ReactiveMongoTemplate template;
6363

64-
ReactiveMongoRepositoryFactory factory;
64+
private ReactiveMongoRepositoryFactory factory;
6565
private ClassLoader classLoader;
6666
private BeanFactory beanFactory;
6767
private ReactivePersonRepostitory repository;
6868

69-
ReactivePerson dave, oliver, carter, boyd, stefan, leroi, alicia;
69+
private ReactivePerson dave, oliver, carter, boyd, stefan, leroi, alicia;
7070

7171
@Override
7272
public void setBeanClassLoader(ClassLoader classLoader) {
@@ -554,7 +554,7 @@ public void deletePublisherOfEntitiesShouldRemoveEntities() {
554554

555555
}
556556

557-
static interface ReactivePersonRepostitory extends ReactiveMongoRepository<ReactivePerson, String> {
557+
interface ReactivePersonRepostitory extends ReactiveMongoRepository<ReactivePerson, String> {
558558

559559
Flux<ReactivePerson> findByLastname(String lastname);
560560

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/ReactiveMongoRepositoriesRegistrarIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import com.mongodb.reactivestreams.client.MongoClients;
3737

3838
/**
39-
* Integration tests for {@link MongoRepositoriesRegistrar}.
39+
* Integration tests for {@link ReactiveMongoRepositoriesRegistrar}.
4040
*
4141
* @author Mark Paluch
4242
*/

0 commit comments

Comments
 (0)