Browse Source

Polishing.

Add missing Override annotations. Remove superfluous final keywords.
Original Pull Request: #4699
pull/4717/head
Mark Paluch 2 years ago committed by Christoph Strobl
parent
commit
c2c3bc3c5b
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 18
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java
  2. 13
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultReactiveIndexOperations.java
  3. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultScriptOperations.java

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

@ -20,6 +20,7 @@ import java.util.Collection; @@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.List;
import org.bson.Document;
import org.springframework.dao.DataAccessException;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.UncategorizedMongoDbException;
@ -54,7 +55,7 @@ public class DefaultIndexOperations implements IndexOperations { @@ -54,7 +55,7 @@ public class DefaultIndexOperations implements IndexOperations {
private final QueryMapper mapper;
private final @Nullable Class<?> type;
private MongoOperations mongoOperations;
private final MongoOperations mongoOperations;
/**
* Creates a new {@link DefaultIndexOperations}.
@ -115,7 +116,7 @@ public class DefaultIndexOperations implements IndexOperations { @@ -115,7 +116,7 @@ public class DefaultIndexOperations implements IndexOperations {
}
@Override
public String ensureIndex(final IndexDefinition indexDefinition) {
public String ensureIndex(IndexDefinition indexDefinition) {
return execute(collection -> {
@ -149,7 +150,8 @@ public class DefaultIndexOperations implements IndexOperations { @@ -149,7 +150,8 @@ public class DefaultIndexOperations implements IndexOperations {
return null;
}
public void dropIndex(final String name) {
@Override
public void dropIndex(String name) {
execute(collection -> {
collection.dropIndex(name);
@ -167,15 +169,18 @@ public class DefaultIndexOperations implements IndexOperations { @@ -167,15 +169,18 @@ public class DefaultIndexOperations implements IndexOperations {
Document result = mongoOperations
.execute(db -> db.runCommand(new Document("collMod", collectionName).append("index", indexOptions)));
if(NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
throw new UncategorizedMongoDbException("Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
if (NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
throw new UncategorizedMongoDbException(
"Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
}
}
@Override
public void dropAllIndexes() {
dropIndex("*");
}
@Override
public List<IndexInfo> getIndexInfo() {
return execute(new CollectionCallback<List<IndexInfo>>() {
@ -224,7 +229,8 @@ public class DefaultIndexOperations implements IndexOperations { @@ -224,7 +229,8 @@ public class DefaultIndexOperations implements IndexOperations {
mapper.getMappedSort((Document) sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY), entity));
}
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops,
@Nullable MongoPersistentEntity<?> entity) {
if (ops.getCollation() != null || entity == null || !entity.hasCollation()) {
return ops;

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

@ -116,8 +116,9 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations { @@ -116,8 +116,9 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
return Flux.from(db.runCommand(new Document("collMod", collectionName).append("index", indexOptions)))
.doOnNext(result -> {
if(NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
throw new UncategorizedMongoDbException("Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
if (NumberUtils.convertNumberToTargetClass(result.get("ok", (Number) 0), Integer.class) != 1) {
throw new UncategorizedMongoDbException(
"Index '%s' could not be modified. Response was %s".formatted(name, result.toJson()), null);
}
});
}).then();
@ -134,14 +135,17 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations { @@ -134,14 +135,17 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
.orElse(null);
}
public Mono<Void> dropIndex(final String name) {
@Override
public Mono<Void> dropIndex(String name) {
return mongoOperations.execute(collectionName, collection -> collection.dropIndex(name)).then();
}
@Override
public Mono<Void> dropAllIndexes() {
return dropIndex("*");
}
@Override
public Flux<IndexInfo> getIndexInfo() {
return mongoOperations.execute(collectionName, collection -> collection.listIndexes(Document.class)) //
@ -160,7 +164,8 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations { @@ -160,7 +164,8 @@ public class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
queryMapper.getMappedObject((Document) sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY), entity));
}
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops,
@Nullable MongoPersistentEntity<?> entity) {
if (ops.getCollation() != null || entity == null || !entity.hasCollation()) {
return ops;

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

@ -85,7 +85,7 @@ class DefaultScriptOperations implements ScriptOperations { @@ -85,7 +85,7 @@ class DefaultScriptOperations implements ScriptOperations {
}
@Override
public Object execute(final ExecutableMongoScript script, final Object... args) {
public Object execute(ExecutableMongoScript script, Object... args) {
Assert.notNull(script, "Script must not be null");
@ -104,7 +104,7 @@ class DefaultScriptOperations implements ScriptOperations { @@ -104,7 +104,7 @@ class DefaultScriptOperations implements ScriptOperations {
}
@Override
public Object call(final String scriptName, final Object... args) {
public Object call(String scriptName, Object... args) {
Assert.hasText(scriptName, "ScriptName must not be null or empty");

Loading…
Cancel
Save