/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexResolver.java

http://github.com/SpringSource/spring-data-mongodb · Java · 72 lines · 19 code · 8 blank · 45 comment · 0 complexity · 012eab3a236e5377a3d08765f98fe391 MD5 · raw file

  1. /*
  2. * Copyright 2014-2021 the original author or authors.
  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. * https://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 org.springframework.data.mongodb.core.index;
  17. import org.springframework.data.mapping.context.MappingContext;
  18. import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
  19. import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
  20. import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
  21. import org.springframework.data.util.ClassTypeInformation;
  22. import org.springframework.data.util.TypeInformation;
  23. import org.springframework.util.Assert;
  24. /**
  25. * {@link IndexResolver} finds those {@link IndexDefinition}s to be created for a given class.
  26. *
  27. * @author Christoph Strobl
  28. * @author Thomas Darimont
  29. * @author Mark Paluch
  30. * @since 1.5
  31. */
  32. public interface IndexResolver {
  33. /**
  34. * Creates a new {@link IndexResolver} given {@link MongoMappingContext}.
  35. *
  36. * @param mappingContext must not be {@literal null}.
  37. * @return the new {@link IndexResolver}.
  38. * @since 2.2
  39. */
  40. static IndexResolver create(
  41. MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext) {
  42. Assert.notNull(mappingContext, "MongoMappingContext must not be null!");
  43. return new MongoPersistentEntityIndexResolver(mappingContext);
  44. }
  45. /**
  46. * Find and create {@link IndexDefinition}s for properties of given {@link TypeInformation}. {@link IndexDefinition}s
  47. * are created for properties and types with {@link Indexed}, {@link CompoundIndexes} or {@link GeoSpatialIndexed}.
  48. *
  49. * @param typeInformation must not be {@literal null}.
  50. * @return Empty {@link Iterable} in case no {@link IndexDefinition} could be resolved for type.
  51. */
  52. Iterable<? extends IndexDefinition> resolveIndexFor(TypeInformation<?> typeInformation);
  53. /**
  54. * Find and create {@link IndexDefinition}s for properties of given {@link TypeInformation}. {@link IndexDefinition}s
  55. * are created for properties and types with {@link Indexed}, {@link CompoundIndexes} or {@link GeoSpatialIndexed}.
  56. *
  57. * @param entityType must not be {@literal null}.
  58. * @return Empty {@link Iterable} in case no {@link IndexDefinition} could be resolved for type.
  59. * @see 2.2
  60. */
  61. default Iterable<? extends IndexDefinition> resolveIndexFor(Class<?> entityType) {
  62. return resolveIndexFor(ClassTypeInformation.from(entityType));
  63. }
  64. }