From 50070dfc64c2dd19641da95a25c96c0c7eae1b66 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 9 Aug 2018 08:11:57 +0200 Subject: [PATCH] DATAMONGO-2040 - Deprecate Indexed.dropDups and CompoundIndex.dropDups. Add deprecation warning and remove options no longer in use. Original pull request: #599. --- .../mongodb/core/index/CompoundIndex.java | 2 ++ .../data/mongodb/core/index/Index.java | 4 --- .../data/mongodb/core/index/Indexed.java | 2 ++ ...ersistentEntityIndexResolverUnitTests.java | 28 ++++++++----------- src/main/asciidoc/reference/mongodb.adoc | 6 ++-- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java index c2866457e..65319adc2 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java @@ -70,7 +70,9 @@ public @interface CompoundIndex { /** * @return * @see https://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping + * @deprecated since 2.1. No longer supported by MongoDB as of server version 3.0. */ + @Deprecated boolean dropDups() default false; /** diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java index d2abadb8a..65b5bcdbb 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java @@ -43,7 +43,6 @@ public class Index implements IndexDefinition { private final Map fieldSpec = new LinkedHashMap(); private @Nullable String name; private boolean unique = false; - private boolean dropDuplicates = false; private boolean sparse = false; private boolean background = false; private long expire = -1; @@ -183,9 +182,6 @@ public class Index implements IndexDefinition { if (unique) { document.put("unique", true); } - if (dropDuplicates) { - document.put("dropDups", true); - } if (sparse) { document.put("sparse", true); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java index d8618bac8..883fa7156 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java @@ -56,7 +56,9 @@ public @interface Indexed { /** * @return * @see https://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping + * @deprecated since 2.1. No longer supported by MongoDB as of server version 3.0. */ + @Deprecated boolean dropDups() default false; /** diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java index 5443db2e0..28d9ebac2 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java @@ -123,10 +123,8 @@ public class MongoPersistentEntityIndexResolverUnitTests { WithOptionsOnIndexedProperty.class); IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); - assertThat(indexDefinition.getIndexOptions(), - equalTo( - new org.bson.Document().append("name", "indexedProperty").append("unique", true) - .append("sparse", true).append("background", true).append("expireAfterSeconds", 10L))); + assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("name", "indexedProperty") + .append("unique", true).append("sparse", true).append("background", true).append("expireAfterSeconds", 10L))); } @Test // DATAMONGO-1297 @@ -210,8 +208,8 @@ public class MongoPersistentEntityIndexResolverUnitTests { @Document("WithOptionsOnIndexedProperty") static class WithOptionsOnIndexedProperty { - @Indexed(background = true, direction = IndexDirection.DESCENDING, - dropDups = true, expireAfterSeconds = 10, sparse = true, unique = true) // + @Indexed(background = true, direction = IndexDirection.DESCENDING, dropDups = true, expireAfterSeconds = 10, + sparse = true, unique = true) // String indexedProperty; } @@ -376,8 +374,7 @@ public class MongoPersistentEntityIndexResolverUnitTests { @Document("WithOptionsOnGeoSpatialIndexProperty") static class WithOptionsOnGeoSpatialIndexProperty { - @GeoSpatialIndexed(bits = 2, max = 100, min = 1, - type = GeoSpatialIndexType.GEO_2D) // + @GeoSpatialIndexed(bits = 2, max = 100, min = 1, type = GeoSpatialIndexType.GEO_2D) // Point location; } @@ -456,8 +453,8 @@ public class MongoPersistentEntityIndexResolverUnitTests { ComountIndexWithAutogeneratedName.class); IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); - assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("unique", true) - .append("sparse", true).append("background", true))); + assertThat(indexDefinition.getIndexOptions(), + equalTo(new org.bson.Document().append("unique", true).append("sparse", true).append("background", true))); assertThat(indexDefinition.getIndexKeys(), equalTo(new org.bson.Document().append("foo", 1).append("bar", -1))); } @@ -519,16 +516,15 @@ public class MongoPersistentEntityIndexResolverUnitTests { @Document("CompoundIndexOnLevelZero") @CompoundIndexes({ @CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true, - dropDups = true, sparse = true, unique = true) }) + sparse = true, unique = true) }) static class CompoundIndexOnLevelZero {} - @CompoundIndexes({ - @CompoundIndex(name = "compound_index", background = true, dropDups = true, sparse = true, unique = true) }) + @CompoundIndexes({ @CompoundIndex(name = "compound_index", background = true, sparse = true, unique = true) }) static class CompoundIndexOnLevelZeroWithEmptyIndexDef {} @Document("CompoundIndexOnLevelZero") - @CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true, dropDups = true, - sparse = true, unique = true) + @CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true, sparse = true, + unique = true) static class SingleCompoundIndex {} static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero { @@ -537,7 +533,7 @@ public class MongoPersistentEntityIndexResolverUnitTests { @Document("ComountIndexWithAutogeneratedName") @CompoundIndexes({ @CompoundIndex(useGeneratedName = true, def = "{'foo': 1, 'bar': -1}", background = true, - dropDups = true, sparse = true, unique = true) }) + sparse = true, unique = true) }) static class ComountIndexWithAutogeneratedName { } diff --git a/src/main/asciidoc/reference/mongodb.adoc b/src/main/asciidoc/reference/mongodb.adoc index 6af4f5e44..ebcf2314f 100644 --- a/src/main/asciidoc/reference/mongodb.adoc +++ b/src/main/asciidoc/reference/mongodb.adoc @@ -2828,13 +2828,13 @@ The `IndexOperations` interface has the `getIndexInfo` method that returns a lis [source,java] ---- -template.indexOps(Person.class).ensureIndex(new Index().on("age", Order.DESCENDING).unique(Duplicates.DROP)); +template.indexOps(Person.class).ensureIndex(new Index().on("age", Order.DESCENDING).unique()); List indexInfoList = template.indexOps(Person.class).getIndexInfo(); // Contains -// [IndexInfo [fieldSpec={_id=ASCENDING}, name=_id_, unique=false, dropDuplicates=false, sparse=false], -// IndexInfo [fieldSpec={age=DESCENDING}, name=age_-1, unique=true, dropDuplicates=true, sparse=false]] +// [IndexInfo [fieldSpec={_id=ASCENDING}, name=_id_, unique=false, sparse=false], +// IndexInfo [fieldSpec={age=DESCENDING}, name=age_-1, unique=true, sparse=false]] ---- [[mongo-template.index-and-collections.collection]]