|
| 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.client.internal; |
| 18 | + |
| 19 | +import com.mongodb.MongoNamespace; |
| 20 | +import com.mongodb.ReadConcern; |
| 21 | +import com.mongodb.ReadPreference; |
| 22 | +import com.mongodb.WriteConcern; |
| 23 | +import com.mongodb.client.AggregateIterable; |
| 24 | +import com.mongodb.client.ChangeStreamIterable; |
| 25 | +import com.mongodb.client.ClientSession; |
| 26 | +import com.mongodb.client.DistinctIterable; |
| 27 | +import com.mongodb.client.FindIterable; |
| 28 | +import com.mongodb.client.ListCollectionsIterable; |
| 29 | +import com.mongodb.client.ListDatabasesIterable; |
| 30 | +import com.mongodb.client.ListIndexesIterable; |
| 31 | +import com.mongodb.client.MapReduceIterable; |
| 32 | +import com.mongodb.client.model.changestream.ChangeStreamLevel; |
| 33 | +import com.mongodb.lang.Nullable; |
| 34 | +import org.bson.codecs.configuration.CodecRegistry; |
| 35 | +import org.bson.conversions.Bson; |
| 36 | + |
| 37 | +import java.util.List; |
| 38 | + |
| 39 | +class FallbackMongoIterableFactory implements MongoIterableFactory { |
| 40 | + @Override |
| 41 | + public <TDocument, TResult> |
| 42 | + FindIterable<TResult> findOf(final @Nullable ClientSession clientSession, final MongoNamespace namespace, |
| 43 | + final Class<TDocument> documentClass, final Class<TResult> resultClass, final CodecRegistry codecRegistry, |
| 44 | + final ReadPreference readPreference, final ReadConcern readConcern, final OperationExecutor executor, |
| 45 | + final Bson filter) { |
| 46 | + return new FindIterableImpl<TDocument, TResult>(clientSession, namespace, documentClass, resultClass, codecRegistry, |
| 47 | + readPreference, readConcern, executor, filter); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public <TDocument, TResult> |
| 52 | + AggregateIterable<TResult> aggregateOf(final @Nullable ClientSession clientSession, final MongoNamespace namespace, |
| 53 | + final Class<TDocument> documentClass, final Class<TResult> resultClass, |
| 54 | + final CodecRegistry codecRegistry, final ReadPreference readPreference, |
| 55 | + final ReadConcern readConcern, final WriteConcern writeConcern, final OperationExecutor executor, |
| 56 | + final List<? extends Bson> pipeline) { |
| 57 | + return new AggregateIterableImpl<TDocument, TResult>(clientSession, namespace, documentClass, resultClass, codecRegistry, |
| 58 | + readPreference, readConcern, writeConcern, executor, pipeline); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public <TResult> |
| 63 | + ChangeStreamIterable<TResult> changeStreamOf(final @Nullable ClientSession clientSession, final String databaseName, |
| 64 | + final CodecRegistry codecRegistry, final ReadPreference readPreference, |
| 65 | + final ReadConcern readConcern, final OperationExecutor executor, |
| 66 | + final List<? extends Bson> pipeline, final Class<TResult> resultClass, |
| 67 | + final ChangeStreamLevel changeStreamLevel) { |
| 68 | + return new ChangeStreamIterableImpl<TResult>(clientSession, databaseName, codecRegistry, readPreference, readConcern, executor, |
| 69 | + pipeline, resultClass, changeStreamLevel); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public <TResult> |
| 74 | + ChangeStreamIterable<TResult> changeStreamOf(final @Nullable ClientSession clientSession, final MongoNamespace namespace, |
| 75 | + final CodecRegistry codecRegistry, final ReadPreference readPreference, |
| 76 | + final ReadConcern readConcern, final OperationExecutor executor, |
| 77 | + final List<? extends Bson> pipeline, final Class<TResult> resultClass, |
| 78 | + final ChangeStreamLevel changeStreamLevel) { |
| 79 | + return new ChangeStreamIterableImpl<TResult>(clientSession, namespace, codecRegistry, readPreference, readConcern, executor, |
| 80 | + pipeline, resultClass, changeStreamLevel); |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + @Override |
| 85 | + public <TDocument, TResult> |
| 86 | + DistinctIterable<TResult> distinctOf(final @Nullable ClientSession clientSession, final MongoNamespace namespace, |
| 87 | + final Class<TDocument> documentClass, final Class<TResult> resultClass, |
| 88 | + final CodecRegistry codecRegistry, final ReadPreference readPreference, |
| 89 | + final ReadConcern readConcern, final OperationExecutor executor, final String fieldName, |
| 90 | + final Bson filter) { |
| 91 | + return new DistinctIterableImpl<TDocument, TResult>(clientSession, namespace, documentClass, resultClass, codecRegistry, |
| 92 | + readPreference, readConcern, executor, fieldName, filter); |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public <TResult> |
| 97 | + ListDatabasesIterable<TResult> listDatabasesOf(final @Nullable ClientSession clientSession, final Class<TResult> resultClass, |
| 98 | + final CodecRegistry codecRegistry, final ReadPreference readPreference, |
| 99 | + final OperationExecutor executor) { |
| 100 | + return new ListDatabasesIterableImpl<TResult>(clientSession, resultClass, codecRegistry, readPreference, executor); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public <TResult> |
| 105 | + ListCollectionsIterable<TResult> listCollectionsOf(final @Nullable ClientSession clientSession, final String databaseName, |
| 106 | + final boolean collectionNamesOnly, final Class<TResult> resultClass, |
| 107 | + final CodecRegistry codecRegistry, final ReadPreference readPreference, |
| 108 | + final OperationExecutor executor) { |
| 109 | + return new ListCollectionsIterableImpl<TResult>(clientSession, databaseName, collectionNamesOnly, resultClass, codecRegistry, |
| 110 | + readPreference, executor); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public <TResult> |
| 115 | + ListIndexesIterable<TResult> listIndexesOf(final @Nullable ClientSession clientSession, final MongoNamespace namespace, |
| 116 | + final Class<TResult> resultClass, final CodecRegistry codecRegistry, |
| 117 | + final ReadPreference readPreference, final OperationExecutor executor) { |
| 118 | + return new ListIndexesIterableImpl<TResult>(clientSession, namespace, resultClass, codecRegistry, readPreference, executor); |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public <TDocument, TResult> |
| 123 | + MapReduceIterable<TResult> mapReduceOf(final @Nullable ClientSession clientSession, final MongoNamespace namespace, |
| 124 | + final Class<TDocument> documentClass, final Class<TResult> resultClass, |
| 125 | + final CodecRegistry codecRegistry, final ReadPreference readPreference, |
| 126 | + final ReadConcern readConcern, final WriteConcern writeConcern, final OperationExecutor executor, |
| 127 | + final String mapFunction, final String reduceFunction) { |
| 128 | + return new MapReduceIterableImpl<TDocument, TResult>(clientSession, namespace, documentClass, resultClass, codecRegistry, |
| 129 | + readPreference, readConcern, writeConcern, executor, mapFunction, reduceFunction); |
| 130 | + } |
| 131 | +} |
0 commit comments