20
20
import java .util .List ;
21
21
22
22
import org .bson .Document ;
23
+
23
24
import org .springframework .dao .DataAccessException ;
24
25
import org .springframework .data .mongodb .MongoDatabaseFactory ;
25
26
import org .springframework .data .mongodb .UncategorizedMongoDbException ;
@@ -54,7 +55,7 @@ public class DefaultIndexOperations implements IndexOperations {
54
55
private final QueryMapper mapper ;
55
56
private final @ Nullable Class <?> type ;
56
57
57
- private MongoOperations mongoOperations ;
58
+ private final MongoOperations mongoOperations ;
58
59
59
60
/**
60
61
* Creates a new {@link DefaultIndexOperations}.
@@ -114,7 +115,7 @@ public DefaultIndexOperations(MongoOperations mongoOperations, String collection
114
115
this .type = type ;
115
116
}
116
117
117
- public String ensureIndex (final IndexDefinition indexDefinition ) {
118
+ public String ensureIndex (IndexDefinition indexDefinition ) {
118
119
119
120
return execute (collection -> {
120
121
@@ -148,7 +149,8 @@ private MongoPersistentEntity<?> lookupPersistentEntity(@Nullable Class<?> entit
148
149
return null ;
149
150
}
150
151
151
- public void dropIndex (final String name ) {
152
+ @ Override
153
+ public void dropIndex (String name ) {
152
154
153
155
execute (collection -> {
154
156
collection .dropIndex (name );
@@ -166,15 +168,18 @@ public void alterIndex(String name, org.springframework.data.mongodb.core.index.
166
168
Document result = mongoOperations
167
169
.execute (db -> db .runCommand (new Document ("collMod" , collectionName ).append ("index" , indexOptions )));
168
170
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 );
171
174
}
172
175
}
173
176
177
+ @ Override
174
178
public void dropAllIndexes () {
175
179
dropIndex ("*" );
176
180
}
177
181
182
+ @ Override
178
183
public List <IndexInfo > getIndexInfo () {
179
184
180
185
return execute (new CollectionCallback <List <IndexInfo >>() {
@@ -223,7 +228,8 @@ private IndexOptions addPartialFilterIfPresent(IndexOptions ops, Document source
223
228
mapper .getMappedSort ((Document ) sourceOptions .get (PARTIAL_FILTER_EXPRESSION_KEY ), entity ));
224
229
}
225
230
226
- private static IndexOptions addDefaultCollationIfRequired (IndexOptions ops , MongoPersistentEntity <?> entity ) {
231
+ private static IndexOptions addDefaultCollationIfRequired (IndexOptions ops ,
232
+ @ Nullable MongoPersistentEntity <?> entity ) {
227
233
228
234
if (ops .getCollation () != null || entity == null || !entity .hasCollation ()) {
229
235
return ops ;
0 commit comments