test_class.declarator: connectionFactory = new MongoConnectionFactory()
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public MongoConnectionFactory connectionFactory = new MongoConnectionFactory();
test_class.type: MongoConnectionFactory
test_class.var_name: connectionFactory
test_class.file: oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
test_class.identifier: MongoUtilsTest
test_case.body: @Test
      public void isCollectionEmpty() {
          MongoConnection c = connectionFactory.getConnection();
          assertNotNull(c);
          c.getDatabase().drop();
  
          String collectionName = Collection.NODES.toString();
          MongoStatus status = new MongoStatus(c.getMongoClient(), c.getDBName());
  
          // consider empty when collection doesn't exist
          MongoCollection<BasicDBObject> nodes = c.getDatabase()
                  .getCollection(collectionName, BasicDBObject.class);
          assertTrue(MongoUtils.isCollectionEmpty(nodes, null));
          if (status.isClientSessionSupported()) {
              try (ClientSession s = c.getMongoClient().startSession()) {
                  assertTrue(MongoUtils.isCollectionEmpty(nodes, s));
              }
          }
  
          // insert a document
          nodes.insertOne(new BasicDBObject("p", "v"));
  
          // check again
          assertFalse(MongoUtils.isCollectionEmpty(nodes, null));
          if (status.isClientSessionSupported()) {
              try (ClientSession s = c.getMongoClient().startSession()) {
                  assertFalse(MongoUtils.isCollectionEmpty(nodes, s));
              }
          }
  
          // remove any document
          nodes.deleteMany(new BasicDBObject());
  
          // must be empty again
          assertTrue(MongoUtils.isCollectionEmpty(nodes, null));
          if (status.isClientSessionSupported()) {
              try (ClientSession s = c.getMongoClient().startSession()) {
                  assertTrue(MongoUtils.isCollectionEmpty(nodes, s));
              }
          }
      }
test_case.class_method_signature: MongoUtilsTest.isCollectionEmpty()
test_case.full_signature: @Test public void isCollectionEmpty()
test_case.identifier: isCollectionEmpty
test_case.invocations: getConnection assertNotNull drop getDatabase toString getMongoClient getDBName getCollection getDatabase assertTrue isCollectionEmpty isClientSessionSupported startSession getMongoClient assertTrue isCollectionEmpty insertOne assertFalse isCollectionEmpty isClientSessionSupported startSession getMongoClient assertFalse isCollectionEmpty deleteMany assertTrue isCollectionEmpty isClientSessionSupported startSession getMongoClient assertTrue isCollectionEmpty
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void isCollectionEmpty()
focal_class.file: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
focal_class.identifier: MongoUtils
focal_class.class_method_signature: MongoUtils.createIndex(MongoCollection<?> collection,
                              String field,
                              boolean ascending,
                              boolean unique,
                              boolean sparse)
focal_class.full_signature: static void createIndex(MongoCollection<?> collection,
                              String field,
                              boolean ascending,
                              boolean unique,
                              boolean sparse)
focal_class.identifier: createIndex
focal_class.modifiers: static
focal_class.parameters: (MongoCollection<?> collection,
                              String field,
                              boolean ascending,
                              boolean unique,
                              boolean sparse)
focal_class.return: void
focal_class.signature: void createIndex(MongoCollection<?> collection,
                              String field,
                              boolean ascending,
                              boolean unique,
                              boolean sparse)
focal_class.class_method_signature: MongoUtils.createIndex(MongoCollection<?> collection,
                              String[] fields,
                              boolean[] ascending,
                              boolean unique,
                              boolean sparse)
focal_class.full_signature: static void createIndex(MongoCollection<?> collection,
                              String[] fields,
                              boolean[] ascending,
                              boolean unique,
                              boolean sparse)
focal_class.identifier: createIndex
focal_class.modifiers: static
focal_class.parameters: (MongoCollection<?> collection,
                              String[] fields,
                              boolean[] ascending,
                              boolean unique,
                              boolean sparse)
focal_class.return: void
focal_class.signature: void createIndex(MongoCollection<?> collection,
                              String[] fields,
                              boolean[] ascending,
                              boolean unique,
                              boolean sparse)
focal_class.class_method_signature: MongoUtils.createPartialIndex(MongoCollection<?> collection,
                                     String[] fields,
                                     boolean[] ascending,
                                     String filter)
focal_class.full_signature: static void createPartialIndex(MongoCollection<?> collection,
                                     String[] fields,
                                     boolean[] ascending,
                                     String filter)
focal_class.identifier: createPartialIndex
focal_class.modifiers: static
focal_class.parameters: (MongoCollection<?> collection,
                                     String[] fields,
                                     boolean[] ascending,
                                     String filter)
focal_class.return: void
focal_class.signature: void createPartialIndex(MongoCollection<?> collection,
                                     String[] fields,
                                     boolean[] ascending,
                                     String filter)
focal_class.class_method_signature: MongoUtils.hasIndex(MongoCollection<?> collection, String... fields)
focal_class.full_signature: static boolean hasIndex(MongoCollection<?> collection, String... fields)
focal_class.identifier: hasIndex
focal_class.modifiers: static
focal_class.parameters: (MongoCollection<?> collection, String... fields)
focal_class.return: boolean
focal_class.signature: boolean hasIndex(MongoCollection<?> collection, String... fields)
focal_class.class_method_signature: MongoUtils.isCollectionEmpty(@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)
focal_class.full_signature: static boolean isCollectionEmpty(@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)
focal_class.identifier: isCollectionEmpty
focal_class.modifiers: static
focal_class.parameters: (@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)
focal_class.return: boolean
focal_class.signature: boolean isCollectionEmpty(@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)
focal_class.class_method_signature: MongoUtils.getDocumentStoreExceptionTypeFor(Throwable t)
focal_class.full_signature: static Type getDocumentStoreExceptionTypeFor(Throwable t)
focal_class.identifier: getDocumentStoreExceptionTypeFor
focal_class.modifiers: static
focal_class.parameters: (Throwable t)
focal_class.return: Type
focal_class.signature: Type getDocumentStoreExceptionTypeFor(Throwable t)
focal_method.body: static boolean isCollectionEmpty(@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session) {
          MongoCollection<?> c = collection.withReadPreference(ReadPreference.primary());
          FindIterable<BasicDBObject> result;
          if (session != null) {
              result = c.find(session, BasicDBObject.class);
          } else {
              result = c.find(BasicDBObject.class);
          }
          return result.limit(1).first() == null;
      }
focal_method.class_method_signature: MongoUtils.isCollectionEmpty(@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)
focal_method.full_signature: static boolean isCollectionEmpty(@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)
focal_method.identifier: isCollectionEmpty
focal_method.invocations: withReadPreference primary find find first limit
focal_method.modifiers: static
focal_method.parameters: (@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)
focal_method.return: boolean
focal_method.signature: boolean isCollectionEmpty(@NotNull MongoCollection<?> collection,
                                       @Nullable ClientSession session)