Search in sources :

Example 66 with QueryImpl

use of lucee.runtime.type.QueryImpl in project Lucee by lucee.

the class RHExtension method populate.

private void populate(Query qry) throws PageException, IOException, BundleException {
    int row = qry.addRow();
    qry.setAt(KeyConstants._id, row, getId());
    qry.setAt(KeyConstants._name, row, name);
    qry.setAt(KeyConstants._image, row, getImage());
    qry.setAt(KeyConstants._description, row, description);
    qry.setAt(KeyConstants._version, row, getVersion() == null ? null : getVersion().toString());
    qry.setAt(TRIAL, row, isTrial());
    qry.setAt(RELEASE_TYPE, row, toReleaseType(getReleaseType(), "all"));
    // qry.setAt(JARS, row,Caster.toArray(getJars()));
    qry.setAt(FLDS, row, Caster.toArray(getFlds()));
    qry.setAt(TLDS, row, Caster.toArray(getTlds()));
    qry.setAt(FUNCTIONS, row, Caster.toArray(getFunctions()));
    qry.setAt(ARCHIVES, row, Caster.toArray(getArchives()));
    qry.setAt(TAGS, row, Caster.toArray(getTags()));
    qry.setAt(CONTEXTS, row, Caster.toArray(getContexts()));
    qry.setAt(WEBCONTEXTS, row, Caster.toArray(getWebContexts()));
    qry.setAt(CONFIG, row, Caster.toArray(getConfigs()));
    qry.setAt(EVENT_GATEWAYS, row, Caster.toArray(getEventGateways()));
    qry.setAt(CATEGORIES, row, Caster.toArray(getCategories()));
    qry.setAt(APPLICATIONS, row, Caster.toArray(getApplications()));
    qry.setAt(COMPONENTS, row, Caster.toArray(getComponents()));
    qry.setAt(PLUGINS, row, Caster.toArray(getPlugins()));
    qry.setAt(START_BUNDLES, row, Caster.toBoolean(getStartBundles()));
    BundleInfo[] bfs = getBundles();
    Query qryBundles = new QueryImpl(new Key[] { KeyConstants._name, KeyConstants._version }, bfs.length, "bundles");
    for (int i = 0; i < bfs.length; i++) {
        qryBundles.setAt(KeyConstants._name, i + 1, bfs[i].getSymbolicName());
        if (bfs[i].getVersion() != null)
            qryBundles.setAt(KeyConstants._version, i + 1, bfs[i].getVersionAsString());
    }
    qry.setAt(BUNDLES, row, qryBundles);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) BundleInfo(lucee.runtime.osgi.BundleInfo) Query(lucee.runtime.type.Query)

Example 67 with QueryImpl

use of lucee.runtime.type.QueryImpl 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 68 with QueryImpl

use of lucee.runtime.type.QueryImpl in project Lucee by lucee.

the class Executer method testExecute.

private Query testExecute(PageContext pc, SQL sql, Query qr, ZQuery query, int maxrows) throws PageException {
    int recCount = qr.getRecordcount();
    Vector vSelects = query.getSelect();
    int selCount = vSelects.size();
    Map<Collection.Key, Object> selects = MapFactory.<Collection.Key, Object>getConcurrentMap();
    boolean isSMS = false;
    // headers
    for (int i = 0; i < selCount; i++) {
        ZSelectItem select = (ZSelectItem) vSelects.get(i);
        if (select.isWildcard() || (isSMS = select.getColumn().equals(SQLPrettyfier.PLACEHOLDER_ASTERIX))) {
            if (!isSMS && !select.getColumn().equals("*"))
                throw new DatabaseException("can't execute this type of query at the moment", null, sql, null);
            // Collection.Key[] keys = qr.keys();
            Iterator<Key> it = qr.keyIterator();
            Key k;
            while (it.hasNext()) {
                k = it.next();
                selects.put(k, k.getString());
            }
            isSMS = false;
        } else {
            // if(SQLPrettyfier.PLACEHOLDER_COUNT.equals(select.getAlias())) select.setAlias("count");
            // if(SQLPrettyfier.PLACEHOLDER_COUNT.equals(select.getColumn())) select.setExpression(new ZConstant("count",ZConstant.COLUMNNAME));
            String alias = select.getAlias();
            String column = select.getColumn();
            if (alias == null)
                alias = column;
            alias = alias.toLowerCase();
            selects.put(KeyImpl.init(alias), select);
        }
    }
    Key[] headers = selects.keySet().toArray(new Collection.Key[selects.size()]);
    // aHeaders.toArray(new String[aHeaders.size()]);
    QueryImpl rtn = new QueryImpl(headers, 0, "query", sql);
    // loop records
    Vector orders = query.getOrderBy();
    ZExp where = query.getWhere();
    // print.out(headers);
    // int newRecCount=0;
    boolean hasMaxrow = maxrows > -1 && (orders == null || orders.size() == 0);
    for (int row = 1; row <= recCount; row++) {
        sql.setPosition(0);
        if (hasMaxrow && maxrows <= rtn.getRecordcount())
            break;
        boolean useRow = where == null || Caster.toBooleanValue(executeExp(pc, sql, qr, where, row));
        if (useRow) {
            rtn.addRow(1);
            for (int cell = 0; cell < headers.length; cell++) {
                Object value = selects.get(headers[cell]);
                rtn.setAt(headers[cell], rtn.getRecordcount(), getValue(pc, sql, qr, row, headers[cell], value));
            }
        }
    }
    // Group By
    if (query.getGroupBy() != null)
        throw new DatabaseException("group by are not supported at the moment", null, sql, null);
    // Order By
    if (orders != null && orders.size() > 0) {
        int len = orders.size();
        for (int i = len - 1; i >= 0; i--) {
            ZOrderBy order = (ZOrderBy) orders.get(i);
            ZConstant name = (ZConstant) order.getExpression();
            rtn.sort(name.getValue().toLowerCase(), order.getAscOrder() ? Query.ORDER_ASC : Query.ORDER_DESC);
        }
        if (maxrows > -1) {
            rtn.cutRowsTo(maxrows);
        }
    }
    // Distinct
    if (query.isDistinct()) {
        String[] keys = rtn.getColumns();
        QueryColumn[] columns = new QueryColumn[keys.length];
        for (int i = 0; i < columns.length; i++) {
            columns[i] = rtn.getColumn(keys[i]);
        }
        int i;
        outer: for (int row = rtn.getRecordcount(); row > 1; row--) {
            for (i = 0; i < columns.length; i++) {
                if (!Operator.equals(QueryUtil.getValue(columns[i], row), QueryUtil.getValue(columns[i], row - 1), true))
                    continue outer;
            }
            rtn.removeRow(row);
        }
    }
    // UNION // TODO support it
    ZExpression set = query.getSet();
    if (set != null) {
        ZExp op = set.getOperand(0);
        if (op instanceof ZQuery)
            throw new DatabaseException("union is not supported at the moment", null, sql, null);
    // getInvokedTables((ZQuery)op, tablesNames);
    }
    return rtn;
}
Also used : ZOrderBy(lucee.runtime.sql.old.ZOrderBy) ZExpression(lucee.runtime.sql.old.ZExpression) ZExp(lucee.runtime.sql.old.ZExp) ZQuery(lucee.runtime.sql.old.ZQuery) ZConstant(lucee.runtime.sql.old.ZConstant) QueryImpl(lucee.runtime.type.QueryImpl) ZSelectItem(lucee.runtime.sql.old.ZSelectItem) QueryColumn(lucee.runtime.type.QueryColumn) Collection(lucee.runtime.type.Collection) Vector(java.util.Vector) DatabaseException(lucee.runtime.exp.DatabaseException) Key(lucee.runtime.type.Collection.Key)

Example 69 with QueryImpl

use of lucee.runtime.type.QueryImpl in project Lucee by lucee.

the class QoQ method execute.

/**
 * execute a SQL Statement against CFML Scopes
 */
public Query execute(PageContext pc, SQL sql, Selects selects, int maxrows) throws PageException {
    Column[] orders = selects.getOrderbys();
    Select[] arrSelects = selects.getSelects();
    QueryImpl target = new QueryImpl(new Collection.Key[0], 0, "query", sql);
    for (int i = 0; i < arrSelects.length; i++) {
        arrSelects[i].getFroms();
        Column[] froms = arrSelects[i].getFroms();
        if (froms.length > 1)
            throw new DatabaseException("can only work with single tables yet", null, sql, null);
        executeSingle(pc, arrSelects[i], getSingleTable(pc, froms[0]), target, arrSelects.length > 1 ? -1 : maxrows, sql, orders.length > 0);
    }
    // Order By
    if (orders.length > 0) {
        order(target, orders);
        if (maxrows > -1)
            target.cutRowsTo(maxrows);
    }
    // Distinct
    if (selects.isDistinct()) {
        // order to filter
        order(target, selects.getDistincts());
        // print.e(selects.getDistincts());
        Key[] _keys = target.getColumnNames();
        QueryColumn[] columns = new QueryColumn[_keys.length];
        for (int i = 0; i < columns.length; i++) {
            columns[i] = target.getColumn(_keys[i]);
        }
        int i;
        Object l, r;
        outer: for (int row = target.getRecordcount(); row > 1; row--) {
            for (i = 0; i < columns.length; i++) {
                l = columns[i].get(row, null);
                r = columns[i].get(row - 1, null);
                if (l == null || r == null) {
                    if (l != r)
                        continue outer;
                } else if (!Operator.equals(l, r, true))
                    continue outer;
            }
            target.removeRow(row);
        }
    }
    order(target, orders);
    return target;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) QueryColumn(lucee.runtime.type.QueryColumn) Column(lucee.runtime.sql.exp.Column) QueryColumn(lucee.runtime.type.QueryColumn) Select(lucee.runtime.sql.Select) Collection(lucee.runtime.type.Collection) DatabaseException(lucee.runtime.exp.DatabaseException) Key(lucee.runtime.type.Collection.Key)

Example 70 with QueryImpl

use of lucee.runtime.type.QueryImpl 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)

Aggregations

QueryImpl (lucee.runtime.type.QueryImpl)82 Query (lucee.runtime.type.Query)65 Collection (lucee.runtime.type.Collection)17 Struct (lucee.runtime.type.Struct)16 StructImpl (lucee.runtime.type.StructImpl)13 PageException (lucee.runtime.exp.PageException)12 Key (lucee.runtime.type.Collection.Key)12 Iterator (java.util.Iterator)11 Map (java.util.Map)10 ApplicationException (lucee.runtime.exp.ApplicationException)10 Array (lucee.runtime.type.Array)10 DatabaseException (lucee.runtime.exp.DatabaseException)9 Stopwatch (lucee.runtime.timer.Stopwatch)9 HashMap (java.util.HashMap)8 Resource (lucee.commons.io.res.Resource)7 BundleCollection (lucee.loader.osgi.BundleCollection)7 Entry (java.util.Map.Entry)6 IOException (java.io.IOException)5 ResultSet (java.sql.ResultSet)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5