DATAMONGO-2040 - Deprecate Indexed.dropDups and CompoundIndex.dropDups.
Add deprecation warning and remove options no longer in use. Original pull request: #599.
This commit is contained in:
committed by
Mark Paluch
parent
029d50e526
commit
50070dfc64
@@ -70,7 +70,9 @@ public @interface CompoundIndex {
|
||||
/**
|
||||
* @return
|
||||
* @see <a href="https://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping">https://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping</a>
|
||||
* @deprecated since 2.1. No longer supported by MongoDB as of server version 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean dropDups() default false;
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,6 @@ public class Index implements IndexDefinition {
|
||||
private final Map<String, Direction> fieldSpec = new LinkedHashMap<String, Direction>();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ public @interface Indexed {
|
||||
/**
|
||||
* @return
|
||||
* @see <a href="https://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping">https://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping</a>
|
||||
* @deprecated since 2.1. No longer supported by MongoDB as of server version 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean dropDups() default false;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
@@ -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<IndexInfo> 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]]
|
||||
|
||||
Reference in New Issue
Block a user