DATAMONGO-1534 - Fix bulk operations missing to write type info.
We now correctly convert entities into their MongoDB representation including type information via _class property. Original pull request: #415.
This commit is contained in:
committed by
Mark Paluch
parent
dd7d25cdb3
commit
e5a41ad7f9
@@ -123,7 +123,16 @@ class DefaultBulkOperations implements BulkOperations {
|
|||||||
|
|
||||||
Assert.notNull(document, "Document must not be null!");
|
Assert.notNull(document, "Document must not be null!");
|
||||||
|
|
||||||
models.add(new InsertOneModel<Document>((Document) mongoOperations.getConverter().convertToMongoType(document)));
|
if (document instanceof Document) {
|
||||||
|
|
||||||
|
models.add(new InsertOneModel<>((Document) document));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Document sink = new Document();
|
||||||
|
mongoOperations.getConverter().write(document, sink);
|
||||||
|
|
||||||
|
models.add(new InsertOneModel<>(sink));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import com.mongodb.client.MongoCollection;
|
|||||||
*
|
*
|
||||||
* @author Tobias Trelle
|
* @author Tobias Trelle
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:infrastructure.xml")
|
@ContextConfiguration("classpath:infrastructure.xml")
|
||||||
@@ -268,6 +269,25 @@ public class DefaultBulkOperationsIntegrationTests {
|
|||||||
assertThat(result.getDeletedCount(), is(1));
|
assertThat(result.getDeletedCount(), is(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAMONGO-1534
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void insertShouldConsiderInheritance() {
|
||||||
|
|
||||||
|
SpecialDoc specialDoc = new SpecialDoc();
|
||||||
|
specialDoc.id = "id-special";
|
||||||
|
specialDoc.value = "normal-value";
|
||||||
|
specialDoc.specialValue = "special-value";
|
||||||
|
|
||||||
|
createBulkOps(BulkMode.ORDERED).insert(Arrays.asList(specialDoc)).execute();
|
||||||
|
|
||||||
|
BaseDoc doc = operations.findOne(where("_id", specialDoc.id), BaseDoc.class, COLLECTION_NAME);
|
||||||
|
|
||||||
|
assertThat(doc, notNullValue());
|
||||||
|
assertThat(doc, instanceOf(SpecialDoc.class));
|
||||||
|
}
|
||||||
|
|
||||||
private void testUpdate(BulkMode mode, boolean multi, int expectedUpdates) {
|
private void testUpdate(BulkMode mode, boolean multi, int expectedUpdates) {
|
||||||
|
|
||||||
BulkOperations bulkOps = createBulkOps(mode);
|
BulkOperations bulkOps = createBulkOps(mode);
|
||||||
|
|||||||
Reference in New Issue
Block a user