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

com.eightkdata.mongowp.server.api.deprecated.commands.QueryReply Maven / Gradle / Ivy

There is a newer version: 0.50.0
Show newest version

package com.eightkdata.mongowp.server.api.deprecated.commands;

import com.eightkdata.mongowp.bson.BsonDocument;
import com.eightkdata.mongowp.messages.request.BsonContext;
import com.eightkdata.mongowp.messages.response.ReplyMessage;
import com.eightkdata.mongowp.messages.utils.IterableDocumentProvider;
import com.eightkdata.mongowp.server.callback.MessageReplier;
import javax.annotation.Nonnull;

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

    private final BsonContext dataContext;
    private final long cursorId;
    private final int startingFrom;
    private final @Nonnull Iterable documents;
    private final boolean cursorNotFound;
    private final boolean queryFailure;
    private final boolean shardConfigStale;
    private final boolean awaitCapable;

    public QueryReply(
            BsonContext dataContext,
            long cursorId,
            int startingFrom,
            Iterable documents,
            boolean cursorNotFound,
            boolean queryFailure,
            boolean shardConfigStale,
            boolean awaitCapable) {
        this.dataContext = dataContext;
        this.cursorId = cursorId;
        this.startingFrom = startingFrom;
        this.documents = documents;
        this.cursorNotFound = cursorNotFound;
        this.queryFailure = queryFailure;
        this.shardConfigStale = shardConfigStale;
        this.awaitCapable = awaitCapable;
    }

    public long getCursorId() {
        return cursorId;
    }

    public int getStartingFrom() {
        return startingFrom;
    }

    public Iterable getDocuments() {
        return documents;
    }

    public boolean isCursorNotFound() {
        return cursorNotFound;
    }

    public boolean isQueryFailure() {
        return queryFailure;
    }

    public boolean isShardConfigStale() {
        return shardConfigStale;
    }

    public boolean isAwaitCapable() {
        return awaitCapable;
    }

    @Override
    public void reply(MessageReplier replier) {
        replier.replyMessage(new ReplyMessage(
                        dataContext,
                        startingFrom,
                        cursorNotFound,
                        queryFailure,
                        shardConfigStale,
                        awaitCapable,
                        cursorId,
                        startingFrom,
                        IterableDocumentProvider.of(documents)
                )
        );
    }
    
    public static class Builder {
        private final BsonContext dataContext;
        private long cursorId;
        private int startingFrom;
        private Iterable documents;

        public Builder(BsonContext dataContext) {
            this.dataContext = dataContext;
        }

        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(
                    dataContext,
                    cursorId, 
                    startingFrom, 
                    documents, 
                    false,
                    false,
                    false,
                    false
            );
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy