Class Query

  • All Implemented Interfaces:
    Queryable, BsonParcelable

    public class Query
    extends EvaluatorCollection
    implements Queryable
    This class contains all the parameter needed to create a query. This kind of queries works over any data collection.
    Author:
    javaito
    • Field Detail

      • QUERY_BSON_FIELD_NAME

        public static final java.lang.String QUERY_BSON_FIELD_NAME
        See Also:
        Constant Field Values
    • Method Detail

      • returnAll

        public final boolean returnAll()
        Verify if the query indicates return all the fields of the result set.
        Returns:
        Return all.
      • getParameterizedQuery

        public final ParameterizedQuery getParameterizedQuery()
        Returns the parameterized query based in this instance of query.
        Returns:
        Parameterized query instance.
      • getId

        public final QueryId getId()
        Return the id of the query.
        Returns:
        Id of the query.
      • getJoins

        public java.util.List<Join> getJoins()
        Return the list of joins.
        Returns:
        Joins.
      • getResource

        public QueryResource getResource()
        Return the resource query object.
        Returns:
        Resource query.
      • getResourceName

        public final java.lang.String getResourceName()
        Return the resource name.
        Specified by:
        getResourceName in interface Queryable
        Returns:
        Resource name.
      • getResources

        public java.util.List<QueryResource> getResources()
        Returns the list of resource of the query.
        Returns:
        List of resource fo the query.
      • getLimit

        public final java.lang.Integer getLimit()
        Return the limit of the query.
        Returns:
        Query limit.
      • setLimit

        public final void setLimit​(java.lang.Integer limit)
        Set the query limit.
        Parameters:
        limit - Query limit.
      • getUnderlyingLimit

        public java.lang.Integer getUnderlyingLimit()
        Returns the query underlying limit.
        Returns:
        Underlying limit.
      • setUnderlyingLimit

        public void setUnderlyingLimit​(java.lang.Integer underlyingLimit)
        Set the underlying limit.
        Parameters:
        underlyingLimit - Underlying limit value.
      • getStart

        public final java.lang.Integer getStart()
        Return the object that represents the first element of the result.
        Returns:
        Firts object of the result.
      • setStart

        public final void setStart​(java.lang.Integer start)
        Set the first object of the result.
        Parameters:
        start - First object of the result.
      • getUnderlyingStart

        public java.lang.Integer getUnderlyingStart()
        Returns the underlying start.
        Returns:
        Underlying start value.
      • setUnderlyingStart

        public void setUnderlyingStart​(java.lang.Integer underlyingStart)
        Set the underlying start.
        Parameters:
        underlyingStart - Underlying start value.
      • getGroupParameters

        public java.util.List<QueryReturnParameter> getGroupParameters()
        Return all the group fields of the query.
        Returns:
        Group field of the query.
      • addGroupField

        public final Query addGroupField​(java.lang.String groupField)
        Add a name of the field for group the data collection. This name must be exist like a setter/getter method in the instances of the data collection.
        Parameters:
        groupField - Name of the pair getter/setter.
        Returns:
        Return the same instance of this class.
      • addGroupField

        public final Query addGroupField​(QueryReturnParameter groupField)
        Add a name of the field for group the data collection. This name must be exist like a setter/getter method in the instances of the data collection.
        Parameters:
        groupField - Name of the pair getter/setter.
        Returns:
        Return the same instance of this class.
      • getOrderParameters

        public final java.util.List<QueryOrderParameter> getOrderParameters()
        Return the unmodifiable list with order fields.
        Returns:
        Order fields.
      • addOrderField

        public final Query addOrderField​(java.lang.String orderField)
        Add a name of the field for order the data collection. This name must be exist like a setter/getter method in the instances of the data collection.
        Parameters:
        orderField - Name of the pair getter/setter.
        Returns:
        Return the same instance of this class.
      • addOrderField

        public final Query addOrderField​(java.lang.String orderField,
                                         boolean desc)
        Add a name of the field for order the data collection. This name must be exist like a setter/getter method in the instances of the data collection.
        Parameters:
        orderField - Name of the pair getter/setter.
        desc - Desc property.
        Returns:
        Return the same instance of this class.
      • addOrderParameter

        public final Query addOrderParameter​(QueryOrderParameter orderParameter)
        Add a name of the field for order the data collection. This name must be exist like a setter/getter method in the instances of the data collection.
        Parameters:
        orderParameter - Order parameter.
        Returns:
        Return the same instance of this class.
      • getReturnParameters

        public final java.util.List<QueryReturnParameter> getReturnParameters()
        Return an unmodifiable list with the return fields.
        Returns:
        Return fields.
      • addReturnField

        public final Query addReturnField​(java.lang.String returnField)
        Add the name of the field to be returned in the result set.
        Parameters:
        returnField - Field name.
        Returns:
        Return the same instance of this class.
      • addReturnField

        public final Query addReturnField​(QueryReturnParameter returnParameter)
        Add the name of the field to be returned in the result set.
        Parameters:
        returnParameter - Return parameter.
        Returns:
        Return the same instance of this class.
      • addJoin

        public final void addJoin​(Join join)
        Add join instance to the query.
        Parameters:
        join - Join instance.
      • evaluate

        public final <O> java.util.Collection<O> evaluate​(java.util.Collection<O> dataSource)
        This method evaluate each object of the collection and sort filtered object to create a result add with the object filtered and sorted. If there are order fields added then the result implementation is a TreeSet implementation else the result implementation is a LinkedHashSet implementation in order to guarantee the data order from the source
        Specified by:
        evaluate in interface Queryable
        Type Parameters:
        O - Kind of instances of the data collection.
        Parameters:
        dataSource - Data source to evaluate the query.
        Returns:
        Result add filtered and sorted.
      • evaluate

        public final <O> java.util.Collection<O> evaluate​(java.util.Collection<O> dataSource,
                                                          Queryable.Consumer<O> consumer)
        This method evaluate each object of the collection and sort filtered object to create a result add with the object filtered and sorted. If there are order fields added then the result implementation is a TreeSet implementation else the result implementation is a LinkedHashSet implementation in order to guarantee the data order from the source
        Specified by:
        evaluate in interface Queryable
        Type Parameters:
        O - Kind of instances of the data collection.
        Parameters:
        dataSource - Data source to evaluate the query.
        consumer - Data source consumer.
        Returns:
        Result add filtered and sorted.
      • evaluate

        public final <O> java.util.Collection<O> evaluate​(Queryable.DataSource<O> dataSource)
        This method evaluate each object of the collection and sort filtered object to create a result add with the object filtered and sorted. If there are order fields added then the result implementation is a TreeSet implementation else the result implementation is a LinkedHashSet implementation in order to guarantee the data order from the source
        Specified by:
        evaluate in interface Queryable
        Type Parameters:
        O - Kind of instances of the data collection.
        Parameters:
        dataSource - Data source to evaluate the query.
        Returns:
        Result add filtered and sorted.
      • evaluate

        public final <O> java.util.Collection<O> evaluate​(Queryable.DataSource<O> dataSource,
                                                          Queryable.Consumer<O> consumer)
        This method evaluate each object of the collection and sort filtered object to create a result add with the object filtered and sorted. If there are order fields added then the result implementation is a TreeSet implementation else the result implementation is a LinkedHashSet implementation in order to guarantee the data order from the source
        Specified by:
        evaluate in interface Queryable
        Type Parameters:
        O - Kind of instances of the data collection.
        Parameters:
        dataSource - Data source to evaluate the query.
        consumer - Data source consumer.
        Returns:
        Result add filtered and sorted.
      • verifyCondition

        public final boolean verifyCondition​(java.lang.Object object)
        This method verify if the conditions of the query are true or not.
        Parameters:
        object - Object to use as condition parameters.
        Returns:
        Returns if the evaluation of conditions are true or false in the otherwise.
      • skipEvaluator

        public static void skipEvaluator​(Evaluator evaluator)
        This method add into the current session an instance that must be skipped of the platform evaluation process.
        Parameters:
        evaluator - Evaluator to skip.
      • reduce

        public final Query reduce​(java.util.Collection<Evaluator> evaluatorsToRemove)
        Return a copy of this query without all the evaluator and order fields of the parameter collections.
        Parameters:
        evaluatorsToRemove - Evaluators to optimizeJoin.
        Returns:
        Reduced copy of the query.
      • reduceFieldEvaluator

        public final Query reduceFieldEvaluator​(java.lang.String fieldName,
                                                java.lang.Class<? extends FieldEvaluator>... evaluatorType)
      • toString

        public java.lang.String toString()
        Creates a string representation of the query object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation.
      • toBson

        public org.hcjf.bson.BsonDocument toBson()
        This method is a particular implementation to create a bson document from a query instance.
        Specified by:
        toBson in interface BsonParcelable
        Returns:
        Returns a bson document.
      • populate

        public <P extends BsonParcelable> P populate​(org.hcjf.bson.BsonDocument document)
        This particular implementation do nothing to populate the instance.
        Specified by:
        populate in interface BsonParcelable
        Type Parameters:
        P - Expected bson parcelable type.
        Parameters:
        document - Bson document to populate the parcelable.
        Returns:
        Returns the same instance.
      • evaluate

        public static java.util.Collection<JoinableMap> evaluate​(java.lang.String query)
        Evaluates the query using a readable data source.
        Parameters:
        query - Query to evaluate.
        Returns:
        Collections of joinable map instances.
      • evaluate

        public static java.util.Collection<JoinableMap> evaluate​(Queryable queryable)
        Evaluates the query using a readable data source.
        Parameters:
        queryable - Query to evaluate.
        Returns:
        Collections of joinable map instances.
      • evaluate

        public static <O> O evaluate​(java.util.UUID uuid)
        This method evaluate if the uuid instance is a uuid type 5 and contains some name of the registered resource and invoke the read method of the resource.
        Type Parameters:
        O - Expected data type.
        Parameters:
        uuid - Resource id.
        Returns:
        Resource instance.
      • compileSingleQuery

        public static Query compileSingleQuery​(java.lang.String resourceName)
        Creates a query with next structure 'SELECT * FROM {resourceName}'
        Parameters:
        resourceName - Resource name.
        Returns:
        Returns a single query instance.
      • compile

        public static Query compile​(java.lang.String sql)
        Create a query instance from sql definition.
        Parameters:
        sql - Sql definition.
        Returns:
        Query instance.
      • compile

        public static Query compile​(java.lang.String sql,
                                    boolean ignoreCache)
        Create a query instance from sql definition.
        Parameters:
        sql - Sql definition
        ignoreCache - Boolean value to indicate if the cache must be ignored or not.
        Returns:
        Query instance.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object