use of org.immutables.criteria.backend.WriteResult in project immutables by immutables.
the class MongoSession method update.
/**
* Uses <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> operation
* with <a href="https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/">bulkWrite</a>. Right now has to convert
* object to BsonDocument to extract {@code _id} attribute.
*/
private <T> Publisher<WriteResult> update(StandardOperations.Update operation) {
ReplaceOptions options = new ReplaceOptions();
if (operation.upsert()) {
options.upsert(operation.upsert());
}
List<ReplaceOneModel<Object>> docs = operation.values().stream().map(value -> new ReplaceOneModel<>(new BsonDocument(Mongos.ID_FIELD_NAME, toBsonValue(keyExtractor.extract(value))), value, options)).collect(Collectors.toList());
Publisher<BulkWriteResult> publisher = ((MongoCollection<Object>) collection).bulkWrite(docs);
return Flowable.fromPublisher(publisher).map(x -> WriteResult.unknown());
}
use of org.immutables.criteria.backend.WriteResult in project immutables by immutables.
the class ScrollingTest method elasticseachInit.
@BeforeEach
void elasticseachInit() throws IOException {
Map<String, String> model = ImmutableMap.<String, String>builder().put("string", "keyword").put("optionalString", "keyword").put("bool", "boolean").put("intNumber", "integer").build();
new IndexOps(restClient, MAPPER, "test").create(model).blockingAwait();
ElasticsearchBackend backend = backend();
ElasticsearchOps ops = new ElasticsearchOps(restClient, "test", MAPPER, 1024);
for (int i = 0; i < SIZE; i++) {
ObjectNode doc = MAPPER.createObjectNode().put("string", "s" + i).put("bool", true).put("intNumber", i);
WriteResult result = ops.insertDocument(doc).blockingGet();
}
}
Aggregations