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}.
@@ -115,7 +116,7 @@ public DefaultIndexOperations(MongoOperations mongoOperations, String collection
115
116
}
116
117
117
118
@ Override
118
- public String ensureIndex (final IndexDefinition indexDefinition ) {
119
+ public String ensureIndex (IndexDefinition indexDefinition ) {
119
120
120
121
return execute (collection -> {
121
122
@@ -149,7 +150,8 @@ private MongoPersistentEntity<?> lookupPersistentEntity(@Nullable Class<?> entit
149
150
return null ;
150
151
}
151
152
152
- public void dropIndex (final String name ) {
153
+ @ Override
154
+ public void dropIndex (String name ) {
153
155
154
156
execute (collection -> {
155
157
collection .dropIndex (name );
@@ -167,15 +169,18 @@ public void alterIndex(String name, org.springframework.data.mongodb.core.index.
167
169
Document result = mongoOperations
168
170
.execute (db -> db .runCommand (new Document ("collMod" , collectionName ).append ("index" , indexOptions )));
169
171
170
- if (NumberUtils .convertNumberToTargetClass (result .get ("ok" , (Number ) 0 ), Integer .class ) != 1 ) {
171
- throw new UncategorizedMongoDbException ("Index '%s' could not be modified. Response was %s" .formatted (name , result .toJson ()), null );
172
+ if (NumberUtils .convertNumberToTargetClass (result .get ("ok" , (Number ) 0 ), Integer .class ) != 1 ) {
173
+ throw new UncategorizedMongoDbException (
174
+ "Index '%s' could not be modified. Response was %s" .formatted (name , result .toJson ()), null );
172
175
}
173
176
}
174
177
178
+ @ Override
175
179
public void dropAllIndexes () {
176
180
dropIndex ("*" );
177
181
}
178
182
183
+ @ Override
179
184
public List <IndexInfo > getIndexInfo () {
180
185
181
186
return execute (new CollectionCallback <List <IndexInfo >>() {
@@ -224,7 +229,8 @@ private IndexOptions addPartialFilterIfPresent(IndexOptions ops, Document source
224
229
mapper .getMappedSort ((Document ) sourceOptions .get (PARTIAL_FILTER_EXPRESSION_KEY ), entity ));
225
230
}
226
231
227
- private static IndexOptions addDefaultCollationIfRequired (IndexOptions ops , MongoPersistentEntity <?> entity ) {
232
+ private static IndexOptions addDefaultCollationIfRequired (IndexOptions ops ,
233
+ @ Nullable MongoPersistentEntity <?> entity ) {
228
234
229
235
if (ops .getCollation () != null || entity == null || !entity .hasCollation ()) {
230
236
return ops ;
0 commit comments