All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eightkdata.mongowp.mongoserver.api.commands.QueryReply Maven / Gradle / Ivy


package com.eightkdata.mongowp.mongoserver.api.commands;

import com.eightkdata.mongowp.messages.response.ReplyMessage;
import com.eightkdata.mongowp.mongoserver.callback.MessageReplier;
import java.util.EnumSet;
import javax.annotation.Nonnull;
import org.bson.BsonDocument;

/**
 *
 */
public class QueryReply implements Reply {

    private final long cursorId;
    private final int startingFrom;
    private final @Nonnull Iterable documents;
    private final @Nonnull EnumSet flags;

    private QueryReply(
            long cursorId, 
            int startingFrom, 
            Iterable documents,
            EnumSet flags) {
        this.cursorId = cursorId;
        this.startingFrom = startingFrom;
        this.documents = documents;
        this.flags = flags;
    }

    public long getCursorId() {
        return cursorId;
    }

    public int getStartingFrom() {
        return startingFrom;
    }

    public Iterable getDocuments() {
        return documents;
    }

    public EnumSet getFlags() {
        return flags;
    }
    
    @Override
    public void reply(MessageReplier replier) {
        replier.replyMessageMultipleDocuments(
                getCursorId(), 
                getStartingFrom(), 
                getDocuments()
        );
    }
    
    public static class Builder {
        private long cursorId;
        private int startingFrom;
        private Iterable documents;

        public long getCursorId() {
            return cursorId;
        }

        public Builder setCursorId(long cursorId) {
            this.cursorId = cursorId;
            return this;
        }

        public int getStartingFrom() {
            return startingFrom;
        }

        public Builder setStartingFrom(int startingFrom) {
            this.startingFrom = startingFrom;
            return this;
        }

        public Iterable getDocuments() {
            return documents;
        }

        public Builder setDocuments(Iterable documents) {
            this.documents = documents;
            return this;
        }
        
        public QueryReply build() {
            return new QueryReply(
                    cursorId, 
                    startingFrom, 
                    documents, 
                    EnumSet.noneOf(ReplyMessage.Flag.class)
            );
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy