DATAMONGO-1569 - Polishing.

Update Javadoc and avoid unrelated index creation during tests due to class path scanning.

Original Pull Request: #738
This commit is contained in:
Christoph Strobl
2020-06-18 15:06:04 +02:00
parent 94a64a156f
commit 613d085bb7
3 changed files with 98 additions and 97 deletions

View File

@@ -96,7 +96,8 @@ public @interface CompoundIndex {
boolean unique() default false;
/**
* If set to true index will skip over any document that is missing the indexed field.
* If set to true index will skip over any document that is missing the indexed field. <br />
* Must not be used with {@link #partialFilter()}.
*
* @return {@literal false} by default.
* @see <a href=
@@ -171,13 +172,14 @@ public @interface CompoundIndex {
*/
boolean background() default false;
/**
* Only index the documents in a collection that meet a specified {@link IndexFilter filter expression}.
* Only index the documents in a collection that meet a specified {@link IndexFilter filter expression}. <br />
* Must not be used with {@link #sparse() sparse = true}.
*
* @return
* @return empty by default.
* @see <a href=
* "https://docs.mongodb.com/manual/core/index-partial/">https://docs.mongodb.com/manual/core/index-partial/</a>
* @since 3.1
*/
String partial() default "";
String partialFilter() default "";
}

View File

@@ -382,8 +382,8 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
indexDefinition.background();
}
if (StringUtils.hasText(index.partial())) {
indexDefinition.partial(PartialIndexFilter.of(org.bson.Document.parse(index.partial())));
if (StringUtils.hasText(index.partialFilter())) {
indexDefinition.partial(evaluatePartialFilter(index.partialFilter(), entity));
}
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);

View File

@@ -282,22 +282,22 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document("Zero")
static class IndexOnLevelZero {
class IndexOnLevelZero {
@Indexed String indexedProperty;
}
@Document("One")
static class IndexOnLevelOne {
class IndexOnLevelOne {
IndexOnLevelZero zero;
}
@Document("Two")
static class IndexOnLevelTwo {
class IndexOnLevelTwo {
IndexOnLevelOne one;
}
@Document("WithOptionsOnIndexedProperty")
static class WithOptionsOnIndexedProperty {
class WithOptionsOnIndexedProperty {
@Indexed(background = true, direction = IndexDirection.DESCENDING, dropDups = true, expireAfterSeconds = 10,
sparse = true, unique = true) //
@@ -305,23 +305,23 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class IndexOnLevelOneWithExplicitlyNamedField {
class IndexOnLevelOneWithExplicitlyNamedField {
@Field("customZero") IndexOnLevelZeroWithExplicityNamedField zero;
}
static class IndexOnLevelZeroWithExplicityNamedField {
class IndexOnLevelZeroWithExplicityNamedField {
@Indexed @Field("customFieldName") String namedProperty;
}
@Document
static class WrapperOfWithDbRef {
class WrapperOfWithDbRef {
WithDbRef nested;
}
@Document
static class WithDbRef {
class WithDbRef {
@Indexed //
@DBRef //
@@ -329,12 +329,12 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document("no-index")
static class NoIndex {
class NoIndex {
@Id String id;
}
@Document
static class IndexedDocumentWithComposedAnnotations {
class IndexedDocumentWithComposedAnnotations {
@Id String id;
@CustomIndexedAnnotation String fieldWithDifferentIndexName;
@@ -372,7 +372,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class WithExpireAfterAsPlainString {
class WithExpireAfterAsPlainString {
@Indexed(expireAfter = "10m") String withTimeout;
}
@@ -382,12 +382,12 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class WithExpireAfterAsExpression {
class WithExpireAfterAsExpression {
@Indexed(expireAfter = "#{10 + 1 + 's'}") String withTimeout;
}
@Document
static class WithExpireAfterAsExpressionResultingInDuration {
class WithExpireAfterAsExpressionResultingInDuration {
@Indexed(expireAfter = "#{T(java.time.Duration).ofSeconds(100)}") String withTimeout;
}
@@ -402,7 +402,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class WithIndexNameAsExpression {
class WithIndexNameAsExpression {
@Indexed(name = "#{'my' + 1 + 'st'}") String spelIndexName;
}
@@ -419,7 +419,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class IndexOnMetaAnnotatedField {
class IndexOnMetaAnnotatedField {
@Field("_name") @IndexedFieldAnnotation String lastname;
}
@@ -496,29 +496,29 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document("Zero")
static class GeoSpatialIndexOnLevelZero {
class GeoSpatialIndexOnLevelZero {
@GeoSpatialIndexed Point geoIndexedProperty;
}
@Document("One")
static class GeoSpatialIndexOnLevelOne {
class GeoSpatialIndexOnLevelOne {
GeoSpatialIndexOnLevelZero zero;
}
@Document("Two")
static class GeoSpatialIndexOnLevelTwo {
class GeoSpatialIndexOnLevelTwo {
GeoSpatialIndexOnLevelOne one;
}
@Document("WithOptionsOnGeoSpatialIndexProperty")
static class WithOptionsOnGeoSpatialIndexProperty {
class WithOptionsOnGeoSpatialIndexProperty {
@GeoSpatialIndexed(bits = 2, max = 100, min = 1, type = GeoSpatialIndexType.GEO_2D) //
Point location;
}
@Document("WithComposedAnnotation")
static class GeoSpatialIndexedDocumentWithComposedAnnotation {
class GeoSpatialIndexedDocumentWithComposedAnnotation {
@ComposedGeoSpatialIndexed //
Point location;
@@ -543,7 +543,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class GeoIndexWithNameAsExpression {
class GeoIndexWithNameAsExpression {
@GeoSpatialIndexed(name = "#{'my' + 1 + 'st'}") Point spelIndexName;
}
@@ -690,18 +690,17 @@ public class MongoPersistentEntityIndexResolverUnitTests {
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "compound_index_with_partial")
.containsEntry("unique", true).containsEntry("background", true);
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("partialFilterExpression",
new org.bson.Document().append("bar", new org.bson.Document().append("$exists", true)));
org.bson.Document.parse("{'value': {'$exists': true}}"));
}
@Document("CompoundIndexOnLevelOne")
static class CompoundIndexOnLevelOne {
class CompoundIndexOnLevelOne {
CompoundIndexOnLevelZero zero;
}
@Document("CompoundIndexOnLevelZeroWithEmptyIndexDef")
static class CompoundIndexOnLevelOneWithEmptyIndexDefinition {
class CompoundIndexOnLevelOneWithEmptyIndexDefinition {
CompoundIndexOnLevelZeroWithEmptyIndexDef zero;
}
@@ -709,26 +708,26 @@ public class MongoPersistentEntityIndexResolverUnitTests {
@Document("CompoundIndexOnLevelZero")
@CompoundIndexes({ @CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true,
sparse = true, unique = true) })
static class CompoundIndexOnLevelZero {}
class CompoundIndexOnLevelZero {}
@CompoundIndexes({ @CompoundIndex(name = "compound_index", background = true, sparse = true, unique = true) })
static class CompoundIndexOnLevelZeroWithEmptyIndexDef {}
class CompoundIndexOnLevelZeroWithEmptyIndexDef {}
@Document("CompoundIndexOnLevelZero")
@CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true, sparse = true,
unique = true)
static class SingleCompoundIndex {}
class SingleCompoundIndex {}
static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {}
class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {}
@Document("ComountIndexWithAutogeneratedName")
@CompoundIndexes({ @CompoundIndex(useGeneratedName = true, def = "{'foo': 1, 'bar': -1}", background = true,
sparse = true, unique = true) })
static class ComountIndexWithAutogeneratedName {}
class ComountIndexWithAutogeneratedName {}
@Document("WithComposedAnnotation")
@ComposedCompoundIndex
static class CompoundIndexDocumentWithComposedAnnotation {}
class CompoundIndexDocumentWithComposedAnnotation {}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@@ -754,21 +753,21 @@ public class MongoPersistentEntityIndexResolverUnitTests {
@Document
@CompoundIndex(name = "#{'cmp' + 2 + 'name'}", def = "{'foo': 1, 'bar': -1}")
static class CompoundIndexWithNameExpression {}
class CompoundIndexWithNameExpression {}
@Document
@CompoundIndex(def = "#{T(org.bson.Document).parse(\"{ 'foo': 1, 'bar': -1 }\")}")
static class CompoundIndexWithDefExpression {}
class CompoundIndexWithDefExpression {}
@Document
@CompoundIndex(name = "cmp-idx-one", def = "{'firstname': 1, 'lastname': -1}")
@CompoundIndex(name = "cmp-idx-two", def = "{'address.city': -1, 'address.street': 1}")
static class RepeatedCompoundIndex {}
class RepeatedCompoundIndex {}
@Document("SingleCompoundIndexWithPartialFilter")
@CompoundIndex(name = "compound_index_with_partial", def = "{'foo': 1, 'bar': -1}", background = true,
unique = true, partial = "{'bar': {$exists: true}}")
static class SingleCompoundIndexWithPartialFilter {}
unique = true, partialFilter = "{'value': {'$exists': true}}")
class SingleCompoundIndexWithPartialFilter {}
}
public static class TextIndexedResolutionTests {
@@ -904,7 +903,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class TextIndexOnSinglePropertyInRoot {
class TextIndexOnSinglePropertyInRoot {
String foo;
@@ -912,13 +911,13 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document(collation = "de_AT")
static class TextIndexWithCollation {
class TextIndexWithCollation {
@TextIndexed String foo;
}
@Document
static class TextIndexOnMultiplePropertiesInRoot {
class TextIndexOnMultiplePropertiesInRoot {
@TextIndexed String foo;
@@ -926,48 +925,48 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class TextIndexOnNestedRoot {
class TextIndexOnNestedRoot {
String bar;
@TextIndexed TextIndexOnNested nested;
}
static class TextIndexOnNested {
class TextIndexOnNested {
String foo;
}
@Document
static class TextIndexOnNestedWithWeightRoot {
class TextIndexOnNestedWithWeightRoot {
@TextIndexed(weight = 5) TextIndexOnNested nested;
}
@Document
static class TextIndexOnNestedWithMostSpecificValueRoot {
class TextIndexOnNestedWithMostSpecificValueRoot {
@TextIndexed(weight = 5) TextIndexOnNestedWithMostSpecificValue nested;
}
static class TextIndexOnNestedWithMostSpecificValue {
class TextIndexOnNestedWithMostSpecificValue {
String foo;
@TextIndexed(weight = 10) String bar;
}
@Document(language = "spanish")
static class DocumentWithDefaultLanguage {
class DocumentWithDefaultLanguage {
@TextIndexed String foo;
}
@Document
static class DocumentWithLanguageOverrideOnNestedElement {
class DocumentWithLanguageOverrideOnNestedElement {
DocumentWithLanguageOverride nested;
}
@Document
static class DocumentWithLanguageOverride {
class DocumentWithLanguageOverride {
@TextIndexed String foo;
@@ -975,19 +974,19 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class DocumentWithNoTextIndexPropertyButReservedFieldLanguage {
class DocumentWithNoTextIndexPropertyButReservedFieldLanguage {
String language;
}
@Document
static class DocumentWithNoTextIndexPropertyButReservedFieldLanguageAnnotated {
class DocumentWithNoTextIndexPropertyButReservedFieldLanguageAnnotated {
@Field("language") String lang;
}
@Document
static class DocumentWithOverlappingLanguageProps {
class DocumentWithOverlappingLanguageProps {
@TextIndexed String foo;
String language;
@@ -995,7 +994,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class TextIndexedDocumentWithComposedAnnotation {
class TextIndexedDocumentWithComposedAnnotation {
@ComposedTextIndexedAnnotation String foo;
String lang;
@@ -1284,104 +1283,104 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class MixedIndexRoot {
class MixedIndexRoot {
@Indexed String first;
NestedGeoIndex nestedGeo;
}
static class NestedGeoIndex {
class NestedGeoIndex {
@GeoSpatialIndexed Point location;
}
@Document
static class Outer {
class Outer {
@DBRef Inner inner;
}
@Document
static class Inner {
class Inner {
@Indexed Outer outer;
}
@Document
static class CycleLevelZero {
class CycleLevelZero {
@Indexed String indexedProperty;
CycleLevelZero cyclicReference;
}
@Document
static class CycleOnLevelOne {
class CycleOnLevelOne {
CycleOnLevelOneReferenced reference;
}
static class CycleOnLevelOneReferenced {
class CycleOnLevelOneReferenced {
@Indexed String indexedProperty;
CycleOnLevelOne cyclicReference;
}
@Document
public static class CycleStartingInBetween {
static class CycleStartingInBetween {
CycleOnLevelOne referenceToCycleStart;
}
@Document
static class NoCycleButIdenticallyNamedProperties {
class NoCycleButIdenticallyNamedProperties {
@Indexed String foo;
NoCycleButIdenticallyNamedPropertiesNested reference;
}
static class NoCycleButIdenticallyNamedPropertiesNested {
class NoCycleButIdenticallyNamedPropertiesNested {
@Indexed String foo;
NoCycleButIndenticallNamedPropertiesDeeplyNested deep;
}
static class NoCycleButIndenticallNamedPropertiesDeeplyNested {
class NoCycleButIndenticallNamedPropertiesDeeplyNested {
@Indexed String foo;
}
@Document("rules")
static class NoCycleManyPathsToDeepValueObject {
class NoCycleManyPathsToDeepValueObject {
private NoCycleLevel3 l3;
private NoCycleLevel2 l2;
}
static class NoCycleLevel2 {
class NoCycleLevel2 {
private NoCycleLevel3 l3;
}
static class NoCycleLevel3 {
class NoCycleLevel3 {
private ValueObject valueObject;
}
static class ValueObject {
class ValueObject {
@Indexed private String value;
}
@Document
static class SimilarityHolingBean {
class SimilarityHolingBean {
@Indexed @Field("norm") String normalProperty;
@Field("similarityL") private List<SimilaritySibling> listOfSimilarilyNamedEntities = null;
}
static class SimilaritySibling {
class SimilaritySibling {
@Field("similarity") private String similarThoughNotEqualNamedProperty;
}
@Document
static class MultipleObjectsOfSameType {
class MultipleObjectsOfSameType {
SelfCyclingViaCollectionType cycleOne;
@@ -1389,7 +1388,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class SelfCyclingViaCollectionType {
class SelfCyclingViaCollectionType {
List<SelfCyclingViaCollectionType> cyclic;
@@ -1397,55 +1396,55 @@ public class MongoPersistentEntityIndexResolverUnitTests {
@Document
@CompoundIndex(name = "c_index", def = "{ foo:1, bar:1 }")
static class DocumentWithNamedCompoundIndex {
class DocumentWithNamedCompoundIndex {
String property;
}
@Document
static class DocumentWithNamedIndex {
class DocumentWithNamedIndex {
@Indexed(name = "property_index") String property;
}
static class TypeWithNamedIndex {
class TypeWithNamedIndex {
@Indexed(name = "property_index") String property;
}
@Document
static class DocumentWithNestedDocumentHavingNamedCompoundIndex {
class DocumentWithNestedDocumentHavingNamedCompoundIndex {
DocumentWithNamedCompoundIndex propertyOfTypeHavingNamedCompoundIndex;
}
@CompoundIndex(name = "c_index", def = "{ foo:1, bar:1 }")
static class TypeWithNamedCompoundIndex {
class TypeWithNamedCompoundIndex {
String property;
}
@Document
static class DocumentWithNestedTypeHavingNamedCompoundIndex {
class DocumentWithNestedTypeHavingNamedCompoundIndex {
TypeWithNamedCompoundIndex propertyOfTypeHavingNamedCompoundIndex;
}
@Document
static class DocumentWithNestedDocumentHavingNamedIndex {
class DocumentWithNestedDocumentHavingNamedIndex {
DocumentWithNamedIndex propertyOfTypeHavingNamedIndex;
}
@Document
static class DocumentWithNestedTypeHavingNamedIndex {
class DocumentWithNestedTypeHavingNamedIndex {
TypeWithNamedIndex propertyOfTypeHavingNamedIndex;
}
@Document
public class MultiplePropertiesOfSameTypeWithMatchingStartLetters {
class MultiplePropertiesOfSameTypeWithMatchingStartLetters {
public class NameComponent {
class NameComponent {
@Indexed String component;
}
@@ -1455,9 +1454,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
public class MultiplePropertiesOfSameTypeWithMatchingStartLettersOnNestedProperty {
class MultiplePropertiesOfSameTypeWithMatchingStartLettersOnNestedProperty {
public class NameComponent {
class NameComponent {
@Indexed String nameLast;
@Indexed String name;
@@ -1467,39 +1466,39 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
public static class OuterDocumentReferingToIndexedPropertyViaDifferentNonCyclingPaths {
static class OuterDocumentReferingToIndexedPropertyViaDifferentNonCyclingPaths {
NoCycleButIndenticallNamedPropertiesDeeplyNested path1;
AlternatePathToNoCycleButIndenticallNamedPropertiesDeeplyNestedDocument path2;
}
public static class AlternatePathToNoCycleButIndenticallNamedPropertiesDeeplyNestedDocument {
static class AlternatePathToNoCycleButIndenticallNamedPropertiesDeeplyNestedDocument {
NoCycleButIndenticallNamedPropertiesDeeplyNested propertyWithIndexedStructure;
}
static class GenericEntityWrapper<T> {
class GenericEntityWrapper<T> {
T entity;
}
@Document
static class EntityWithGenericTypeWrapperAsElement {
class EntityWithGenericTypeWrapperAsElement {
List<GenericEntityWrapper<DocumentWithNamedIndex>> listWithGeneircTypeElement;
}
@Document
static class WithHashedIndexOnId {
class WithHashedIndexOnId {
@HashIndexed @Id String id;
}
@Document
static class WithHashedIndex {
class WithHashedIndex {
@HashIndexed String value;
}
@Document
static class WithHashedIndexAndIndex {
class WithHashedIndexAndIndex {
@Indexed //
@HashIndexed //
@@ -1507,7 +1506,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
}
@Document
static class WithComposedHashedIndexAndIndex {
class WithComposedHashedIndexAndIndex {
@ComposedHashIndexed(name = "idx-name") String value;
}