MongoIndexManagerBase.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright 2010-2015 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. public virtual string CreateOne(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
  40. {
  41. var model = new CreateIndexModel<TDocument>(keys, options);
  42. var result = CreateMany(new[] { model }, cancellationToken);
  43. return result.Single();
  44. }
  45. /// <inheritdoc />
  46. public virtual async Task<string> CreateOneAsync(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
  47. {
  48. var model = new CreateIndexModel<TDocument>(keys, options);
  49. var result = await CreateManyAsync(new[] { model }, cancellationToken).ConfigureAwait(false);
  50. return result.Single();
  51. }
  52. /// <inheritdoc />
  53. public virtual IEnumerable<string> CreateMany(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken))
  54. {
  55. throw new NotImplementedException();
  56. }
  57. /// <inheritdoc />
  58. public virtual Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken))
  59. {
  60. throw new NotImplementedException("CreateManyAsync has not been implemented.");
  61. }
  62. /// <inheritdoc />
  63. public virtual void DropAll(CancellationToken cancellationToken = default(CancellationToken))
  64. {
  65. throw new NotImplementedException();
  66. }
  67. /// <inheritdoc />
  68. public abstract Task DropAllAsync(CancellationToken cancellationToken = default(CancellationToken));
  69. /// <inheritdoc />
  70. public virtual void DropOne(string name, CancellationToken cancellationToken = default(CancellationToken))
  71. {
  72. throw new NotImplementedException();
  73. }
  74. /// <inheritdoc />
  75. public abstract Task DropOneAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
  76. /// <inheritdoc />
  77. public virtual IAsyncCursor<BsonDocument> List(CancellationToken cancellationToken = default(CancellationToken))
  78. {
  79. throw new NotImplementedException();
  80. }
  81. /// <inheritdoc />
  82. public abstract Task<IAsyncCursor<BsonDocument>> ListAsync(CancellationToken cancellationToken = default(CancellationToken));
  83. }
  84. }