use of nl.nn.adapterframework.stream.MessageOutputStreamCap in project iaf by ibissource.
the class MongoDbSender method sendMessage.
@Override
public PipeRunResult sendMessage(Message message, PipeLineSession session, IForwardTarget next) throws SenderException, TimeoutException {
message.closeOnCloseOf(session, this);
MongoAction mngaction = getAction();
try (MessageOutputStream target = mngaction == MongoAction.FINDONE || mngaction == MongoAction.FINDMANY ? MessageOutputStream.getTargetStream(this, session, next) : new MessageOutputStreamCap(this, next)) {
ParameterValueList pvl = ParameterValueList.get(getParameterList(), message, session);
MongoDatabase mongoDatabase = getDatabase(pvl);
MongoCollection<Document> mongoCollection = getCollection(mongoDatabase, pvl);
switch(mngaction) {
case INSERTONE:
renderResult(mongoCollection.insertOne(getDocument(message)), target);
break;
case INSERTMANY:
renderResult(mongoCollection.insertMany(getDocuments(message)), target);
break;
case FINDONE:
renderResult(mongoCollection.find(getFilter(pvl, message)).first(), target);
break;
case FINDMANY:
renderResult(mongoCollection.find(getFilter(pvl, message)).limit(getLimit(pvl)), target);
break;
case UPDATEONE:
renderResult(mongoCollection.updateOne(getFilter(pvl, null), getDocument(message)), target);
break;
case UPDATEMANY:
renderResult(mongoCollection.updateMany(getFilter(pvl, null), getDocument(message)), target);
break;
case DELETEONE:
renderResult(mongoCollection.deleteOne(getFilter(pvl, message)), target);
break;
case DELETEMANY:
renderResult(mongoCollection.deleteMany(getFilter(pvl, message)), target);
break;
default:
throw new SenderException("Unknown action [" + getAction() + "]");
}
return target.getPipeRunResult();
} catch (Exception e) {
throw new SenderException("Cannot execute action [" + getAction() + "]", e);
}
}
Aggregations