Search in sources :

Example 1 with ForEachQueryIterator

use of lucee.runtime.type.it.ForEachQueryIterator in project Lucee by lucee.

the class Every method invoke.

private static boolean invoke(PageContext pc, Query qry, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws CasterException, PageException {
    final int pid = pc.getId();
    ForEachQueryIterator it = new ForEachQueryIterator(qry, pid);
    boolean async = es != null;
    double r;
    Object res, row;
    try {
        while (it.hasNext()) {
            row = it.next();
            r = Caster.toDoubleValue(qry.getCurrentrow(pid));
            res = _inv(pc, udf, new Object[] { row, r, qry }, r, row, es, futures);
            if (!async && !Caster.toBooleanValue(res)) {
                return false;
            }
        }
    } finally {
        it.reset();
    }
    return true;
}
Also used : ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator)

Example 2 with ForEachQueryIterator

use of lucee.runtime.type.it.ForEachQueryIterator in project Lucee by lucee.

the class Filter method invoke.

private static Collection invoke(PageContext pc, Query qry, UDF udf, ExecutorService es, List<Future<Data<Pair<Object, Object>>>> futures) throws CasterException, PageException {
    Key[] colNames = qry.getColumnNames();
    Query rtn = new QueryImpl(colNames, 0, qry.getName());
    final int pid = pc.getId();
    ForEachQueryIterator it = new ForEachQueryIterator(qry, pid);
    int rowNbr;
    Object row;
    boolean async = es != null;
    Object res;
    while (it.hasNext()) {
        row = it.next();
        rowNbr = qry.getCurrentrow(pid);
        res = _inv(pc, udf, new Object[] { row, Caster.toDoubleValue(rowNbr), qry }, rowNbr, qry, es, futures);
        if (!async && Caster.toBooleanValue(res)) {
            addRow(qry, rtn, rowNbr);
        }
    }
    return rtn;
}
Also used : ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Key(lucee.runtime.type.Collection.Key) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Example 3 with ForEachQueryIterator

use of lucee.runtime.type.it.ForEachQueryIterator in project Lucee by lucee.

the class Reduce method invoke.

private static Object invoke(PageContext pc, Query qry, UDF udf, Object initalValue) throws CasterException, PageException {
    final int pid = pc.getId();
    ForEachQueryIterator it = new ForEachQueryIterator(qry, pid);
    int rowNbr;
    Object row;
    while (it.hasNext()) {
        row = it.next();
        rowNbr = qry.getCurrentrow(pid);
        initalValue = udf.call(pc, new Object[] { initalValue, row, Caster.toDoubleValue(rowNbr), qry }, true);
    }
    return initalValue;
}
Also used : ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator)

Example 4 with ForEachQueryIterator

use of lucee.runtime.type.it.ForEachQueryIterator in project Lucee by lucee.

the class SerializeJSON method _call.

private static String _call(PageContext pc, Object var, Object options, Charset charset) throws PageException {
    try {
        JSONConverter json = new JSONConverter(true, charset);
        if (Decision.isBoolean(options))
            return json.serialize(pc, var, Caster.toBoolean(options));
        if (Decision.isQuery(var)) {
            if (Decision.isSimpleValue(options)) {
                String opt = Caster.toString(options);
                if ("struct".equalsIgnoreCase(opt)) {
                    Array arr = new ArrayImpl();
                    ForEachQueryIterator it = new ForEachQueryIterator((Query) var, pc.getId());
                    try {
                        while (it.hasNext()) {
                            // append each record from the query as a struct
                            arr.append(it.next());
                        }
                    } finally {
                        it.reset();
                    }
                    return json.serialize(pc, arr, false);
                }
            } else if (Decision.isBoolean(options)) {
                return json.serialize(pc, var, Caster.toBoolean(options));
            } else
                throw new FunctionException(pc, SerializeJSON.class.getSimpleName(), 2, "options", "When var is a Query, argument [options] must be either a boolean value or a string with the value of [struct]");
        }
        // var is not a query so options doesn't make a difference here
        return json.serialize(pc, var, false);
    } catch (ConverterException e) {
        throw Caster.toPageException(e);
    }
}
Also used : Array(lucee.runtime.type.Array) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) ConverterException(lucee.runtime.converter.ConverterException) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException) JSONConverter(lucee.runtime.converter.JSONConverter)

Example 5 with ForEachQueryIterator

use of lucee.runtime.type.it.ForEachQueryIterator in project Lucee by lucee.

the class Each method invoke.

public static void invoke(PageContext pc, Query qry, UDF udf, ExecutorService execute, List<Future<Data<Object>>> futures) throws PageException {
    final int pid = pc.getId();
    ForEachQueryIterator it = new ForEachQueryIterator(qry, pid);
    try {
        Object row;
        while (it.hasNext()) {
            row = it.next();
            _call(pc, udf, new Object[] { row, Caster.toDoubleValue(qry.getCurrentrow(pid)), qry }, execute, futures);
        }
    } finally {
        it.reset();
    }
}
Also used : ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator)

Aggregations

ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)7 ArrayImpl (lucee.runtime.type.ArrayImpl)2 Key (lucee.runtime.type.Collection.Key)2 QueryImpl (lucee.runtime.type.QueryImpl)2 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)2 ConverterException (lucee.runtime.converter.ConverterException)1 JSONConverter (lucee.runtime.converter.JSONConverter)1 FunctionException (lucee.runtime.exp.FunctionException)1 Array (lucee.runtime.type.Array)1 Query (lucee.runtime.type.Query)1