@Override public GetMoreMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try { buffer.skipBytes(4); String fullCollectionName = stringReader.readCString(buffer, true); int numberToReturn = buffer.readInt(); long cursorId = buffer.readLong(); //TODO: improve the way database and cache are pooled return new GetMoreMessage( requestBaseMessage, getDatabase(fullCollectionName).intern(), getCollection(fullCollectionName).intern(), numberToReturn, cursorId ); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } } }
@Override @SuppressFBWarnings(value = {"RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT"}, justification = "Findbugs thinks ByteBuf#readerIndex(...) has no" + "side effect") public InsertMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try { MyBsonContext context = new MyBsonContext(buffer); int flags = buffer.readInt(); String fullCollectionName = stringReader.readCString(buffer, true); ByteBuf docBuf = buffer.slice(buffer.readerIndex(), buffer.readableBytes()); docBuf.retain(); buffer.readerIndex(buffer.writerIndex()); ByteBufIterableDocumentProvider documents = new ByteBufIterableDocumentProvider(docBuf, docReader); //TODO: improve the way database and cache are pooled return new InsertMessage( requestBaseMessage, context, getDatabase(fullCollectionName).intern(), getCollection(fullCollectionName).intern(), EnumInt32FlagsUtil.isActive(Flag.CONTINUE_ON_ERROR, flags), documents ); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } }
@Override @Nonnegative public DeleteMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try { MyBsonContext context = new MyBsonContext(buffer); buffer.skipBytes(4); String fullCollectionName = stringReader.readCString(buffer, true); int flags = buffer.readInt(); BsonDocument document = docReader.readDocument(HEAP, buffer); //TODO: improve the way database and cache are pooled String database = getDatabase(fullCollectionName).intern(); String collection = getCollection(fullCollectionName).intern(); return new DeleteMessage( requestBaseMessage, context, database, collection, document, EnumInt32FlagsUtil.isActive(Flag.SINGLE_REMOVE, flags) ); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } }
@Override public UpdateMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try { buffer.skipBytes(4); String fullCollectionName = stringReader.readCString(buffer, true); int flags = buffer.readInt(); BsonDocument selector = docReader.readDocument(HEAP, buffer); BsonDocument update = docReader.readDocument(HEAP, buffer); //TODO: improve the way database and cache are pooled return new UpdateMessage( requestBaseMessage, EmptyBsonContext.getInstance(), getDatabase(fullCollectionName).intern(), getCollection(fullCollectionName).intern(), selector, update, EnumInt32FlagsUtil.isActive(Flag.UPSERT, flags), EnumInt32FlagsUtil.isActive(Flag.MULTI_UPDATE, flags) ); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } }