|
| 1 | +/* |
| 2 | + * Copyright 2008-present MongoDB, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.mongodb.internal.operation; |
| 18 | + |
| 19 | +import com.mongodb.AutoEncryptionSettings; |
| 20 | +import com.mongodb.MongoNamespace; |
| 21 | +import com.mongodb.ReadConcern; |
| 22 | +import com.mongodb.ReadPreference; |
| 23 | +import com.mongodb.WriteConcern; |
| 24 | +import com.mongodb.bulk.BulkWriteResult; |
| 25 | +import com.mongodb.client.model.BulkWriteOptions; |
| 26 | +import com.mongodb.client.model.Collation; |
| 27 | +import com.mongodb.client.model.CountOptions; |
| 28 | +import com.mongodb.client.model.CreateIndexOptions; |
| 29 | +import com.mongodb.client.model.DeleteOptions; |
| 30 | +import com.mongodb.client.model.DropCollectionOptions; |
| 31 | +import com.mongodb.client.model.DropIndexOptions; |
| 32 | +import com.mongodb.client.model.EstimatedDocumentCountOptions; |
| 33 | +import com.mongodb.client.model.FindOneAndDeleteOptions; |
| 34 | +import com.mongodb.client.model.FindOneAndReplaceOptions; |
| 35 | +import com.mongodb.client.model.FindOneAndUpdateOptions; |
| 36 | +import com.mongodb.client.model.IndexModel; |
| 37 | +import com.mongodb.client.model.InsertManyOptions; |
| 38 | +import com.mongodb.client.model.InsertOneOptions; |
| 39 | +import com.mongodb.client.model.RenameCollectionOptions; |
| 40 | +import com.mongodb.client.model.ReplaceOptions; |
| 41 | +import com.mongodb.client.model.UpdateOptions; |
| 42 | +import com.mongodb.client.model.WriteModel; |
| 43 | +import com.mongodb.internal.async.AsyncBatchCursor; |
| 44 | +import com.mongodb.internal.client.model.AggregationLevel; |
| 45 | +import com.mongodb.internal.client.model.FindOptions; |
| 46 | +import org.bson.BsonValue; |
| 47 | +import org.bson.codecs.configuration.CodecRegistry; |
| 48 | +import org.bson.conversions.Bson; |
| 49 | + |
| 50 | +import java.util.List; |
| 51 | + |
| 52 | +/** |
| 53 | + * <p>This class is not part of the public API and may be removed or changed at any time</p> |
| 54 | + */ |
| 55 | +public final class AsyncOperations<TDocument> { |
| 56 | + private final Operations<TDocument> operations; |
| 57 | + |
| 58 | + public AsyncOperations(final MongoNamespace namespace, final Class<TDocument> documentClass, final ReadPreference readPreference, |
| 59 | + final CodecRegistry codecRegistry, final ReadConcern readConcern, final WriteConcern writeConcern, |
| 60 | + final boolean retryWrites, final boolean retryReads) { |
| 61 | + this.operations = new Operations<>(namespace, documentClass, readPreference, codecRegistry, readConcern, writeConcern, |
| 62 | + retryWrites, retryReads); |
| 63 | + } |
| 64 | + |
| 65 | + public MongoNamespace getNamespace() { |
| 66 | + return operations.getNamespace(); |
| 67 | + } |
| 68 | + |
| 69 | + public Class<TDocument> getDocumentClass() { |
| 70 | + return operations.getDocumentClass(); |
| 71 | + } |
| 72 | + |
| 73 | + public ReadPreference getReadPreference() { |
| 74 | + return operations.getReadPreference(); |
| 75 | + } |
| 76 | + |
| 77 | + public CodecRegistry getCodecRegistry() { |
| 78 | + return operations.getCodecRegistry(); |
| 79 | + } |
| 80 | + |
| 81 | + public ReadConcern getReadConcern() { |
| 82 | + return operations.getReadConcern(); |
| 83 | + } |
| 84 | + |
| 85 | + public WriteConcern getWriteConcern() { |
| 86 | + return operations.getWriteConcern(); |
| 87 | + } |
| 88 | + |
| 89 | + public boolean isRetryWrites() { |
| 90 | + return operations.isRetryWrites(); |
| 91 | + } |
| 92 | + |
| 93 | + public boolean isRetryReads() { |
| 94 | + return operations.isRetryReads(); |
| 95 | + } |
| 96 | + |
| 97 | + public AsyncReadOperation<Long> countDocuments(final Bson filter, final CountOptions options) { |
| 98 | + return operations.countDocuments(filter, options); |
| 99 | + } |
| 100 | + |
| 101 | + public AsyncReadOperation<Long> estimatedDocumentCount(final EstimatedDocumentCountOptions options) { |
| 102 | + return operations.estimatedDocumentCount(options); |
| 103 | + } |
| 104 | + |
| 105 | + public <TResult> AsyncReadOperation<AsyncBatchCursor<TResult>> findFirst(final Bson filter, final Class<TResult> resultClass, |
| 106 | + final FindOptions options) { |
| 107 | + return operations.findFirst(filter, resultClass, options); |
| 108 | + } |
| 109 | + |
| 110 | + public <TResult> AsyncExplainableReadOperation<AsyncBatchCursor<TResult>> find(final Bson filter, final Class<TResult> resultClass, |
| 111 | + final FindOptions options) { |
| 112 | + return operations.find(filter, resultClass, options); |
| 113 | + } |
| 114 | + |
| 115 | + public <TResult> AsyncReadOperation<AsyncBatchCursor<TResult>> find(final MongoNamespace findNamespace, final Bson filter, |
| 116 | + final Class<TResult> resultClass, final FindOptions options) { |
| 117 | + return operations.find(findNamespace, filter, resultClass, options); |
| 118 | + } |
| 119 | + |
| 120 | + public <TResult> AsyncReadOperation<AsyncBatchCursor<TResult>> distinct(final String fieldName, final Bson filter, |
| 121 | + final Class<TResult> resultClass, final long maxTimeMS, |
| 122 | + final Collation collation, final BsonValue comment) { |
| 123 | + return operations.distinct(fieldName, filter, resultClass, maxTimeMS, collation, comment); |
| 124 | + } |
| 125 | + |
| 126 | + public <TResult> AsyncExplainableReadOperation<AsyncBatchCursor<TResult>> aggregate(final List<? extends Bson> pipeline, |
| 127 | + final Class<TResult> resultClass, |
| 128 | + final long maxTimeMS, final long maxAwaitTimeMS, |
| 129 | + final Integer batchSize, |
| 130 | + final Collation collation, final Bson hint, |
| 131 | + final String hintString, |
| 132 | + final BsonValue comment, |
| 133 | + final Bson variables, |
| 134 | + final Boolean allowDiskUse, |
| 135 | + final AggregationLevel aggregationLevel) { |
| 136 | + return operations.aggregate(pipeline, resultClass, maxTimeMS, maxAwaitTimeMS, batchSize, collation, hint, hintString, comment, |
| 137 | + variables, allowDiskUse, aggregationLevel); |
| 138 | + } |
| 139 | + |
| 140 | + public AsyncReadOperation<Void> aggregateToCollection(final List<? extends Bson> pipeline, final long maxTimeMS, |
| 141 | + final Boolean allowDiskUse, final Boolean bypassDocumentValidation, |
| 142 | + final Collation collation, final Bson hint, final String hintString, final BsonValue comment, |
| 143 | + final Bson variables, final AggregationLevel aggregationLevel) { |
| 144 | + return operations.aggregateToCollection(pipeline, maxTimeMS, allowDiskUse, bypassDocumentValidation, collation, hint, hintString, |
| 145 | + comment, variables, aggregationLevel); |
| 146 | + } |
| 147 | + |
| 148 | + @SuppressWarnings("deprecation") |
| 149 | + public AsyncWriteOperation<MapReduceStatistics> mapReduceToCollection(final String databaseName, final String collectionName, |
| 150 | + final String mapFunction, final String reduceFunction, |
| 151 | + final String finalizeFunction, final Bson filter, final int limit, |
| 152 | + final long maxTimeMS, final boolean jsMode, final Bson scope, |
| 153 | + final Bson sort, final boolean verbose, |
| 154 | + final com.mongodb.client.model.MapReduceAction action, |
| 155 | + final boolean nonAtomic, final boolean sharded, |
| 156 | + final Boolean bypassDocumentValidation, final Collation collation) { |
| 157 | + return operations.mapReduceToCollection(databaseName, collectionName, mapFunction, reduceFunction, finalizeFunction, filter, limit, |
| 158 | + maxTimeMS, jsMode, scope, sort, verbose, action, nonAtomic, sharded, bypassDocumentValidation, collation); |
| 159 | + } |
| 160 | + |
| 161 | + public <TResult> AsyncReadOperation<MapReduceAsyncBatchCursor<TResult>> mapReduce(final String mapFunction, final String reduceFunction, |
| 162 | + final String finalizeFunction, final Class<TResult> resultClass, |
| 163 | + final Bson filter, final int limit, |
| 164 | + final long maxTimeMS, final boolean jsMode, final Bson scope, |
| 165 | + final Bson sort, final boolean verbose, |
| 166 | + final Collation collation) { |
| 167 | + return operations.mapReduce(mapFunction, reduceFunction, finalizeFunction, resultClass, filter, limit, maxTimeMS, jsMode, scope, |
| 168 | + sort, verbose, collation); |
| 169 | + } |
| 170 | + |
| 171 | + public AsyncWriteOperation<TDocument> findOneAndDelete(final Bson filter, final FindOneAndDeleteOptions options) { |
| 172 | + return operations.findOneAndDelete(filter, options); |
| 173 | + } |
| 174 | + |
| 175 | + public AsyncWriteOperation<TDocument> findOneAndReplace(final Bson filter, final TDocument replacement, |
| 176 | + final FindOneAndReplaceOptions options) { |
| 177 | + return operations.findOneAndReplace(filter, replacement, options); |
| 178 | + } |
| 179 | + |
| 180 | + public AsyncWriteOperation<TDocument> findOneAndUpdate(final Bson filter, final Bson update, final FindOneAndUpdateOptions options) { |
| 181 | + return operations.findOneAndUpdate(filter, update, options); |
| 182 | + } |
| 183 | + |
| 184 | + public AsyncWriteOperation<TDocument> findOneAndUpdate(final Bson filter, final List<? extends Bson> update, |
| 185 | + final FindOneAndUpdateOptions options) { |
| 186 | + return operations.findOneAndUpdate(filter, update, options); |
| 187 | + } |
| 188 | + |
| 189 | + public AsyncWriteOperation<BulkWriteResult> insertOne(final TDocument document, final InsertOneOptions options) { |
| 190 | + return operations.insertOne(document, options); |
| 191 | + } |
| 192 | + |
| 193 | + |
| 194 | + public AsyncWriteOperation<BulkWriteResult> replaceOne(final Bson filter, final TDocument replacement, final ReplaceOptions options) { |
| 195 | + return operations.replaceOne(filter, replacement, options); |
| 196 | + } |
| 197 | + |
| 198 | + public AsyncWriteOperation<BulkWriteResult> deleteOne(final Bson filter, final DeleteOptions options) { |
| 199 | + return operations.deleteOne(filter, options); |
| 200 | + } |
| 201 | + |
| 202 | + public AsyncWriteOperation<BulkWriteResult> deleteMany(final Bson filter, final DeleteOptions options) { |
| 203 | + return operations.deleteMany(filter, options); |
| 204 | + } |
| 205 | + |
| 206 | + public AsyncWriteOperation<BulkWriteResult> updateOne(final Bson filter, final Bson update, final UpdateOptions updateOptions) { |
| 207 | + return operations.updateOne(filter, update, updateOptions); |
| 208 | + } |
| 209 | + |
| 210 | + public AsyncWriteOperation<BulkWriteResult> updateOne(final Bson filter, final List<? extends Bson> update, |
| 211 | + final UpdateOptions updateOptions) { |
| 212 | + return operations.updateOne(filter, update, updateOptions); |
| 213 | + } |
| 214 | + |
| 215 | + public AsyncWriteOperation<BulkWriteResult> updateMany(final Bson filter, final Bson update, final UpdateOptions updateOptions) { |
| 216 | + return operations.updateMany(filter, update, updateOptions); |
| 217 | + } |
| 218 | + |
| 219 | + public AsyncWriteOperation<BulkWriteResult> updateMany(final Bson filter, final List<? extends Bson> update, |
| 220 | + final UpdateOptions updateOptions) { |
| 221 | + return operations.updateMany(filter, update, updateOptions); |
| 222 | + } |
| 223 | + |
| 224 | + public AsyncWriteOperation<BulkWriteResult> insertMany(final List<? extends TDocument> documents, |
| 225 | + final InsertManyOptions options) { |
| 226 | + return operations.insertMany(documents, options); |
| 227 | + } |
| 228 | + |
| 229 | + public AsyncWriteOperation<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends TDocument>> requests, |
| 230 | + final BulkWriteOptions options) { |
| 231 | + return operations.bulkWrite(requests, options); |
| 232 | + } |
| 233 | + |
| 234 | + |
| 235 | + public AsyncWriteOperation<Void> dropCollection(final DropCollectionOptions dropCollectionOptions, |
| 236 | + final AutoEncryptionSettings autoEncryptionSettings) { |
| 237 | + return operations.dropCollection(dropCollectionOptions, autoEncryptionSettings); |
| 238 | + } |
| 239 | + |
| 240 | + public AsyncWriteOperation<Void> renameCollection(final MongoNamespace newCollectionNamespace, |
| 241 | + final RenameCollectionOptions options) { |
| 242 | + return operations.renameCollection(newCollectionNamespace, options); |
| 243 | + } |
| 244 | + |
| 245 | + public AsyncWriteOperation<Void> createIndexes(final List<IndexModel> indexes, final CreateIndexOptions options) { |
| 246 | + return operations.createIndexes(indexes, options); |
| 247 | + } |
| 248 | + |
| 249 | + public AsyncWriteOperation<Void> dropIndex(final String indexName, final DropIndexOptions options) { |
| 250 | + return operations.dropIndex(indexName, options); |
| 251 | + } |
| 252 | + |
| 253 | + public AsyncWriteOperation<Void> dropIndex(final Bson keys, final DropIndexOptions options) { |
| 254 | + return operations.dropIndex(keys, options); |
| 255 | + } |
| 256 | + |
| 257 | + public <TResult> AsyncReadOperation<AsyncBatchCursor<TResult>> listCollections(final String databaseName, final Class<TResult> resultClass, |
| 258 | + final Bson filter, final boolean collectionNamesOnly, |
| 259 | + final Integer batchSize, final long maxTimeMS, |
| 260 | + final BsonValue comment) { |
| 261 | + return operations.listCollections(databaseName, resultClass, filter, collectionNamesOnly, batchSize, maxTimeMS, comment); |
| 262 | + } |
| 263 | + |
| 264 | + public <TResult> AsyncReadOperation<AsyncBatchCursor<TResult>> listDatabases(final Class<TResult> resultClass, final Bson filter, |
| 265 | + final Boolean nameOnly, final long maxTimeMS, |
| 266 | + final Boolean authorizedDatabases, final BsonValue comment) { |
| 267 | + return operations.listDatabases(resultClass, filter, nameOnly, maxTimeMS, authorizedDatabases, comment); |
| 268 | + } |
| 269 | + |
| 270 | + public <TResult> AsyncReadOperation<AsyncBatchCursor<TResult>> listIndexes(final Class<TResult> resultClass, final Integer batchSize, |
| 271 | + final long maxTimeMS, final BsonValue comment) { |
| 272 | + return operations.listIndexes(resultClass, batchSize, maxTimeMS, comment); |
| 273 | + } |
| 274 | +} |
0 commit comments