Skip to content

Commit 60f7628

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-1444 - Adopt changes in Spring Data Commons.
- Adopt RxJava to RxJava1 repository interface renaming. - Remove ReactiveChunk, Slice and Page. - Update documentation. - Prevent sliced/paged query execution.
1 parent a73c947 commit 60f7628

24 files changed

+49
-967
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public interface ReactiveMongoOperations {
5858
*
5959
* @return index operations on the named collection
6060
*/
61-
ReactiveIndexOperations reactiveIndexOps(String collectionName);
61+
ReactiveIndexOperations indexOps(String collectionName);
6262

6363
/**
6464
* Returns the reactive operations that can be performed on indexes
6565
*
6666
* @return index operations on the named collection associated with the given entity class
6767
*/
68-
ReactiveIndexOperations reactiveIndexOps(Class<?> entityClass);
68+
ReactiveIndexOperations indexOps(Class<?> entityClass);
6969

7070
/**
7171
* Execute the a MongoDB command expressed as a JSON string. This will call the method JSON.parse that is part of the

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory,
209209

210210
if (null != mappingContext && mappingContext instanceof MongoMappingContext) {
211211
indexCreator = new MongoPersistentEntityIndexCreator((MongoMappingContext) mappingContext,
212-
(collectionName) -> IndexOperationsAdapter.blocking(reactiveIndexOps(collectionName)));
212+
(collectionName) -> IndexOperationsAdapter.blocking(indexOps(collectionName)));
213213
eventPublisher = new MongoMappingEventPublisher(indexCreator);
214214
if (mappingContext instanceof ApplicationEventPublisherAware) {
215215
((ApplicationEventPublisherAware) mappingContext).setApplicationEventPublisher(eventPublisher);
@@ -316,14 +316,14 @@ public MongoConverter getConverter() {
316316
/* (non-Javadoc)
317317
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#reactiveIndexOps(java.lang.String)
318318
*/
319-
public ReactiveIndexOperations reactiveIndexOps(String collectionName) {
319+
public ReactiveIndexOperations indexOps(String collectionName) {
320320
return new DefaultReactiveIndexOperations(this, collectionName);
321321
}
322322

323323
/* (non-Javadoc)
324324
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#reactiveIndexOps(java.lang.Class)
325325
*/
326-
public ReactiveIndexOperations reactiveIndexOps(Class<?> entityClass) {
326+
public ReactiveIndexOperations indexOps(Class<?> entityClass) {
327327
return new DefaultReactiveIndexOperations(this, determineCollectionName(entityClass));
328328
}
329329

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.springframework.data.domain.Example;
2222
import org.springframework.data.domain.Sort;
2323
import org.springframework.data.repository.NoRepositoryBean;
24-
import org.springframework.data.repository.reactive.ReactivePagingAndSortingRepository;
2524

25+
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
2626
import reactor.core.publisher.Flux;
2727
import reactor.core.publisher.Mono;
2828

@@ -33,7 +33,7 @@
3333
* @since 2.0
3434
*/
3535
@NoRepositoryBean
36-
public interface ReactiveMongoRepository<T, ID extends Serializable> extends ReactivePagingAndSortingRepository<T, ID> {
36+
public interface ReactiveMongoRepository<T, ID extends Serializable> extends ReactiveSortingRepository<T, ID> {
3737

3838
/**
3939
* Inserts the given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.CollectionExecution;
2626
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.DeleteExecution;
2727
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution;
28-
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.PagedExecution;
2928
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.ResultProcessingConverter;
3029
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.ResultProcessingExecution;
3130
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.SingleEntityExecution;
32-
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.SlicedExecution;
3331
import org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.TailExecution;
3432
import org.springframework.data.repository.query.ParameterAccessor;
3533
import org.springframework.data.repository.query.RepositoryQuery;
@@ -136,14 +134,10 @@ private ReactiveMongoQueryExecution getExecutionToWrap(MongoParameterAccessor ac
136134
return new DeleteExecution(operations, method);
137135
} else if (method.isGeoNearQuery()) {
138136
return new GeoNearExecution(operations, accessor, method.getReturnType());
139-
} else if (method.isSliceQuery()) {
140-
return new SlicedExecution(operations, accessor.getPageable());
141137
} else if (isInfiniteStream(method)) {
142138
return new TailExecution(operations, accessor.getPageable());
143139
} else if (method.isCollectionQuery()) {
144140
return new CollectionExecution(operations, accessor.getPageable());
145-
} else if (method.isPageQuery()) {
146-
return new PagedExecution(operations, accessor.getPageable());
147141
} else {
148142
return new SingleEntityExecution(operations, isCountQuery());
149143
}

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

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
2727
import org.springframework.data.mongodb.core.query.NearQuery;
2828
import org.springframework.data.mongodb.core.query.Query;
29-
import org.springframework.data.mongodb.repository.support.ReactivePageImpl;
30-
import org.springframework.data.mongodb.repository.support.ReactiveSliceImpl;
3129
import org.springframework.data.repository.query.ResultProcessor;
3230
import org.springframework.data.repository.query.ReturnedType;
3331
import org.springframework.data.repository.util.ReactiveWrappers;
@@ -87,61 +85,6 @@ public Object execute(Query query, Class<?> type, String collection) {
8785
}
8886
}
8987

90-
/**
91-
* {@link ReactiveMongoQueryExecution} for {@link Slice} query methods.
92-
*
93-
* @author Mark Paluch
94-
*/
95-
@RequiredArgsConstructor
96-
final class SlicedExecution implements ReactiveMongoQueryExecution {
97-
98-
private final @NonNull ReactiveMongoOperations operations;
99-
private final @NonNull Pageable pageable;
100-
101-
@Override
102-
public Object execute(Query query, Class<?> type, String collection) {
103-
104-
int pageSize = pageable.getPageSize();
105-
106-
// Apply Pageable but tweak limit to peek into next page
107-
Query modifiedQuery = query.with(pageable).limit(pageSize + 1);
108-
Flux<?> flux = operations.find(modifiedQuery, type, collection);
109-
110-
return Mono.fromSupplier(() -> new ReactiveSliceImpl<>(flux, pageable));
111-
}
112-
}
113-
114-
/**
115-
* {@link ReactiveMongoQueryExecution} for pagination queries.
116-
*
117-
* @author Mark Paluch
118-
*/
119-
@RequiredArgsConstructor
120-
final class PagedExecution implements ReactiveMongoQueryExecution {
121-
122-
private final @NonNull ReactiveMongoOperations operations;
123-
private final @NonNull Pageable pageable;
124-
125-
@Override
126-
public Object execute(Query query, Class<?> type, String collection) {
127-
128-
int overallLimit = query.getLimit();
129-
Mono<Long> count = operations.count(query, type, collection);
130-
131-
// Apply raw pagination
132-
query = query.with(pageable);
133-
134-
// Adjust limit if page would exceed the overall limit
135-
if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) {
136-
query.limit(overallLimit - pageable.getOffset());
137-
}
138-
139-
Flux<?> flux = operations.find(query, type, collection);
140-
141-
return Mono.fromSupplier(() -> new ReactivePageImpl<>(flux, pageable, count));
142-
}
143-
}
144-
14588
/**
14689
* {@link ReactiveMongoQueryExecution} to return a single entity.
14790
*

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.lang.reflect.Method;
2121

22+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2223
import org.springframework.data.domain.Page;
2324
import org.springframework.data.domain.Pageable;
2425
import org.springframework.data.domain.Slice;
@@ -34,6 +35,7 @@
3435
import org.springframework.data.repository.util.ReactiveWrappers;
3536
import org.springframework.data.util.ClassTypeInformation;
3637
import org.springframework.data.util.TypeInformation;
38+
import org.springframework.util.ClassUtils;
3739

3840
/**
3941
* Reactive specific implementation of {@link MongoQueryMethod}.
@@ -71,6 +73,12 @@ public ReactiveMongoQueryMethod(Method method, RepositoryMetadata metadata, Proj
7173
&& (PAGE_TYPE.isAssignableFrom(returnType.getComponentType())
7274
|| SLICE_TYPE.isAssignableFrom(returnType.getComponentType()));
7375

76+
if (singleWrapperWithWrappedPageableResult) {
77+
throw new InvalidDataAccessApiUsageException(
78+
String.format("'%s.%s' must not use sliced or paged execution. Please use Flux.buffer(size, skip).",
79+
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
80+
}
81+
7482
if (!multiWrapper && !singleWrapperWithWrappedPageableResult) {
7583
throw new IllegalStateException(String.format(
7684
"Method has to use a either multi-item reactive wrapper return type or a wrapped Page/Slice type. Offending method: %s",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
4343
import org.springframework.data.repository.query.RepositoryQuery;
4444
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
45-
import org.springframework.data.repository.reactive.RxJavaCrudRepository;
45+
import org.springframework.data.repository.reactive.RxJava1CrudRepository;
4646
import org.springframework.data.repository.util.QueryExecutionConverters;
4747
import org.springframework.data.repository.util.ReactiveWrappers;
4848
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -92,7 +92,7 @@ protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
9292

9393

9494
boolean isReactiveRepository = (PROJECT_REACTOR_PRESENT && ReactiveCrudRepository.class.isAssignableFrom(metadata.getRepositoryInterface())) || (
95-
RXJAVA_OBSERVABLE_PRESENT && RxJavaCrudRepository.class.isAssignableFrom(metadata.getRepositoryInterface()));
95+
RXJAVA_OBSERVABLE_PRESENT && RxJava1CrudRepository.class.isAssignableFrom(metadata.getRepositoryInterface()));
9696

9797
boolean isQueryDslRepository = QUERY_DSL_PRESENT
9898
&& QueryDslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());

0 commit comments

Comments
 (0)