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