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

com.microsoft.azure.documentdb.internal.query.QueryInfo Maven / Gradle / Ivy

package com.microsoft.azure.documentdb.internal.query;

import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;

import com.microsoft.azure.documentdb.JsonSerializable;
import com.microsoft.azure.documentdb.internal.query.aggregation.AggregateOperator;

/**
 * Used internally to encapsulates a query's information in the Azure Cosmos DB database service.
 */
public final class QueryInfo extends JsonSerializable {
    private Integer top;
    private Collection orderBy;
    private Collection aggregates;
    private Collection orderByExpressions;
    private String rewrittenQuery;

    public QueryInfo() { }

    public QueryInfo(String jsonString) {
        super(jsonString);
    }

    public QueryInfo(JSONObject jsonObject) {
        super(jsonObject);
    }

    public Integer getTop() {
        return this.top != null ? this.top : (this.top = super.getInt("top"));
    }

    public Collection getOrderBy() {
        return this.orderBy != null ? this.orderBy : (this.orderBy = super.getCollection("orderBy", SortOrder.class));
    }

    public String getRewrittenQuery() {
        return this.rewrittenQuery != null ? this.rewrittenQuery
                : (this.rewrittenQuery = super.getString("rewrittenQuery"));
    }

    public boolean hasTop() {
        return this.getTop() != null;
    }

    public boolean hasOrderBy() {
        Collection orderBy = this.getOrderBy();
        return orderBy != null && orderBy.size() > 0;
    }

    public boolean hasRewrittenQuery() {
        return !StringUtils.isEmpty(this.getRewrittenQuery());
    }

    public boolean hasAggregates() {
        Collection aggregates = this.getAggregates();
        return aggregates != null && aggregates.size() > 0;
    }

    public Collection getAggregates() {
        return this.aggregates != null
                ? this.aggregates
                : (this.aggregates = super.getCollection("aggregates", AggregateOperator.class));
    }

    public Collection getOrderByExpressions() {
        return this.orderByExpressions != null
                ? this.orderByExpressions
                : (this.orderByExpressions = super.getCollection("orderByExpressions", String.class));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy