From bfba47b60b0ec98be398e179643b652a74099a77 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 29 Jan 2026 09:54:30 +0100 Subject: [PATCH] hacking --- .../mongodb/core/NamespaceBulkOperations.java | 57 ++++++++++++------- ...DefaultBulkOperationsIntegrationTests.java | 56 ++++++++++++------ 2 files changed, 76 insertions(+), 37 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/NamespaceBulkOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/NamespaceBulkOperations.java index 31de09fdc..9e3072f10 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/NamespaceBulkOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/NamespaceBulkOperations.java @@ -36,6 +36,7 @@ import java.util.List; import com.mongodb.bulk.BulkWriteResult; import org.springframework.data.mongodb.core.query.CriteriaDefinition; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.UpdateDefinition; /** @@ -44,31 +45,47 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition; */ public interface NamespaceBulkOperations { - NamespacedBulkOperations inNamespace(Namespace namespace); - NamespacedBulkOperations inNamespace(Class type); + NamespaceAwareBulkIOperations inCollection(Class type); + NamespaceAwareBulkIOperations inCollection(String collection); + NamespaceBulkOperations switchDatabase(String databaseName); - interface NamespacedBulkOperations { - NamespacedBulkInsertOperations insert(); - NamespacedBulkUpdateOperations update(); - NamespacedBulkDeleteOperations delete(); - NamespacedBulkOperations inNamespace(Namespace namespace); - NamespacedBulkOperations inNamespace(Class type); + interface NamespaceAwareBulkIOperations extends BulkOperations, NamespaceBulkOperations { - BulkWriteResult execute(); - } + NamespaceAwareBulkIOperations insert(List documents); - interface NamespacedBulkInsertOperations extends NamespacedBulkOperations { - NamespacedBulkInsertOperations one(T object); - NamespacedBulkInsertOperations many(List object); + @Override + default NamespaceAwareBulkIOperations upsert(Query query, Update update) { + upsert(query, (UpdateDefinition) update); + return this; + } } - interface NamespacedBulkUpdateOperations extends NamespacedBulkOperations { - NamespacedBulkUpdateOperations one(Query query, UpdateDefinition update); - NamespacedBulkUpdateOperations one(CriteriaDefinition where, UpdateDefinition update); - } - interface NamespacedBulkDeleteOperations { - NamespacedBulkDeleteOperations delete(Query query); - } + +// NamespacedBulkOperations inNamespace(Namespace namespace); +// NamespacedBulkOperations inNamespace(Class type); +// +// interface NamespacedBulkOperations { +// NamespacedBulkInsertOperations insert(); +// NamespacedBulkUpdateOperations update(); +// NamespacedBulkDeleteOperations delete(); +// NamespacedBulkOperations inNamespace(Namespace namespace); +// NamespacedBulkOperations inNamespace(Class type); +// +// BulkWriteResult execute(); +// } +// +// interface NamespacedBulkInsertOperations extends NamespacedBulkOperations { +// NamespacedBulkInsertOperations one(T object); +// NamespacedBulkInsertOperations many(List object); +// } +// +// interface NamespacedBulkUpdateOperations extends NamespacedBulkOperations { +// NamespacedBulkUpdateOperations one(Query query, UpdateDefinition update); +// NamespacedBulkUpdateOperations one(CriteriaDefinition where, UpdateDefinition update); +// } +// interface NamespacedBulkDeleteOperations { +// NamespacedBulkDeleteOperations delete(Query query); +// } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DefaultBulkOperationsIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DefaultBulkOperationsIntegrationTests.java index 4f81156f9..f21256c8c 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DefaultBulkOperationsIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DefaultBulkOperationsIntegrationTests.java @@ -377,25 +377,47 @@ public class DefaultBulkOperationsIntegrationTests { @Test // GH-5087 void hackItOn() { - - NamespaceBulkOperations bulkOps = operations.bulkOps(BulkMode.ORDERED); bulkOps - .inNamespace(namespace("person")) - .update() - .one(Criteria.where("name").is("batman"), null) - .one(Criteria.where("name").is("joker"), null) - .insert() - .many(List.of(new Person())) - .inNamespace(namespace("log")) - .insert() - .one(new User()) - .inNamespace(Score.class) - .insert().many(List.of()) - - .execute(); - - + .inCollection(User.class) + .insert(List.of(new User())) + .upsert(Query.query(Criteria.where("name").is("batman")), new Update().set("actor", "...")) + .switchDatabase("db2") + .inCollection("sql") + .insert(List.of(new Document())); + + +// +// NamespaceBulkOperations bulkOps = operations.bulkOps(BulkMode.ORDERED); +// bulkOps +// .inNamespace(namespace("person")) +// .update() +// .one(Criteria.where("name").is("batman"), null) +// .one(Criteria.where("name").is("joker"), null) +// .insert() +// .many(List.of(new Person())) +// .inNamespace(namespace("log")) +// .insert() +// .one(new User()) +// .inNamespace(Score.class) +// .insert().many(List.of()) +// +// .execute(); + + +// NamespaceBulkOps bulkOps1 = null; +// bulkOps1.inNamespace(namespace("person")) +// .andInNamespace(namespace("log")); + + } + +// interface NamespaceBulkOps { +// NamespaceBoundBulkOps inNamespace(Namespace namespace); +// CollectionBound +// } + + interface NamespaceBoundBulkOps extends BulkOperations { + NamespaceBoundBulkOps andInNamespace(Namespace namespace); } @Test // GH-5087