use of lucee.runtime.type.Query in project Lucee by lucee.
the class QueryCacheHandlerFilter method accept.
@Override
public boolean accept(Object obj) {
Query qry;
if (!(obj instanceof Query)) {
if (obj instanceof QueryCacheItem) {
qry = ((QueryCacheItem) obj).getQuery();
} else
return false;
} else
qry = (Query) obj;
String sql = qry.getSql().toString();
StringBuilder sb = new StringBuilder();
char[] text = sql.toCharArray();
for (int i = 0; i < text.length; i++) {
if (text[i] == '\n' || text[i] == '\r') {
sb.append(' ');
} else
sb.append(text[i]);
}
return filter.accept(sb.toString());
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class UDFArgConverter method serializeCollection.
private static String serializeCollection(Collection coll, Set<Object> done) {
if (coll instanceof Query) {
Query qry = (Query) coll;
StringBuilder sb = new StringBuilder(8192);
Iterator<Key> it = qry.keyIterator();
Key k;
sb.append("{");
int len = qry.getRecordcount();
while (it.hasNext()) {
k = it.next();
sb.append(',');
sb.append(k.getLowerString());
sb.append('[');
boolean doIt = false;
for (int y = 1; y <= len; y++) {
if (doIt)
sb.append(',');
doIt = true;
try {
sb.append(serialize(qry.getAt(k, y), done));
} catch (PageException e) {
sb.append(serialize(e.getMessage(), done));
}
}
sb.append(']');
}
sb.append('}');
return sb.toString();
}
StringBuilder sb = new StringBuilder("{");
Iterator<Entry<Key, Object>> it = coll.entryIterator();
Entry<Key, Object> e;
boolean notFirst = false;
while (it.hasNext()) {
if (notFirst)
sb.append(",");
e = it.next();
sb.append(e.getKey().getLowerString());
sb.append(":");
sb.append(serialize(e.getValue(), done));
notFirst = true;
}
return sb.append("}").toString();
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class Every method _call.
public static boolean _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Object>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Object>>>();
}
boolean res;
// Array
if (type == TYPE_ARRAY) {
res = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
res = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (type == TYPE_STRUCT) {
res = invoke(pc, (Struct) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
res = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
res = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (obj instanceof Struct) {
res = invoke(pc, (Struct) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
res = invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof java.util.Map) {
res = invoke(pc, (java.util.Map) obj, udf, execute, futures);
} else // List
if (obj instanceof List) {
res = invoke(pc, (List) obj, udf, execute, futures);
} else // Iterator
if (obj instanceof Iterator) {
res = invoke(pc, (Iterator) obj, udf, execute, futures);
} else // Enumeration
if (obj instanceof Enumeration) {
res = invoke(pc, (Enumeration) obj, udf, execute, futures);
} else // String List
if (obj instanceof StringListData) {
res = invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Every", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
res = afterCall(pc, futures, execute);
return res;
}
use of lucee.runtime.type.Query 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.Query in project Lucee by lucee.
the class Map method _call.
public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, Query resQry, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Object>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Object>>>();
}
Collection coll;
// Array
if (type == TYPE_ARRAY) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
} else // Struct
if (type == TYPE_STRUCT) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
coll = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
} else // Struct
if (obj instanceof Struct) {
coll = invoke(pc, (Struct) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
coll = invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof java.util.Map) {
coll = invoke(pc, (java.util.Map) obj, udf, execute, futures);
} else // List
if (obj instanceof List) {
coll = invoke(pc, (List) obj, udf, execute, futures);
} else // Iterator
if (obj instanceof Iterator) {
coll = invoke(pc, (Iterator) obj, udf, execute, futures);
} else // Enumeration
if (obj instanceof Enumeration) {
coll = invoke(pc, (Enumeration) obj, udf, execute, futures);
} else // String List
if (obj instanceof StringListData) {
coll = invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Map", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
afterCall(pc, coll, futures, execute);
return coll;
}
Aggregations