/** * Resolve the {@link IndexDefinition}s for given {@literal root} entity by traversing {@link MongoPersistentProperty} * scanning for index annotations {@link Indexed}, {@link CompoundIndex} and {@link GeospatialIndex}. The given * {@literal root} has therefore to be annotated with {@link Document}. * * @param root must not be null. * @return List of {@link IndexDefinitionHolder}. Will never be {@code null}. * @throws IllegalArgumentException in case of missing {@link Document} annotation marking root entities. */ public List<IndexDefinitionHolder> resolveIndexForEntity(final MongoPersistentEntity<?> root) { Assert.notNull(root, "Index cannot be resolved for given 'null' entity."); Document document = root.findAnnotation(Document.class); Assert.notNull(document, "Given entity is not collection root."); final List<IndexDefinitionHolder> indexInformation = new ArrayList<>(); indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions("", root.getCollection(), root)); indexInformation.addAll(potentiallyCreateTextIndexDefinition(root)); root.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> this .potentiallyAddIndexForProperty(root, property, indexInformation, new CycleGuard())); indexInformation.addAll(resolveIndexesForDbrefs("", root.getCollection(), root)); return indexInformation; }
/** * Resolve the {@link IndexDefinition}s for given {@literal root} entity by traversing {@link MongoPersistentProperty} * scanning for index annotations {@link Indexed}, {@link CompoundIndex} and {@link GeospatialIndex}. The given * {@literal root} has therefore to be annotated with {@link Document}. * * @param root must not be null. * @return List of {@link IndexDefinitionHolder}. Will never be {@code null}. * @throws IllegalArgumentException in case of missing {@link Document} annotation marking root entities. */ public List<IndexDefinitionHolder> resolveIndexForEntity(final MongoPersistentEntity<?> root) { Assert.notNull(root, "Index cannot be resolved for given 'null' entity."); Document document = root.findAnnotation(Document.class); Assert.notNull(document, "Given entity is not collection root."); final List<IndexDefinitionHolder> indexInformation = new ArrayList<>(); indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions("", root.getCollection(), root)); indexInformation.addAll(potentiallyCreateTextIndexDefinition(root)); root.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> this .potentiallyAddIndexForProperty(root, property, indexInformation, new CycleGuard())); indexInformation.addAll(resolveIndexesForDbrefs("", root.getCollection(), root)); return indexInformation; }