Search in sources :

Example 66 with Query

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;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Element(org.w3c.dom.Element) ResourceProvider(lucee.commons.io.res.ResourceProvider)

Example 67 with Query

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);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Query(lucee.runtime.type.Query) Stopwatch(lucee.runtime.timer.Stopwatch) SQLParserException(lucee.runtime.sql.SQLParserException) Selects(lucee.runtime.sql.Selects) ParseException(lucee.runtime.sql.old.ParseException) SelectParser(lucee.runtime.sql.SelectParser) DatabaseException(lucee.runtime.exp.DatabaseException)

Example 68 with Query

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;
}
Also used : DebugQueryColumn(lucee.runtime.type.DebugQueryColumn) StructImpl(lucee.runtime.type.StructImpl) Query(lucee.runtime.type.Query) QueryColumn(lucee.runtime.type.QueryColumn) DebugQueryColumn(lucee.runtime.type.DebugQueryColumn) Collection(lucee.runtime.type.Collection) Key(lucee.runtime.type.Collection.Key) Struct(lucee.runtime.type.Struct)

Example 69 with Query

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;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Collection(lucee.runtime.type.Collection)

Example 70 with Query

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;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) ListIterator(java.util.ListIterator) Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

Query (lucee.runtime.type.Query)82 QueryImpl (lucee.runtime.type.QueryImpl)52 Struct (lucee.runtime.type.Struct)19 Array (lucee.runtime.type.Array)16 Collection (lucee.runtime.type.Collection)14 Iterator (java.util.Iterator)13 PageException (lucee.runtime.exp.PageException)12 Map (java.util.Map)11 StructImpl (lucee.runtime.type.StructImpl)11 ApplicationException (lucee.runtime.exp.ApplicationException)10 Stopwatch (lucee.runtime.timer.Stopwatch)10 Key (lucee.runtime.type.Collection.Key)9 List (java.util.List)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 QueryColumn (lucee.runtime.type.QueryColumn)7 Enumeration (java.util.Enumeration)6 Entry (java.util.Map.Entry)6 FunctionException (lucee.runtime.exp.FunctionException)6