DATAMONGO-2344 - Polishing.
Remove generics from FindPublisherPreparer. Rename ReadPreferenceAware.hasReadPreferences to hasReadPreference. Original pull request: #779.
This commit is contained in:
@@ -50,7 +50,7 @@ interface CursorPreparer extends ReadPreferenceAware {
|
||||
/**
|
||||
* Apply query specific settings to {@link MongoCollection} and initate a find operation returning a
|
||||
* {@link FindIterable} via the given {@link Function find} function.
|
||||
*
|
||||
*
|
||||
* @param collection must not be {@literal null}.
|
||||
* @param find must not be {@literal null}.
|
||||
* @return
|
||||
@@ -63,7 +63,7 @@ interface CursorPreparer extends ReadPreferenceAware {
|
||||
Assert.notNull(collection, "Collection must not be null!");
|
||||
Assert.notNull(find, "Find function must not be null!");
|
||||
|
||||
if (hasReadPreferences()) {
|
||||
if (hasReadPreference()) {
|
||||
collection = collection.withReadPreference(getReadPreference());
|
||||
}
|
||||
|
||||
|
||||
@@ -38,20 +38,14 @@ interface FindPublisherPreparer extends ReadPreferenceAware {
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
FindPublisherPreparer NO_OP_PREPARER = new FindPublisherPreparer() {
|
||||
|
||||
@Override
|
||||
public <T> FindPublisher<T> prepare(FindPublisher<T> findPublisher) {
|
||||
return findPublisher;
|
||||
}
|
||||
};
|
||||
FindPublisherPreparer NO_OP_PREPARER = (findPublisher -> findPublisher);
|
||||
|
||||
/**
|
||||
* Prepare the given cursor (apply limits, skips and so on). Returns the prepared cursor.
|
||||
*
|
||||
* @param findPublisher must not be {@literal null}.
|
||||
*/
|
||||
<T> FindPublisher<T> prepare(FindPublisher<T> findPublisher);
|
||||
FindPublisher<Document> prepare(FindPublisher<Document> findPublisher);
|
||||
|
||||
/**
|
||||
* Apply query specific settings to {@link MongoCollection} and initate a find operation returning a
|
||||
@@ -69,7 +63,7 @@ interface FindPublisherPreparer extends ReadPreferenceAware {
|
||||
Assert.notNull(collection, "Collection must not be null!");
|
||||
Assert.notNull(find, "Find function must not be null!");
|
||||
|
||||
if (hasReadPreferences()) {
|
||||
if (hasReadPreference()) {
|
||||
collection = collection.withReadPreference(getReadPreference());
|
||||
}
|
||||
|
||||
|
||||
@@ -935,7 +935,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
}
|
||||
|
||||
QueryCursorPreparer preparer = new QueryCursorPreparer(query, entityClass);
|
||||
if (preparer.hasReadPreferences()) {
|
||||
if (preparer.hasReadPreference()) {
|
||||
collection = collection.withReadPreference(preparer.getReadPreference());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.data.mongodb.core.query.NearQuery;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
@@ -31,8 +32,6 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.reactivestreams.client.FindPublisher;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ReactiveFindOperation}.
|
||||
*
|
||||
@@ -120,12 +119,7 @@ class ReactiveFindOperationSupport implements ReactiveFindOperation {
|
||||
public Mono<T> first() {
|
||||
|
||||
FindPublisherPreparer preparer = getCursorPreparer(query);
|
||||
Flux<T> result = doFind(new FindPublisherPreparer() {
|
||||
@Override
|
||||
public <D> FindPublisher<D> prepare(FindPublisher<D> publisher) {
|
||||
return preparer.prepare(publisher).limit(1);
|
||||
}
|
||||
});
|
||||
Flux<T> result = doFind(publisher -> preparer.prepare(publisher).limit(1));
|
||||
|
||||
return result.next();
|
||||
}
|
||||
@@ -138,12 +132,7 @@ class ReactiveFindOperationSupport implements ReactiveFindOperation {
|
||||
public Mono<T> one() {
|
||||
|
||||
FindPublisherPreparer preparer = getCursorPreparer(query);
|
||||
Flux<T> result = doFind(new FindPublisherPreparer() {
|
||||
@Override
|
||||
public <D> FindPublisher<D> prepare(FindPublisher<D> publisher) {
|
||||
return preparer.prepare(publisher).limit(2);
|
||||
}
|
||||
});
|
||||
Flux<T> result = doFind(publisher -> preparer.prepare(publisher).limit(2));
|
||||
|
||||
return result.collectList().flatMap(it -> {
|
||||
|
||||
|
||||
@@ -934,7 +934,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
FindPublisherPreparer preparer = new QueryFindPublisherPreparer(query, entityClass);
|
||||
if (preparer.hasReadPreferences()) {
|
||||
if (preparer.hasReadPreference()) {
|
||||
collection = collection.withReadPreference(preparer.getReadPreference());
|
||||
}
|
||||
|
||||
@@ -2334,12 +2334,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
protected <T> Mono<T> doFindOne(String collectionName, Document query, @Nullable Document fields,
|
||||
Class<T> entityClass, @Nullable Collation collation) {
|
||||
|
||||
return doFindOne(collectionName, query, fields, entityClass, new FindPublisherPreparer() {
|
||||
@Override
|
||||
public <T> FindPublisher<T> prepare(FindPublisher<T> findPublisher) {
|
||||
return collation != null ? findPublisher.collation(collation.toMongoCollation()) : findPublisher;
|
||||
}
|
||||
});
|
||||
return doFindOne(collectionName, query, fields, entityClass,
|
||||
findPublisher -> collation != null ? findPublisher.collation(collation.toMongoCollation()) : findPublisher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3183,9 +3179,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public <T> FindPublisher<T> prepare(FindPublisher<T> findPublisher) {
|
||||
public FindPublisher<Document> prepare(FindPublisher<Document> findPublisher) {
|
||||
|
||||
FindPublisher<T> findPublisherToUse = operations.forType(type) //
|
||||
FindPublisher<Document> findPublisherToUse = operations.forType(type) //
|
||||
.getCollation(query) //
|
||||
.map(Collation::toMongoCollation) //
|
||||
.map(findPublisher::collation) //
|
||||
@@ -3259,7 +3255,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> FindPublisher<T> prepare(FindPublisher<T> findPublisher) {
|
||||
public FindPublisher<Document> prepare(FindPublisher<Document> findPublisher) {
|
||||
return super.prepare(findPublisher.cursorType(CursorType.TailableAwait));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,12 @@ import org.springframework.lang.Nullable;
|
||||
import com.mongodb.ReadPreference;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by any object that wishes to expose the {@link ReadPreference}.
|
||||
* <p>
|
||||
* Typically implemented by cursor or query preparer objects.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 2.2
|
||||
*/
|
||||
interface ReadPreferenceAware {
|
||||
@@ -28,7 +33,7 @@ interface ReadPreferenceAware {
|
||||
/**
|
||||
* @return {@literal true} if a {@link ReadPreference} is set.
|
||||
*/
|
||||
default boolean hasReadPreferences() {
|
||||
default boolean hasReadPreference() {
|
||||
return getReadPreference() != null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user