MongoIndexManagerBase.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /* Copyright 2010-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. using MongoDB.Bson;
  21. using MongoDB.Bson.Serialization;
  22. namespace MongoDB.Driver
  23. {
  24. /// <summary>
  25. /// Base class for implementors of <see cref="IMongoIndexManager{TDocument}"/>.
  26. /// </summary>
  27. /// <typeparam name="TDocument">The type of the document.</typeparam>
  28. public abstract class MongoIndexManagerBase<TDocument> : IMongoIndexManager<TDocument>
  29. {
  30. // public properties
  31. /// <inheritdoc />
  32. public abstract CollectionNamespace CollectionNamespace { get; }
  33. /// <inheritdoc />
  34. public abstract IBsonSerializer<TDocument> DocumentSerializer { get; }
  35. /// <inheritdoc />
  36. public abstract MongoCollectionSettings Settings { get; }
  37. // public methods
  38. /// <inheritdoc />
  39. [Obsolete("Use CreateOne with a CreateIndexModel instead.")]
  40. public virtual string CreateOne(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
  41. {
  42. var model = new CreateIndexModel<TDocument>(keys, options);
  43. var result = CreateMany(new[] { model }, cancellationToken);
  44. return result.Single();
  45. }
  46. /// <inheritdoc />
  47. public virtual string CreateOne(
  48. CreateIndexModel<TDocument> model,
  49. CreateOneIndexOptions options = null,
  50. CancellationToken cancellationToken = default(CancellationToken))
  51. {
  52. var createManyIndexOptions = ToCreateManyIndexesOptions(options);
  53. var result = CreateMany(new[] { model }, createManyIndexOptions, cancellationToken);
  54. return result.Single();
  55. }
  56. /// <inheritdoc />
  57. [Obsolete("Use CreateOne with a CreateIndexModel instead.")]
  58. public virtual string CreateOne(IClientSessionHandle session, IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
  59. {
  60. var model = new CreateIndexModel<TDocument>(keys, options);
  61. var result = CreateMany(session, new[] { model }, cancellationToken);
  62. return result.Single();
  63. }
  64. /// <inheritdoc />
  65. public virtual string CreateOne(
  66. IClientSessionHandle session,
  67. CreateIndexModel<TDocument> model,
  68. CreateOneIndexOptions options = null,
  69. CancellationToken cancellationToken = default(CancellationToken))
  70. {
  71. var createManyIndexOptions = ToCreateManyIndexesOptions(options);
  72. var result = CreateMany(session, new[] { model }, createManyIndexOptions, cancellationToken);
  73. return result.Single();
  74. }
  75. /// <inheritdoc />
  76. [Obsolete("Use CreateOneAsync with a CreateIndexModel instead.")]
  77. public virtual async Task<string> CreateOneAsync(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
  78. {
  79. var model = new CreateIndexModel<TDocument>(keys, options);
  80. var result = await CreateManyAsync(new[] { model }, cancellationToken).ConfigureAwait(false);
  81. return result.Single();
  82. }
  83. /// <inheritdoc />
  84. public virtual async Task<string> CreateOneAsync(
  85. CreateIndexModel<TDocument> model,
  86. CreateOneIndexOptions options = null,
  87. CancellationToken cancellationToken = default(CancellationToken))
  88. {
  89. var createManyIndexOptions = ToCreateManyIndexesOptions(options);
  90. var result = await CreateManyAsync(new[] { model }, createManyIndexOptions, cancellationToken).ConfigureAwait(false);
  91. return result.Single();
  92. }
  93. /// <inheritdoc />
  94. [Obsolete("Use CreateOneAsync with a CreateIndexModel instead.")]
  95. public virtual async Task<string> CreateOneAsync(IClientSessionHandle session, IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
  96. {
  97. var model = new CreateIndexModel<TDocument>(keys, options);
  98. var result = await CreateManyAsync(session, new[] { model }, cancellationToken).ConfigureAwait(false);
  99. return result.Single();
  100. }
  101. /// <inheritdoc />
  102. public virtual async Task<string> CreateOneAsync(
  103. IClientSessionHandle session,
  104. CreateIndexModel<TDocument> model,
  105. CreateOneIndexOptions options = null,
  106. CancellationToken cancellationToken = default(CancellationToken))
  107. {
  108. var createManyIndexOptions = ToCreateManyIndexesOptions(options);
  109. var result = await CreateManyAsync(session, new[] { model }, createManyIndexOptions, cancellationToken).ConfigureAwait(false);
  110. return result.Single();
  111. }
  112. /// <inheritdoc />
  113. public virtual IEnumerable<string> CreateMany(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken))
  114. {
  115. throw new NotImplementedException();
  116. }
  117. /// <inheritdoc />
  118. public virtual IEnumerable<string> CreateMany(
  119. IEnumerable<CreateIndexModel<TDocument>> models,
  120. CreateManyIndexesOptions options,
  121. CancellationToken cancellationToken = default(CancellationToken))
  122. {
  123. throw new NotImplementedException();
  124. }
  125. /// <inheritdoc />
  126. public virtual IEnumerable<string> CreateMany(IClientSessionHandle session, IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken))
  127. {
  128. throw new NotImplementedException();
  129. }
  130. /// <inheritdoc />
  131. public virtual IEnumerable<string> CreateMany(IClientSessionHandle session, IEnumerable<CreateIndexModel<TDocument>> models, CreateManyIndexesOptions options,
  132. CancellationToken cancellationToken = default(CancellationToken))
  133. {
  134. throw new NotImplementedException();
  135. }
  136. /// <inheritdoc />
  137. public virtual Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken))
  138. {
  139. throw new NotImplementedException();
  140. }
  141. /// <inheritdoc />
  142. public virtual Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateIndexModel<TDocument>> models, CreateManyIndexesOptions options,
  143. CancellationToken cancellationToken = default(CancellationToken))
  144. {
  145. throw new NotImplementedException();
  146. }
  147. /// <inheritdoc />
  148. public virtual Task<IEnumerable<string>> CreateManyAsync(IClientSessionHandle session, IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken))
  149. {
  150. throw new NotImplementedException();
  151. }
  152. /// <inheritdoc />
  153. public virtual Task<IEnumerable<string>> CreateManyAsync(
  154. IClientSessionHandle session,
  155. IEnumerable<CreateIndexModel<TDocument>> models,
  156. CreateManyIndexesOptions options,
  157. CancellationToken cancellationToken = default(CancellationToken))
  158. {
  159. throw new NotImplementedException();
  160. }
  161. /// <inheritdoc />
  162. public virtual void DropAll(DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken))
  163. {
  164. throw new NotImplementedException();
  165. }
  166. /// <inheritdoc />
  167. public virtual void DropAll(CancellationToken cancellationToken = default(CancellationToken))
  168. {
  169. throw new NotImplementedException();
  170. }
  171. /// <inheritdoc />
  172. public virtual void DropAll(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken))
  173. {
  174. throw new NotImplementedException();
  175. }
  176. /// <inheritdoc />
  177. public virtual void DropAll(IClientSessionHandle session, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken))
  178. {
  179. throw new NotImplementedException();
  180. }
  181. /// <inheritdoc />
  182. public virtual Task DropAllAsync(DropIndexOptions options, CancellationToken cancellationToken)
  183. {
  184. throw new NotImplementedException();
  185. }
  186. /// <inheritdoc />
  187. public abstract Task DropAllAsync(CancellationToken cancellationToken = default(CancellationToken));
  188. /// <inheritdoc />
  189. public virtual Task DropAllAsync(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken))
  190. {
  191. throw new NotImplementedException();
  192. }
  193. /// <inheritdoc />
  194. public virtual Task DropAllAsync(IClientSessionHandle session, DropIndexOptions options, CancellationToken cancellationToken)
  195. {
  196. throw new NotImplementedException();
  197. }
  198. /// <inheritdoc />
  199. public virtual void DropOne(string name, CancellationToken cancellationToken = default(CancellationToken))
  200. {
  201. throw new NotImplementedException();
  202. }
  203. /// <inheritdoc />
  204. public virtual void DropOne(string name, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken))
  205. {
  206. throw new NotImplementedException();
  207. }
  208. /// <inheritdoc />
  209. public virtual void DropOne(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken))
  210. {
  211. throw new NotImplementedException();
  212. }
  213. /// <inheritdoc />
  214. public virtual void DropOne(IClientSessionHandle session, string name, DropIndexOptions options, CancellationToken cancellationToken)
  215. {
  216. throw new NotImplementedException();
  217. }
  218. /// <inheritdoc />
  219. public abstract Task DropOneAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
  220. /// <inheritdoc />
  221. public virtual Task DropOneAsync(string name, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken))
  222. {
  223. throw new NotImplementedException();
  224. }
  225. /// <inheritdoc />
  226. public virtual Task DropOneAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken))
  227. {
  228. throw new NotImplementedException();
  229. }
  230. /// <inheritdoc />
  231. public virtual Task DropOneAsync(IClientSessionHandle session, string name, DropIndexOptions options, CancellationToken cancellationToken)
  232. {
  233. throw new NotImplementedException();
  234. }
  235. /// <inheritdoc />
  236. public virtual IAsyncCursor<BsonDocument> List(CancellationToken cancellationToken = default(CancellationToken))
  237. {
  238. throw new NotImplementedException();
  239. }
  240. /// <inheritdoc />
  241. public virtual IAsyncCursor<BsonDocument> List( IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken))
  242. {
  243. throw new NotImplementedException();
  244. }
  245. /// <inheritdoc />
  246. public abstract Task<IAsyncCursor<BsonDocument>> ListAsync(CancellationToken cancellationToken = default(CancellationToken));
  247. /// <inheritdoc />
  248. public virtual Task<IAsyncCursor<BsonDocument>> ListAsync(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken))
  249. {
  250. throw new NotImplementedException();
  251. }
  252. private CreateManyIndexesOptions ToCreateManyIndexesOptions(CreateOneIndexOptions options)
  253. {
  254. return new CreateManyIndexesOptions { MaxTime = options?.MaxTime };
  255. }
  256. }
  257. }