Current Object ScopeCurrent Object Scope
The special bind variables :_allobjs and :_currobj have different values at different points in the execution of the SQL statement. It is important to understand what values these variables can have at each point.

When execution commences the value of :_currobj value is null and the value of :_allobjs is equal to the list of objects passed in. If a EXECUTE ON ALL clause is defined using :_allobjs in that context means "the objects passed in to the execute method". When these functions are executed the function itself may set the value of: :_currobj to allow expressions to work correctly, for example:
FROM   java.io.File
EXECUTE ON ALL avg (:_allobjs, length) avgLength
The avg function takes a List as it's first argument and an accessor as the second argument, it then determines the value of the length accessor for each object in the List (denoted here by the :_allobjs bind variable). The avg function sets the current object in the Query object by calling:
q.setCurrentObject (object);
For every object in the list then gets the value for the accessor. The avg function will also record what the value of the current object is before iterating over the List and then restores that value once iteration has completed.

When a WHERE clause is being executed, the list of objects passed in to the execute method is iterated over, the :_currobj value is set to the current object in the iteration and the WHERE clause then executed for that object. In essence the loop looks like (in the Query.execute(List) method):
// Iterate over all the objects passed in.
for (int i = 0; i < objs.size (); i++)

    Object o = objs.get (i);

    setCurrentObject (o);

    if (whereClause.isTrue (this,

       // Add to results.


Once all the objects have been iterated over for the WHERE clause, the :_allobjs value is set to the List of objects that were accepted by the WHERE clause (the WHERE clause returned true). At this point any EXECUTE ON RESULTS functions are executed, the same rules as for the EXECUTE ON ALL apply, the only difference here is that the :_allobjs bind variable now refers to the list of objects that were accepted by the WHERE clause. When the ORDER BY clause (if any) is then executed the value of :_currobj is a little more complex.
See Also