/driver-sync/src/main/com/mongodb/client/internal/ListIndexesIterableImpl.java

https://github.com/mebigfatguy/mongo-java-driver · Java · 65 lines · 41 code · 9 blank · 15 comment · 0 complexity · 4dede5a574d939502d0c298379e6e54c MD5 · raw file

  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. package com.mongodb.client.internal;
  17. import com.mongodb.MongoNamespace;
  18. import com.mongodb.ReadConcern;
  19. import com.mongodb.ReadPreference;
  20. import com.mongodb.client.ListIndexesIterable;
  21. import com.mongodb.internal.operation.SyncOperations;
  22. import com.mongodb.lang.Nullable;
  23. import com.mongodb.operation.BatchCursor;
  24. import com.mongodb.operation.ReadOperation;
  25. import com.mongodb.client.ClientSession;
  26. import org.bson.BsonDocument;
  27. import org.bson.codecs.configuration.CodecRegistry;
  28. import java.util.concurrent.TimeUnit;
  29. import static com.mongodb.assertions.Assertions.notNull;
  30. import static java.util.concurrent.TimeUnit.MILLISECONDS;
  31. final class ListIndexesIterableImpl<TResult> extends MongoIterableImpl<TResult> implements ListIndexesIterable<TResult> {
  32. private final SyncOperations<BsonDocument> operations;
  33. private final Class<TResult> resultClass;
  34. private long maxTimeMS;
  35. ListIndexesIterableImpl(@Nullable final ClientSession clientSession, final MongoNamespace namespace, final Class<TResult> resultClass,
  36. final CodecRegistry codecRegistry, final ReadPreference readPreference, final OperationExecutor executor) {
  37. super(clientSession, executor, ReadConcern.DEFAULT, readPreference);
  38. this.operations = new SyncOperations<BsonDocument>(namespace, BsonDocument.class, readPreference, codecRegistry);
  39. this.resultClass = notNull("resultClass", resultClass);
  40. }
  41. @Override
  42. public ListIndexesIterable<TResult> maxTime(final long maxTime, final TimeUnit timeUnit) {
  43. notNull("timeUnit", timeUnit);
  44. this.maxTimeMS = MILLISECONDS.convert(maxTime, timeUnit);
  45. return this;
  46. }
  47. @Override
  48. public ListIndexesIterable<TResult> batchSize(final int batchSize) {
  49. super.batchSize(batchSize);
  50. return this;
  51. }
  52. @Override
  53. public ReadOperation<BatchCursor<TResult>> asReadOperation() {
  54. return operations.listIndexes(resultClass, getBatchSize(), maxTimeMS);
  55. }
  56. }