use of org.bson.conversions.Bson in project storm by apache.
the class MongoMapState method multiPut.
@Override
public void multiPut(List<List<Object>> keysList, List<T> values) {
try {
for (int i = 0; i < keysList.size(); i++) {
List<Object> keys = keysList.get(i);
T value = values.get(i);
Bson filter = options.queryCreator.createFilterByKeys(keys);
Document document = options.mapper.toDocumentByKeys(keys);
document.append(options.serDocumentField, this.serializer.serialize(value));
this.mongoClient.update(filter, document, true, false);
}
} catch (Exception e) {
LOG.warn("Batch write operation failed.", e);
throw new FailedException(e);
}
}
use of org.bson.conversions.Bson in project storm by apache.
the class MongoState method batchRetrieve.
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
List<List<Values>> batchRetrieveResult = Lists.newArrayList();
try {
for (TridentTuple tuple : tridentTuples) {
Bson filter = options.queryCreator.createFilter(tuple);
Document doc = mongoClient.find(filter);
List<Values> values = options.lookupMapper.toTuple(tuple, doc);
batchRetrieveResult.add(values);
}
} catch (Exception e) {
LOG.warn("Batch get operation failed. Triggering replay.", e);
throw new FailedException(e);
}
return batchRetrieveResult;
}
use of org.bson.conversions.Bson in project storm by apache.
the class MongoLookupBolt method execute.
@Override
public void execute(Tuple tuple) {
if (TupleUtils.isTick(tuple)) {
return;
}
try {
//get query filter
Bson filter = queryCreator.createFilter(tuple);
//find document from mongodb
Document doc = mongoClient.find(filter);
//get storm values and emit
List<Values> valuesList = mapper.toTuple(tuple, doc);
for (Values values : valuesList) {
this.collector.emit(tuple, values);
}
this.collector.ack(tuple);
} catch (Exception e) {
this.collector.reportError(e);
this.collector.fail(tuple);
}
}
use of org.bson.conversions.Bson in project storm by apache.
the class MongoUpdateBolt method execute.
@Override
public void execute(Tuple tuple) {
if (TupleUtils.isTick(tuple)) {
return;
}
try {
//get document
Document doc = mapper.toDocument(tuple);
//get query filter
Bson filter = queryCreator.createFilter(tuple);
mongoClient.update(filter, doc, upsert, many);
this.collector.ack(tuple);
} catch (Exception e) {
this.collector.reportError(e);
this.collector.fail(tuple);
}
}
use of org.bson.conversions.Bson in project mongo-java-driver by mongodb.
the class MongoDatabaseImpl method createBsonDocumentList.
private List<BsonDocument> createBsonDocumentList(final List<? extends Bson> pipeline) {
notNull("pipeline", pipeline);
List<BsonDocument> bsonDocumentPipeline = new ArrayList<BsonDocument>(pipeline.size());
for (Bson obj : pipeline) {
if (obj == null) {
throw new IllegalArgumentException("pipeline can not contain a null value");
}
bsonDocumentPipeline.add(obj.toBsonDocument(BsonDocument.class, codecRegistry));
}
return bsonDocumentPipeline;
}
Aggregations