Skip to content

Simplify Operations by uniting Sync and Async operations #1776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
abstract class AbstractWriteSearchIndexOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
abstract class AbstractWriteSearchIndexOperation implements WriteOperation<Void> {
private final MongoNamespace namespace;

AbstractWriteSearchIndexOperation(final MongoNamespace namespace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class AggregateOperation<T> implements AsyncExplainableReadOperation<AsyncBatchCursor<T>>, ExplainableReadOperation<BatchCursor<T>> {
public class AggregateOperation<T> implements ReadOperationExplainable<T> {
private final AggregateOperationImpl<T> wrapped;

public AggregateOperation(final MongoNamespace namespace, final List<BsonDocument> pipeline, final Decoder<T> decoder) {
Expand Down Expand Up @@ -151,13 +151,7 @@ public void executeAsync(final AsyncReadBinding binding, final SingleResultCallb
}

@Override
public <R> ReadOperation<R> asExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder<R> resultDecoder) {
return createExplainableOperation(verbosity, resultDecoder);
}

@Override
public <R> AsyncReadOperation<R> asAsyncExplainableOperation(@Nullable final ExplainVerbosity verbosity,
final Decoder<R> resultDecoder) {
public <R> ReadOperationSimple<R> asExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder<R> resultDecoder) {
return createExplainableOperation(verbosity, resultDecoder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static com.mongodb.internal.operation.SyncOperationHelper.CommandReadTransformer;
import static com.mongodb.internal.operation.SyncOperationHelper.executeRetryableRead;

class AggregateOperationImpl<T> implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>> {
class AggregateOperationImpl<T> implements ReadOperationCursor<T> {
private static final String COMMAND_NAME = "aggregate";
private static final String RESULT = "result";
private static final String CURSOR = "cursor";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class AggregateToCollectionOperation implements ReadOperation<Void>, AsyncReadOperation<Void> {
public class AggregateToCollectionOperation implements ReadOperationSimple<Void> {
private static final String COMMAND_NAME = "aggregate";
private final MongoNamespace namespace;
private final List<BsonDocument> pipeline;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public abstract class BaseFindAndModifyOperation<T> implements AsyncWriteOperation<T>, WriteOperation<T> {
public abstract class BaseFindAndModifyOperation<T> implements WriteOperation<T> {
private static final String COMMAND_NAME = "findAndModify";
private final MongoNamespace namespace;
private final WriteConcern writeConcern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class ChangeStreamOperation<T> implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>> {
public class ChangeStreamOperation<T> implements ReadOperationCursor<T> {
private static final RawBsonDocumentCodec RAW_BSON_DOCUMENT_CODEC = new RawBsonDocumentCodec();
private final AggregateOperationImpl<RawBsonDocument> wrapped;
private final FullDocument fullDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
/**
* This class is not part of the public API and may be removed or changed at any time.
*/
public final class ClientBulkWriteOperation implements AsyncWriteOperation<ClientBulkWriteResult>, WriteOperation<ClientBulkWriteResult> {
public final class ClientBulkWriteOperation implements WriteOperation<ClientBulkWriteResult> {
private static final ConcreteClientBulkWriteOptions EMPTY_OPTIONS = new ConcreteClientBulkWriteOptions();
private static final String BULK_WRITE_COMMAND_NAME = "bulkWrite";
private static final EncoderContext DEFAULT_ENCODER_CONTEXT = EncoderContext.builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class CommandReadOperation<T> implements AsyncReadOperation<T>, ReadOperation<T> {
public class CommandReadOperation<T> implements ReadOperationSimple<T> {
private final String commandName;
private final String databaseName;
private final CommandCreator commandCreator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class CountDocumentsOperation implements AsyncReadOperation<Long>, ReadOperation<Long> {
public class CountDocumentsOperation implements ReadOperationSimple<Long> {
private static final String COMMAND_NAME = "aggregate";
private static final Decoder<BsonDocument> DECODER = new BsonDocumentCodec();
private final MongoNamespace namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class CountOperation implements AsyncReadOperation<Long>, ReadOperation<Long> {
public class CountOperation implements ReadOperationSimple<Long> {
private static final String COMMAND_NAME = "count";
private static final Decoder<BsonDocument> DECODER = new BsonDocumentCodec();
private final MongoNamespace namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class CreateCollectionOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
public class CreateCollectionOperation implements WriteOperation<Void> {
private static final String ENCRYPT_PREFIX = "enxcol_.";
private static final BsonDocument ENCRYPT_CLUSTERED_INDEX = BsonDocument.parse("{key: {_id: 1}, unique: true}");
private static final BsonArray SAFE_CONTENT_ARRAY = new BsonArray(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class CreateIndexesOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
public class CreateIndexesOperation implements WriteOperation<Void> {
private static final String COMMAND_NAME = "createIndexes";
private final MongoNamespace namespace;
private final List<IndexRequest> requests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class CreateViewOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
public class CreateViewOperation implements WriteOperation<Void> {
private final String databaseName;
private final String viewName;
private final String viewOn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class DistinctOperation<T> implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>> {
public class DistinctOperation<T> implements ReadOperationCursor<T> {
private static final String COMMAND_NAME = "distinct";
private static final String VALUES = "values";
private final MongoNamespace namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class DropCollectionOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
public class DropCollectionOperation implements WriteOperation<Void> {
private static final String ENCRYPT_PREFIX = "enxcol_.";
private static final BsonValueCodec BSON_VALUE_CODEC = new BsonValueCodec();
private final MongoNamespace namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class DropDatabaseOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
public class DropDatabaseOperation implements WriteOperation<Void> {
private final String databaseName;
private final WriteConcern writeConcern;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class DropIndexOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
public class DropIndexOperation implements WriteOperation<Void> {
private static final String COMMAND_NAME = "dropIndexes";
private final MongoNamespace namespace;
private final String indexName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/**
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class EstimatedDocumentCountOperation implements AsyncReadOperation<Long>, ReadOperation<Long> {
public class EstimatedDocumentCountOperation implements ReadOperationSimple<Long> {
private static final String COMMAND_NAME = "count";
private static final Decoder<BsonDocument> DECODER = new BsonDocumentCodec();
private final MongoNamespace namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class FindOperation<T> implements AsyncExplainableReadOperation<AsyncBatchCursor<T>>, ExplainableReadOperation<BatchCursor<T>> {
public class FindOperation<T> implements ReadOperationExplainable<T> {
private static final String COMMAND_NAME = "find";
private static final String FIRST_BATCH = "firstBatch";

Expand Down Expand Up @@ -361,11 +361,6 @@ private static <T> SingleResultCallback<T> exceptionTransformingCallback(final S
public <R> CommandReadOperation<R> asExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder<R> resultDecoder) {
return createExplainableOperation(verbosity, resultDecoder);
}
@Override
public <R> AsyncReadOperation<R> asAsyncExplainableOperation(@Nullable final ExplainVerbosity verbosity,
final Decoder<R> resultDecoder) {
return createExplainableOperation(verbosity, resultDecoder);
}

<R> CommandReadOperation<R> createExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder<R> resultDecoder) {
return new CommandReadOperation<>(getNamespace().getDatabaseName(), getCommandName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class ListCollectionsOperation<T> implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>> {
public class ListCollectionsOperation<T> implements ReadOperationCursor<T> {
private static final String COMMAND_NAME = "listCollections";
private final String databaseName;
private final Decoder<T> decoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class ListDatabasesOperation<T> implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>> {
public class ListDatabasesOperation<T> implements ReadOperationCursor<T> {
private static final String COMMAND_NAME = "listDatabases";
private static final String DATABASES = "databases";
private final Decoder<T> decoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class ListIndexesOperation<T> implements AsyncReadOperation<AsyncBatchCursor<T>>, ReadOperation<BatchCursor<T>> {
public class ListIndexesOperation<T> implements ReadOperationCursor<T> {
private static final String COMMAND_NAME = "listIndexes";
private final MongoNamespace namespace;
private final Decoder<T> decoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public final class ListSearchIndexesOperation<T>
implements AsyncExplainableReadOperation<AsyncBatchCursor<T>>, ExplainableReadOperation<BatchCursor<T>> {
public final class ListSearchIndexesOperation<T> implements ReadOperationExplainable<T> {
private static final String COMMAND_NAME = "aggregate";
private static final String STAGE_LIST_SEARCH_INDEXES = "$listSearchIndexes";
private final MongoNamespace namespace;
Expand Down Expand Up @@ -107,16 +106,10 @@ public void executeAsync(final AsyncReadBinding binding, final SingleResultCallb
}

@Override
public <R> ReadOperation<R> asExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder<R> resultDecoder) {
public <R> ReadOperationSimple<R> asExplainableOperation(@Nullable final ExplainVerbosity verbosity, final Decoder<R> resultDecoder) {
return asAggregateOperation().asExplainableOperation(verbosity, resultDecoder);
}

@Override
public <R> AsyncReadOperation<R> asAsyncExplainableOperation(@Nullable final ExplainVerbosity verbosity,
final Decoder<R> resultDecoder) {
return asAggregateOperation().asAsyncExplainableOperation(verbosity, resultDecoder);
}

private AggregateOperation<T> asAggregateOperation() {
BsonDocument searchDefinition = getSearchDefinition();
BsonDocument listSearchIndexesStage = new BsonDocument(STAGE_LIST_SEARCH_INDEXES, searchDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class MapReduceToCollectionOperation implements AsyncWriteOperation<MapReduceStatistics>, WriteOperation<MapReduceStatistics> {
public class MapReduceToCollectionOperation implements WriteOperation<MapReduceStatistics> {
private static final String COMMAND_NAME = "mapReduce";
private final MongoNamespace namespace;
private final BsonJavaScript mapFunction;
Expand Down Expand Up @@ -234,17 +234,7 @@ public void executeAsync(final AsyncWriteBinding binding, final SingleResultCall
* @param explainVerbosity the explain verbosity
* @return a read operation that when executed will explain this operation
*/
public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) {
return createExplainableOperation(explainVerbosity);
}

/**
* Gets an operation whose execution explains this operation.
*
* @param explainVerbosity the explain verbosity
* @return a read operation that when executed will explain this operation
*/
public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) {
public ReadOperationSimple<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) {
return createExplainableOperation(explainVerbosity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class MapReduceWithInlineResultsOperation<T> implements ReadOperation<MapReduceBatchCursor<T>>,
AsyncReadOperation<MapReduceAsyncBatchCursor<T>> {
public class MapReduceWithInlineResultsOperation<T> implements ReadOperation<MapReduceBatchCursor<T>, MapReduceAsyncBatchCursor<T>> {
private static final String COMMAND_NAME = "mapReduce";
private final MongoNamespace namespace;
private final BsonJavaScript mapFunction;
Expand Down Expand Up @@ -185,11 +184,7 @@ public void executeAsync(final AsyncReadBinding binding, final SingleResultCallb
asyncTransformer(), false, errHandlingCallback);
}

public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) {
return createExplainableOperation(explainVerbosity);
}

public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) {
public ReadOperationSimple<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) {
return createExplainableOperation(explainVerbosity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class MixedBulkWriteOperation implements AsyncWriteOperation<BulkWriteResult>, WriteOperation<BulkWriteResult> {
public class MixedBulkWriteOperation implements WriteOperation<BulkWriteResult> {
private final MongoNamespace namespace;
private final List<? extends WriteRequest> writeRequests;
private final boolean ordered;
Expand Down
Loading