Once called the method performs (roughly) the following steps:
Evaluate the EXECUTE ON ALL clause
The first step taken is to execute any functions/expressions present in the EXECUTE ON ALL clause (if the clause is present). At this point the :_allobjs special bind variable is set to the list of objects passed into the execute method. See the EXECUTE ON clause for more details.Evaluate the WHERE clause
The WHERE clause is evaluated against each object in the list passed to the execute method. The WHERE clause is basically just an expression that consists of other expressions. For each object the current object scope is modified such that the :_currobj special bind variable is set to that object.If the WHERE clause evaluates to
true
for the object (by calling: isTrue(java.lang.Object,org.josql.Query)) then it is added to the where results.If there are is no WHERE clause then the where results is just the same list of objects (un-modified) that is passed into the execute method.
At this point, the :_allobjs special bind variable is set to the where results. i.e. any access to the :_allobjs bind variable will return the where results.
Evaluate the EXECUTE ON RESULTS clause
The EXECUTE ON RESULTS clause (if present) is then evaluated. At this point the :_allobjs special bind variable is set to the where results. See the EXECUTE ON clause for more details.Evaluate the GROUP BY clause
The GROUP BY clause is then evaluated. The group by clause only works on the objects that matched the WHERE clause (if present). For each object the current object scope is modified such that the :_currobj special bind variable is set to that object.The GROUP BY clause is basically a list of expressions and each one is evaluated (against the current object) and the values saved in a List. The List is then used as a key to a Map, the value it maps to is also a List which holds the list of objects that have the unique key. The Map then constitutes the group by results (which can be gained by calling method: getGroupByResults()).
Evaluate the GROUP BY ORDER clause
The GROUP BY ORDER clause is then evaluated. This evaluates the group by order clause against the "keys" of the group by results Map. If no group by order clause is specified then the group by results are not guaranteed to be in any specific order. It should be noted that the group by order clause works on a List NOT the object type specified in the FROM clause. As such "normal" accessors won't work.
Evaluate the GROUP BY LIMIT clause
The GROUP BY LIMIT clause is then evaluated. This will limit the group by results between the values specified. Expressions can be used for the start and row count values, but they must return numbers.Evaluate the ORDER BY clause
JoSQL allows the GROUP BY results AND the "normal" results to be ordered. When a GROUP BY clause is specified this means that each List of matching objects that are present in the group by results are then ordered according to the order by clause. It should be noted that when the order by clause is evaluated the :_allobjs variable is set to the List of objects. Also the :_grpby variable is set to the "keys". Just before the ordering takes place however the EXECUTE ON GROUP_BY_RESULTS clause is executed on the List of objects.It should be noted here that the order by clause works on the objects NOT the values that have been selected. This is important since it then allows you to order the results based on information NOT present in the SELECT clause. For example, you may have special methods in your object that provide complex sorting criteria.
Evaluate the LIMIT clause
The LIMIT clause is then applied. For group by results this will occur on each List of objects in the results. For where results (no group by clause) this will occur on the List of objects that matched the WHERE clause. The start and row count values can be expressions but they must return numbers.Evaluate the SELECT clause
Finally, after all of the above has been performed the SELECT clause is evaluated. If a GROUP BY clause has been specified then the select clause will return values (basically a List of Lists) for each "key" provided by the group by results.Each "column" in the select clause is just an expression that is evaluated with the object set as the :_currobj special bind variable. i.e. in a similar way to the WHERE clause the select clause is evaluated with respect to the object in the where results or group by results.
If the DISTINCT keyword is used then the distinct set of results is found and returned.
Once all that has been done the results are then returned from the execute method.