Skip to content

Commit b1ac55c

Browse files
christophstroblmp911de
authored andcommitted
Update javadoc & switch method defaulting.
Closes #5010 Original pull request: #5015
1 parent 5d85f24 commit b1ac55c

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public DefaultIndexOperations(MongoOperations mongoOperations, String collection
116116

117117
@Override
118118
@SuppressWarnings("NullAway")
119-
public String ensureIndex(IndexDefinition indexDefinition) {
119+
public String createIndex(IndexDefinition indexDefinition) {
120120

121121
return execute(collection -> {
122122

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public DefaultReactiveIndexOperations(ReactiveMongoOperations mongoOperations, S
8484

8585
@Override
8686
@SuppressWarnings("NullAway")
87-
public Mono<String> ensureIndex(IndexDefinition indexDefinition) {
87+
public Mono<String> createIndex(IndexDefinition indexDefinition) {
8888

8989
return mongoOperations.execute(collectionName, collection -> {
9090

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ public interface IndexOperations {
3636
* @deprecated since 4.5, in favor of {@link #createIndex(IndexDefinition)}.
3737
*/
3838
@Deprecated(since = "4.5", forRemoval = true)
39-
String ensureIndex(IndexDefinition indexDefinition);
39+
default String ensureIndex(IndexDefinition indexDefinition) {
40+
return createIndex(indexDefinition);
41+
}
4042

4143
/**
42-
* Create the index for the provided {@link IndexDefinition} exists for the collection indicated by the entity class.
43-
* If not it will be created.
44+
* Create the index for the provided {@link IndexDefinition} for the collection indicated by the entity class. If the
45+
* index does not exist it will be created. Might error if the collection already defines an index with the same name
46+
* but different settings.
4447
*
4548
* @param indexDefinition must not be {@literal null}.
4649
* @return the index name.
4750
* @since 4.5
4851
*/
49-
default String createIndex(IndexDefinition indexDefinition) {
50-
return ensureIndex(indexDefinition);
51-
}
52+
String createIndex(IndexDefinition indexDefinition);
5253

5354
/**
5455
* Alters the index with given {@literal name}.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ static IndexOperationsAdapter blocking(ReactiveIndexOperations reactiveIndexOper
4141
return new IndexOperationsAdapter() {
4242

4343
@Override
44-
public String ensureIndex(IndexDefinition indexDefinition) {
45-
return reactiveIndexOperations.ensureIndex(indexDefinition).block();
44+
public String createIndex(IndexDefinition indexDefinition) {
45+
return reactiveIndexOperations.createIndex(indexDefinition).block();
4646
}
4747

4848
@Override

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ public interface ReactiveIndexOperations {
3636
* @deprecated since 4.5, in favor of {@link #createIndex(IndexDefinition)}.
3737
*/
3838
@Deprecated(since = "4.5", forRemoval = true)
39-
Mono<String> ensureIndex(IndexDefinition indexDefinition);
39+
default Mono<String> ensureIndex(IndexDefinition indexDefinition) {
40+
return createIndex(indexDefinition);
41+
}
4042

4143
/**
42-
* Create the index for the provided {@link IndexDefinition} exists for the collection indicated by the entity class.
43-
* If not it will be created.
44+
* Create the index for the provided {@link IndexDefinition} for the collection indicated by the entity class. If the
45+
* index does not exist it will be created. Might error if the collection already defines an index with the same name
46+
* but different settings.
4447
*
4548
* @param indexDefinition must not be {@literal null}.
4649
* @return the index name.
4750
* @since 4.5
4851
*/
49-
default Mono<String> createIndex(IndexDefinition indexDefinition) {
50-
return ensureIndex(indexDefinition);
51-
}
52+
Mono<String> createIndex(IndexDefinition indexDefinition);
5253

5354
/**
5455
* Alters the index with given {@literal name}.

0 commit comments

Comments
 (0)