All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mongodb.internal.operation.AggregateOperation Maven / Gradle / Ivy

Go to download

The Java operations layer for the MongoDB Java Driver. Third parties can ' + 'wrap this layer to provide custom higher-level APIs

There is a newer version: 5.3.0-beta0
Show 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.internal.operation;

import com.mongodb.ExplainVerbosity;
import com.mongodb.MongoNamespace;
import com.mongodb.client.model.Collation;
import com.mongodb.internal.async.AsyncBatchCursor;
import com.mongodb.internal.async.SingleResultCallback;
import com.mongodb.internal.binding.AsyncReadBinding;
import com.mongodb.internal.binding.ReadBinding;
import com.mongodb.internal.client.model.AggregationLevel;
import com.mongodb.internal.connection.NoOpSessionContext;
import com.mongodb.lang.Nullable;
import org.bson.BsonDocument;
import org.bson.BsonValue;
import org.bson.codecs.Decoder;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.mongodb.internal.operation.ExplainHelper.asExplainCommand;
import static com.mongodb.internal.operation.ServerVersionHelper.MIN_WIRE_VERSION;

/**
 * An operation that executes an aggregation query.
 *
 * 

This class is not part of the public API and may be removed or changed at any time

*/ public class AggregateOperation implements AsyncExplainableReadOperation>, ExplainableReadOperation> { private final AggregateOperationImpl wrapped; public AggregateOperation(final MongoNamespace namespace, final List pipeline, final Decoder decoder) { this(namespace, pipeline, decoder, AggregationLevel.COLLECTION); } public AggregateOperation(final MongoNamespace namespace, final List pipeline, final Decoder decoder, final AggregationLevel aggregationLevel) { this.wrapped = new AggregateOperationImpl<>(namespace, pipeline, decoder, aggregationLevel); } public List getPipeline() { return wrapped.getPipeline(); } public Boolean getAllowDiskUse() { return wrapped.getAllowDiskUse(); } public AggregateOperation allowDiskUse(@Nullable final Boolean allowDiskUse) { wrapped.allowDiskUse(allowDiskUse); return this; } public Integer getBatchSize() { return wrapped.getBatchSize(); } public AggregateOperation batchSize(@Nullable final Integer batchSize) { wrapped.batchSize(batchSize); return this; } public long getMaxAwaitTime(final TimeUnit timeUnit) { return wrapped.getMaxAwaitTime(timeUnit); } public AggregateOperation maxAwaitTime(final long maxAwaitTime, final TimeUnit timeUnit) { wrapped.maxAwaitTime(maxAwaitTime, timeUnit); return this; } public long getMaxTime(final TimeUnit timeUnit) { return wrapped.getMaxTime(timeUnit); } public AggregateOperation maxTime(final long maxTime, final TimeUnit timeUnit) { wrapped.maxTime(maxTime, timeUnit); return this; } public Collation getCollation() { return wrapped.getCollation(); } public AggregateOperation collation(@Nullable final Collation collation) { wrapped.collation(collation); return this; } @Nullable public BsonValue getComment() { return wrapped.getComment(); } public AggregateOperation comment(@Nullable final BsonValue comment) { wrapped.comment(comment); return this; } public AggregateOperation let(@Nullable final BsonDocument variables) { wrapped.let(variables); return this; } public AggregateOperation retryReads(final boolean retryReads) { wrapped.retryReads(retryReads); return this; } public boolean getRetryReads() { return wrapped.getRetryReads(); } @Nullable public BsonDocument getHint() { BsonValue hint = wrapped.getHint(); if (hint == null) { return null; } if (!hint.isDocument()) { throw new IllegalArgumentException("Hint is not a BsonDocument please use the #getHintBsonValue() method. "); } return hint.asDocument(); } @Nullable public BsonValue getHintBsonValue() { return wrapped.getHint(); } public AggregateOperation hint(@Nullable final BsonValue hint) { wrapped.hint(hint); return this; } @Override public BatchCursor execute(final ReadBinding binding) { return wrapped.execute(binding); } @Override public void executeAsync(final AsyncReadBinding binding, final SingleResultCallback> callback) { wrapped.executeAsync(binding, callback); } public ReadOperation asExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder resultDecoder) { return new CommandReadOperation<>(getNamespace().getDatabaseName(), asExplainCommand(wrapped.getCommand(NoOpSessionContext.INSTANCE, MIN_WIRE_VERSION), verbosity), resultDecoder); } public AsyncReadOperation asAsyncExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder resultDecoder) { return new CommandReadOperation<>(getNamespace().getDatabaseName(), asExplainCommand(wrapped.getCommand(NoOpSessionContext.INSTANCE, MIN_WIRE_VERSION), verbosity), resultDecoder); } MongoNamespace getNamespace() { return wrapped.getNamespace(); } Decoder getDecoder() { return wrapped.getDecoder(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy