com.mongodb.reactivestreams.client.internal.ListSearchIndexesPublisherImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongodb-driver-reactivestreams Show documentation
Show all versions of mongodb-driver-reactivestreams Show documentation
A Reactive Streams implementation of the MongoDB Java driver
The newest version!
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mongodb.reactivestreams.client.internal;
import com.mongodb.ExplainVerbosity;
import com.mongodb.client.cursor.TimeoutMode;
import com.mongodb.client.model.Collation;
import com.mongodb.internal.TimeoutSettings;
import com.mongodb.internal.async.AsyncBatchCursor;
import com.mongodb.internal.operation.AsyncExplainableReadOperation;
import com.mongodb.internal.operation.AsyncOperations;
import com.mongodb.internal.operation.AsyncReadOperation;
import com.mongodb.lang.Nullable;
import com.mongodb.reactivestreams.client.ListSearchIndexesPublisher;
import org.bson.BsonString;
import org.bson.BsonValue;
import org.bson.Document;
import org.reactivestreams.Publisher;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import static com.mongodb.assertions.Assertions.notNull;
final class ListSearchIndexesPublisherImpl extends BatchCursorPublisher implements ListSearchIndexesPublisher {
@Nullable
private Boolean allowDiskUse;
private long maxTimeMS;
@Nullable
private Collation collation;
@Nullable
private BsonValue comment;
@Nullable
private String indexName;
ListSearchIndexesPublisherImpl(
final MongoOperationPublisher mongoOperationPublisher) {
super(null, mongoOperationPublisher);
}
@Override
public ListSearchIndexesPublisher name(final String indexName) {
this.indexName = notNull("indexName", indexName);
return this;
}
@Override
public ListSearchIndexesPublisher allowDiskUse(@Nullable final Boolean allowDiskUse) {
this.allowDiskUse = allowDiskUse;
return this;
}
@Override
public ListSearchIndexesPublisher batchSize(final int batchSize) {
super.batchSize(batchSize);
return this;
}
@Override
public ListSearchIndexesPublisher maxTime(final long maxTime, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit);
return this;
}
@Override
public ListSearchIndexesPublisher collation(@Nullable final Collation collation) {
this.collation = collation;
return this;
}
@Override
public ListSearchIndexesPublisher comment(@Nullable final String comment) {
this.comment = comment != null ? new BsonString(comment) : null;
return this;
}
@Override
public ListSearchIndexesPublisher timeoutMode(final TimeoutMode timeoutMode) {
super.timeoutMode(timeoutMode);
return this;
}
@Override
public ListSearchIndexesPublisher comment(@Nullable final BsonValue comment) {
this.comment = comment;
return this;
}
@Override
public Publisher explain() {
return publishExplain(Document.class, null);
}
@Override
public Publisher explain(final ExplainVerbosity verbosity) {
notNull("verbosity", verbosity);
return publishExplain(Document.class, verbosity);
}
@Override
public Publisher explain(final Class explainResultClass) {
notNull("explainResultClass", explainResultClass);
return publishExplain(explainResultClass, null);
}
@Override
public Publisher explain(final Class explainResultClass, final ExplainVerbosity verbosity) {
notNull("verbosity", verbosity);
notNull("explainResultClass", explainResultClass);
return publishExplain(explainResultClass, verbosity);
}
private Publisher publishExplain(final Class explainResultClass, @Nullable final ExplainVerbosity verbosity) {
return getMongoOperationPublisher().createReadOperationMono(
(asyncOperations -> asyncOperations.createTimeoutSettings(maxTimeMS)),
() -> asAggregateOperation(1).asAsyncExplainableOperation(verbosity,
getCodecRegistry().get(explainResultClass)), getClientSession());
}
@Override
AsyncReadOperation> asAsyncReadOperation(final int initialBatchSize) {
return asAggregateOperation(initialBatchSize);
}
@Override
Function, TimeoutSettings> getTimeoutSettings() {
return (asyncOperations -> asyncOperations.createTimeoutSettings(maxTimeMS));
}
private AsyncExplainableReadOperation> asAggregateOperation(final int initialBatchSize) {
return getOperations().listSearchIndexes(getDocumentClass(), indexName, initialBatchSize, collation, comment, allowDiskUse);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy