2020import java .util .List ;
2121
2222import org .bson .Document ;
23+
2324import org .springframework .dao .DataAccessException ;
2425import org .springframework .data .mongodb .MongoDatabaseFactory ;
2526import org .springframework .data .mongodb .UncategorizedMongoDbException ;
@@ -54,7 +55,7 @@ public class DefaultIndexOperations implements IndexOperations {
5455 private final QueryMapper mapper ;
5556 private final @ Nullable Class <?> type ;
5657
57- private MongoOperations mongoOperations ;
58+ private final MongoOperations mongoOperations ;
5859
5960 /**
6061 * Creates a new {@link DefaultIndexOperations}.
@@ -114,7 +115,7 @@ public DefaultIndexOperations(MongoOperations mongoOperations, String collection
114115 this .type = type ;
115116 }
116117
117- public String ensureIndex (final IndexDefinition indexDefinition ) {
118+ public String ensureIndex (IndexDefinition indexDefinition ) {
118119
119120 return execute (collection -> {
120121
@@ -148,7 +149,8 @@ private MongoPersistentEntity<?> lookupPersistentEntity(@Nullable Class<?> entit
148149 return null ;
149150 }
150151
151- public void dropIndex (final String name ) {
152+ @ Override
153+ public void dropIndex (String name ) {
152154
153155 execute (collection -> {
154156 collection .dropIndex (name );
@@ -166,15 +168,18 @@ public void alterIndex(String name, org.springframework.data.mongodb.core.index.
166168 Document result = mongoOperations
167169 .execute (db -> db .runCommand (new Document ("collMod" , collectionName ).append ("index" , indexOptions )));
168170
169- if (NumberUtils .convertNumberToTargetClass (result .get ("ok" , (Number ) 0 ), Integer .class ) != 1 ) {
170- throw new UncategorizedMongoDbException ("Index '%s' could not be modified. Response was %s" .formatted (name , result .toJson ()), null );
171+ if (NumberUtils .convertNumberToTargetClass (result .get ("ok" , (Number ) 0 ), Integer .class ) != 1 ) {
172+ throw new UncategorizedMongoDbException (
173+ "Index '%s' could not be modified. Response was %s" .formatted (name , result .toJson ()), null );
171174 }
172175 }
173176
177+ @ Override
174178 public void dropAllIndexes () {
175179 dropIndex ("*" );
176180 }
177181
182+ @ Override
178183 public List <IndexInfo > getIndexInfo () {
179184
180185 return execute (new CollectionCallback <List <IndexInfo >>() {
@@ -223,7 +228,8 @@ private IndexOptions addPartialFilterIfPresent(IndexOptions ops, Document source
223228 mapper .getMappedSort ((Document ) sourceOptions .get (PARTIAL_FILTER_EXPRESSION_KEY ), entity ));
224229 }
225230
226- private static IndexOptions addDefaultCollationIfRequired (IndexOptions ops , MongoPersistentEntity <?> entity ) {
231+ private static IndexOptions addDefaultCollationIfRequired (IndexOptions ops ,
232+ @ Nullable MongoPersistentEntity <?> entity ) {
227233
228234 if (ops .getCollation () != null || entity == null || !entity .hasCollation ()) {
229235 return ops ;
0 commit comments