Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Add missing Override annotations. Remove superfluous final keywords.
Original Pull Request: #4699
  • Loading branch information
mp911de authored and christophstrobl committed May 16, 2024
1 parent 7f1c66e commit a819a5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -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}.
Expand Down Expand Up @@ -114,7 +115,7 @@ public DefaultIndexOperations(MongoOperations mongoOperations, String collection
this.type = type;
}

public String ensureIndex(final IndexDefinition indexDefinition) {
public String ensureIndex(IndexDefinition indexDefinition) {

return execute(collection -> {

Expand Down Expand Up @@ -148,7 +149,8 @@ private MongoPersistentEntity<?> lookupPersistentEntity(@Nullable Class<?> entit
return null;
}

public void dropIndex(final String name) {
@Override
public void dropIndex(String name) {

execute(collection -> {
collection.dropIndex(name);
Expand All @@ -166,15 +168,18 @@ public void alterIndex(String name, org.springframework.data.mongodb.core.index.
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>>() {
Expand Down Expand Up @@ -223,7 +228,8 @@ private IndexOptions addPartialFilterIfPresent(IndexOptions ops, Document source
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ public Mono<Void> alterIndex(String name, org.springframework.data.mongodb.core.

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();
Expand All @@ -133,14 +134,17 @@ private MongoPersistentEntity<?> lookupPersistentEntity(String collection) {
.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)) //
Expand All @@ -159,7 +163,8 @@ private IndexOptions addPartialFilterIfPresent(IndexOptions ops, Document source
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public NamedMongoScript register(NamedMongoScript script) {
}

@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");

Expand All @@ -104,7 +104,7 @@ public Object doInDB(MongoDatabase db) throws MongoException, DataAccessExceptio
}

@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");

Expand Down

0 comments on commit a819a5e

Please sign in to comment.