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;
}
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;
}
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;
}
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);
}
}
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();
}
}
Aggregations