use of lucee.runtime.type.Query in project Lucee by lucee.
the class XMLConfigAdmin method getResourceProviders.
public Query getResourceProviders() throws PageException {
checkReadAccess();
// check parameters
Element parent = _getRootElement("resources");
Element[] elProviders = XMLConfigWebFactory.getChildren(parent, "resource-provider");
Element[] elDefaultProviders = XMLConfigWebFactory.getChildren(parent, "default-resource-provider");
ResourceProvider[] providers = config.getResourceProviders();
ResourceProvider defaultProvider = config.getDefaultResourceProvider();
Query qry = new QueryImpl(new String[] { "support", "scheme", "caseSensitive", "default", "class", "bundleName", "bundleVersion", "arguments" }, elProviders.length + elDefaultProviders.length, "resourceproviders");
int row = 1;
for (int i = 0; i < elDefaultProviders.length; i++) {
getResourceProviders(new ResourceProvider[] { defaultProvider }, qry, elDefaultProviders[i], row++, Boolean.TRUE);
}
for (int i = 0; i < elProviders.length; i++) {
getResourceProviders(providers, qry, elProviders[i], row++, Boolean.FALSE);
}
return qry;
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class HSQLDBHandler method execute.
/**
* executes a query on the queries inside the cld fusion enviroment
* @param pc Page Context
* @param sql
* @param maxrows
* @return result as Query
* @throws PageException
* @throws PageException
*/
public Query execute(PageContext pc, SQL sql, int maxrows, int fetchsize, TimeSpan timeout) throws PageException {
Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
stopwatch.start();
String prettySQL = null;
Selects selects = null;
// First Chance
try {
SelectParser parser = new SelectParser();
selects = parser.parse(sql.getSQLString());
Query q = qoq.execute(pc, sql, selects, maxrows);
q.setExecutionTime(stopwatch.time());
return q;
} catch (SQLParserException spe) {
// lucee.print.printST(spe);
// sp
// lucee.print.out("sql parser crash at:");
// lucee.print.out("--------------------------------");
// lucee.print.out(sql.getSQLString().trim());
// lucee.print.out("--------------------------------");
// print.e("1:"+sql.getSQLString());
prettySQL = SQLPrettyfier.prettyfie(sql.getSQLString());
// print.e("2:"+prettySQL);
try {
Query query = executer.execute(pc, sql, prettySQL, maxrows);
query.setExecutionTime(stopwatch.time());
return query;
} catch (PageException ex) {
// lucee.print.printST(ex);
// lucee.print.out("old executor/zql crash at:");
// lucee.print.out("--------------------------------");
// lucee.print.out(sql.getSQLString().trim());
// lucee.print.out("--------------------------------");
}
} catch (PageException e) {
// throw e;
// print.out("new executor crash at:");
// print.out("--------------------------------");
// print.out(sql.getSQLString().trim());
// print.out("--------------------------------");
}
// SECOND Chance with hsqldb
try {
boolean isUnion = false;
Set<String> tables = null;
if (selects != null) {
HSQLUtil2 hsql2 = new HSQLUtil2(selects);
isUnion = hsql2.isUnion();
tables = hsql2.getInvokedTables();
} else {
if (prettySQL == null)
prettySQL = SQLPrettyfier.prettyfie(sql.getSQLString());
HSQLUtil hsql = new HSQLUtil(prettySQL);
tables = hsql.getInvokedTables();
isUnion = hsql.isUnion();
}
String strSQL = StringUtil.replace(sql.getSQLString(), "[", "", false);
strSQL = StringUtil.replace(strSQL, "]", "", false);
sql.setSQLString(strSQL);
return _execute(pc, sql, maxrows, fetchsize, timeout, stopwatch, tables, isUnion);
} catch (ParseException e) {
throw new DatabaseException(e.getMessage(), null, sql, null);
}
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class DebugEntryTemplatePartComparator method getUsage.
private static Struct getUsage(QueryEntry qe) throws PageException {
Query qry = qe.getQry();
QueryColumn c;
DebugQueryColumn dqc;
outer: if (qry != null) {
Struct usage = null;
Collection.Key[] columnNames = qry.getColumnNames();
Collection.Key columnName;
for (int i = 0; i < columnNames.length; i++) {
columnName = columnNames[i];
c = qry.getColumn(columnName);
if (!(c instanceof DebugQueryColumn))
break outer;
dqc = (DebugQueryColumn) c;
if (usage == null)
usage = new StructImpl();
usage.setEL(columnName, Caster.toBoolean(dqc.isUsed()));
}
return usage;
}
return null;
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class DebugEntryTemplatePartComparator method getOutputText.
public Query getOutputText() throws DatabaseException {
DebugTextFragment[] fragments = outputLog.getFragments();
int len = fragments == null ? 0 : fragments.length;
Query qryOutputLog = new QueryImpl(new Collection.Key[] { KeyConstants._line, KeyConstants._template, KeyConstants._text }, len, "query");
if (len > 0) {
for (int i = 0; i < fragments.length; i++) {
qryOutputLog.setAtEL(KeyConstants._line, i + 1, fragments[i].getLine());
qryOutputLog.setAtEL(KeyConstants._template, i + 1, fragments[i].getTemplate());
qryOutputLog.setAtEL(KeyConstants._text, i + 1, fragments[i].getText());
}
}
return qryOutputLog;
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class Each method _call.
private static String _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>>>();
}
// Array
if (type == TYPE_ARRAY) {
invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
invoke(pc, (Query) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
invoke(pc, (Query) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof Map) {
Iterator it = ((Map) obj).entrySet().iterator();
Entry e;
while (it.hasNext()) {
e = (Entry) it.next();
_call(pc, udf, new Object[] { e.getKey(), e.getValue(), obj }, execute, futures);
// udf.call(pc, new Object[]{e.getKey(),e.getValue()}, true);
}
} else // List
if (obj instanceof List) {
ListIterator it = ((List) obj).listIterator();
int index;
while (it.hasNext()) {
index = it.nextIndex();
_call(pc, udf, new Object[] { it.next(), new Double(index), obj }, execute, futures);
// udf.call(pc, new Object[]{it.next()}, true);
}
} else // Iterator
if (obj instanceof Iterator) {
Iterator it = (Iterator) obj;
while (it.hasNext()) {
_call(pc, udf, new Object[] { it.next() }, execute, futures);
// udf.call(pc, new Object[]{it.next()}, true);
}
} else // Enumeration
if (obj instanceof Enumeration) {
Enumeration e = (Enumeration) obj;
while (e.hasMoreElements()) {
_call(pc, udf, new Object[] { e.nextElement() }, execute, futures);
// udf.call(pc, new Object[]{e.nextElement()}, true);
}
} else // StringListData
if (obj instanceof StringListData) {
invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Each", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
afterCall(pc, futures, execute);
return null;
}
Aggregations