Search in sources :

Example 1 with ReplyMessage

use of com.eightkdata.mongowp.messages.response.ReplyMessage in project torodb by torodb.

the class TorodbSafeRequestProcessor method query.

@Override
public ReplyMessage query(MongodConnection connection, Request req, int requestId, QueryRequest queryRequest) throws MongoException {
    FindArgument findArg = new FindArgument.Builder().setCollection(queryRequest.getCollection()).setFilter(queryRequest.getQuery() != null ? queryRequest.getQuery() : DefaultBsonValues.EMPTY_DOC).build();
    Status<FindResult> status = execute(req, FindCommand.INSTANCE, findArg, connection);
    if (!status.isOk()) {
        throw new MongoException(status.getErrorCode(), status.getErrorMsg());
    }
    FindResult result = status.getResult();
    assert result != null;
    return new ReplyMessage(EmptyBsonContext.getInstance(), requestId, false, false, false, false, result.getCursor().getCursorId(), queryRequest.getNumberToSkip(), IterableDocumentProvider.of(Lists.newArrayList(result.getCursor().getFirstBatch())));
}
Also used : FindArgument(com.torodb.mongodb.commands.signatures.general.FindCommand.FindArgument) MongoException(com.eightkdata.mongowp.exceptions.MongoException) ReplyMessage(com.eightkdata.mongowp.messages.response.ReplyMessage) FindResult(com.torodb.mongodb.commands.signatures.general.FindCommand.FindResult)

Aggregations

MongoException (com.eightkdata.mongowp.exceptions.MongoException)1 ReplyMessage (com.eightkdata.mongowp.messages.response.ReplyMessage)1 FindArgument (com.torodb.mongodb.commands.signatures.general.FindCommand.FindArgument)1 FindResult (com.torodb.mongodb.commands.signatures.general.FindCommand.FindResult)1