Skip to content

Commit 4eaef30

Browse files
christophstroblodrotbohm
authored andcommitted
DATAMONGO-1025 - Fix creation of nested named index.
Deprecated collection attribute for @indexed, @CompoundIndex, @GeoSpatialIndexed. Removed deprecated attribute `expireAfterSeconds` from @CompoundIndex. Original pull request: #219.
1 parent ec1a6b5 commit 4eaef30

File tree

5 files changed

+15
-48
lines changed

5 files changed

+15
-48
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@
129129
* stored in.
130130
*
131131
* @return
132+
* @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might
133+
* result in broken definitions. Will be removed in 1.7.
132134
*/
135+
@Deprecated
133136
String collection() default "";
134137

135138
/**
@@ -140,14 +143,4 @@
140143
*/
141144
boolean background() default false;
142145

143-
/**
144-
* Configures the number of seconds after which the collection should expire. Defaults to -1 for no expiry.
145-
*
146-
* @deprecated TTL cannot be defined for {@link CompoundIndex} having more than one field as key. Will be removed in
147-
* 1.6.
148-
* @see http://docs.mongodb.org/manual/tutorial/expire-data/
149-
* @return
150-
*/
151-
@Deprecated
152-
int expireAfterSeconds() default -1;
153146
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@
8585
* Name of the collection in which to create the index.
8686
*
8787
* @return
88+
* @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might
89+
* result in broken definitions. Will be removed in 1.7.
8890
*/
91+
@Deprecated
8992
String collection() default "";
9093

9194
/**

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@
108108
boolean useGeneratedName() default false;
109109

110110
/**
111-
* Colleciton name for index to be created on.
111+
* Collection name for index to be created on.
112112
*
113113
* @return
114+
* @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might
115+
* result in broken definitions. Will be removed in 1.7.
114116
*/
117+
@Deprecated
115118
String collection() default "";
116119

117120
/**

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,6 @@ protected IndexDefinitionHolder createCompoundIndexDefinition(String dotPath, St
320320
indexDefinition.background();
321321
}
322322

323-
int ttl = index.expireAfterSeconds();
324-
325-
if (ttl >= 0) {
326-
if (indexDefinition.getIndexKeys().keySet().size() > 1) {
327-
LOGGER.warn("TTL is not supported for compound index with more than one key. TTL={} will be ignored.", ttl);
328-
} else {
329-
indexDefinition.expire(ttl, TimeUnit.SECONDS);
330-
}
331-
}
332-
333323
String collection = StringUtils.hasText(index.collection()) ? index.collection() : fallbackCollection;
334324
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);
335325
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -374,22 +374,6 @@ public void singleCompoundIndexPathOnLevelZeroIsResolvedCorrectly() {
374374
assertIndexPathAndCollection(new String[] { "foo", "bar" }, "CompoundIndexOnLevelZero", indexDefinitions.get(0));
375375
}
376376

377-
/**
378-
* @see DATAMONGO-963
379-
*/
380-
@Test
381-
public void compoundIndexShouldIncludeTTLWhenConsistingOfOnlyOneKey() {
382-
383-
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(CompoundIndexWithOnlyOneKeyAndTTL.class);
384-
385-
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
386-
assertThat(
387-
indexDefinition.getIndexOptions(),
388-
equalTo(new BasicDBObjectBuilder().add("unique", true).add("dropDups", true).add("sparse", true)
389-
.add("background", true).add("expireAfterSeconds", 10L).get()));
390-
assertThat(indexDefinition.getIndexKeys(), equalTo(new BasicDBObjectBuilder().add("foo", 1).get()));
391-
}
392-
393377
@Document(collection = "CompoundIndexOnLevelOne")
394378
static class CompoundIndexOnLevelOne {
395379

@@ -404,16 +388,16 @@ static class CompoundIndexOnLevelOneWithEmptyIndexDefinition {
404388

405389
@Document(collection = "CompoundIndexOnLevelZero")
406390
@CompoundIndexes({ @CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true,
407-
dropDups = true, expireAfterSeconds = 10, sparse = true, unique = true) })
391+
dropDups = true, sparse = true, unique = true) })
408392
static class CompoundIndexOnLevelZero {}
409393

410-
@CompoundIndexes({ @CompoundIndex(name = "compound_index", background = true, dropDups = true,
411-
expireAfterSeconds = 10, sparse = true, unique = true) })
394+
@CompoundIndexes({ @CompoundIndex(name = "compound_index", background = true, dropDups = true, sparse = true,
395+
unique = true) })
412396
static class CompoundIndexOnLevelZeroWithEmptyIndexDef {}
413397

414398
@Document(collection = "CompoundIndexOnLevelZero")
415399
@CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true, dropDups = true,
416-
expireAfterSeconds = 10, sparse = true, unique = true)
400+
sparse = true, unique = true)
417401
static class SingleCompoundIndex {}
418402

419403
static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {
@@ -422,17 +406,11 @@ static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {
422406

423407
@Document(collection = "ComountIndexWithAutogeneratedName")
424408
@CompoundIndexes({ @CompoundIndex(useGeneratedName = true, def = "{'foo': 1, 'bar': -1}", background = true,
425-
dropDups = true, expireAfterSeconds = 10, sparse = true, unique = true) })
409+
dropDups = true, sparse = true, unique = true) })
426410
static class ComountIndexWithAutogeneratedName {
427411

428412
}
429413

430-
@Document(collection = "CompoundIndexWithOnlyOneKeyAndTTL")
431-
@CompoundIndex(def = "{'foo': 1}", background = true, dropDups = true, expireAfterSeconds = 10, sparse = true,
432-
unique = true)
433-
static class CompoundIndexWithOnlyOneKeyAndTTL {
434-
435-
}
436414
}
437415

438416
public static class TextIndexedResolutionTests {

0 commit comments

Comments
 (0)