Package org.hcjf.layers.query
Class Query
- java.lang.Object
-
- org.hcjf.layers.query.evaluators.EvaluatorCollection
-
- org.hcjf.layers.query.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.hcjf.utils.bson.BsonParcelable
BsonParcelable.Builder
-
Nested classes/interfaces inherited from interface org.hcjf.layers.query.Queryable
Queryable.Consumer<O>, Queryable.DataSource<O>, Queryable.DefaultConsumer<O>, Queryable.IntrospectionConsumer<O>, Queryable.ReadableDataSource
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringQUERY_BSON_FIELD_NAME-
Fields inherited from class org.hcjf.layers.query.evaluators.EvaluatorCollection
evaluators
-
Fields inherited from interface org.hcjf.utils.bson.BsonParcelable
MAP_KEYS_FIELD_NAME, MAP_VALUES_FIELD_NAME, PARCELABLE_CLASS_NAME
-
-
Constructor Summary
Constructors Constructor Description Query(java.lang.String resource)Query(QueryResource resource)Query(QueryResource resource, QueryId id)
-
Method Summary
Modifier and Type Method Description QueryaddGroupField(java.lang.String groupField)Add a name of the field for group the data collection.QueryaddGroupField(QueryReturnParameter groupField)Add a name of the field for group the data collection.voidaddJoin(Join join)Add join instance to the query.QueryaddOrderField(java.lang.String orderField)Add a name of the field for order the data collection.QueryaddOrderField(java.lang.String orderField, boolean desc)Add a name of the field for order the data collection.QueryaddOrderParameter(QueryOrderParameter orderParameter)Add a name of the field for order the data collection.QueryaddReturnField(java.lang.String returnField)Add the name of the field to be returned in the result set.QueryaddReturnField(QueryReturnParameter returnParameter)Add the name of the field to be returned in the result set.protected EvaluatorcheckEvaluator(Evaluator evaluator)static Querycompile(java.lang.String sql)Create a query instance from sql definition.static Querycompile(java.lang.String sql, boolean ignoreCache)Create a query instance from sql definition.static QuerycompileSingleQuery(java.lang.String resourceName)Creates a query with next structure 'SELECT * FROM {resourceName}'booleanequals(java.lang.Object obj)static java.util.Collection<JoinableMap>evaluate(java.lang.String query)Evaluates the query using a readable data source.<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.<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.static <O> Oevaluate(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.static java.util.Collection<JoinableMap>evaluate(Queryable queryable)Evaluates the query using a readable data source.<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.<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.java.util.List<QueryReturnParameter>getGroupParameters()Return all the group fields of the query.QueryIdgetId()Return the id of the query.java.util.List<Join>getJoins()Return the list of joins.java.lang.IntegergetLimit()Return the limit of the query.java.util.List<QueryOrderParameter>getOrderParameters()Return the unmodifiable list with order fields.ParameterizedQuerygetParameterizedQuery()Returns the parameterized query based in this instance of query.QueryResourcegetResource()Return the resource query object.java.lang.StringgetResourceName()Return the resource name.java.util.List<QueryResource>getResources()Returns the list of resource of the query.java.util.List<QueryReturnParameter>getReturnParameters()Return an unmodifiable list with the return fields.java.lang.IntegergetStart()Return the object that represents the first element of the result.java.lang.IntegergetUnderlyingLimit()Returns the query underlying limit.java.lang.IntegergetUnderlyingStart()Returns the underlying start.<P extends BsonParcelable>
Ppopulate(org.hcjf.bson.BsonDocument document)This particular implementation do nothing to populate the instance.Queryreduce(java.util.Collection<Evaluator> evaluatorsToRemove)Return a copy of this query without all the evaluator and order fields of the parameter collections.QueryreduceFieldEvaluator(java.lang.String fieldName, java.lang.Class<? extends FieldEvaluator>... evaluatorType)booleanreturnAll()Verify if the query indicates return all the fields of the result set.voidsetLimit(java.lang.Integer limit)Set the query limit.voidsetStart(java.lang.Integer start)Set the first object of the result.voidsetUnderlyingLimit(java.lang.Integer underlyingLimit)Set the underlying limit.voidsetUnderlyingStart(java.lang.Integer underlyingStart)Set the underlying start.static voidskipEvaluator(Evaluator evaluator)This method add into the current session an instance that must be skipped of the platform evaluation process.org.hcjf.bson.BsonDocumenttoBson()This method is a particular implementation to create a bson document from a query instance.java.lang.StringtoString()Creates a string representation of the query object.booleanverifyCondition(java.lang.Object object)This method verify if the conditions of the query are true or not.-
Methods inherited from class org.hcjf.layers.query.evaluators.EvaluatorCollection
addBoolean, addEvaluator, and, distinct, equals, getEvaluators, getFieldEvaluators, greaterThan, greaterThanOrEquals, hasEvaluators, in, like, notIn, onAddEvaluator, or, removeEvaluator, smallerThan, smallerThanOrEqual, up
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.hcjf.utils.bson.BsonParcelable
fromBson, fromBson, fromBson, toBson, toBson, toBson, typeFromBson
-
-
-
-
Field Detail
-
QUERY_BSON_FIELD_NAME
public static final java.lang.String QUERY_BSON_FIELD_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Query
public Query(QueryResource resource, QueryId id)
-
Query
public Query(java.lang.String resource)
-
Query
public Query(QueryResource resource)
-
-
Method Detail
-
checkEvaluator
protected Evaluator checkEvaluator(Evaluator evaluator)
- Overrides:
checkEvaluatorin classEvaluatorCollection
-
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:
getResourceNamein interfaceQueryable- 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 aTreeSetimplementation else the result implementation is aLinkedHashSetimplementation in order to guarantee the data order from the source
-
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 aTreeSetimplementation else the result implementation is aLinkedHashSetimplementation in order to guarantee the data order from the source
-
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 aTreeSetimplementation else the result implementation is aLinkedHashSetimplementation in order to guarantee the data order from the source
-
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 aTreeSetimplementation else the result implementation is aLinkedHashSetimplementation in order to guarantee the data order from the source
-
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:
toStringin classjava.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:
toBsonin interfaceBsonParcelable- 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:
populatein interfaceBsonParcelable- 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 definitionignoreCache- Boolean value to indicate if the cache must be ignored or not.- Returns:
- Query instance.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-