Search in sources :

Example 36 with Array

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

the class DebugEntryTemplatePartComparator method getDebuggingData.

@Override
public Struct getDebuggingData(PageContext pc, boolean addAddionalInfo) throws DatabaseException {
    Struct debugging = new StructImpl();
    // datasources
    debugging.setEL(KeyConstants._datasources, ((ConfigImpl) pc.getConfig()).getDatasourceConnectionPool().meta());
    // queries
    List<QueryEntry> queries = getQueries();
    Struct qryExe = new StructImpl();
    ListIterator<QueryEntry> qryIt = queries.listIterator();
    Collection.Key[] cols = new Collection.Key[] { KeyConstants._name, KeyConstants._time, KeyConstants._sql, KeyConstants._src, KeyConstants._count, KeyConstants._datasource, KeyConstants._usage, CACHE_TYPE };
    String[] types = new String[] { "VARCHAR", "DOUBLE", "VARCHAR", "VARCHAR", "DOUBLE", "VARCHAR", "ANY", "VARCHAR" };
    Query qryQueries = null;
    try {
        qryQueries = new QueryImpl(cols, types, queries.size(), "query");
    } catch (DatabaseException e) {
        qryQueries = new QueryImpl(cols, queries.size(), "query");
    }
    int row = 0;
    try {
        QueryEntry qe;
        while (qryIt.hasNext()) {
            row++;
            qe = qryIt.next();
            qryQueries.setAt(KeyConstants._name, row, qe.getName() == null ? "" : qe.getName());
            qryQueries.setAt(KeyConstants._time, row, Long.valueOf(qe.getExecutionTime()));
            qryQueries.setAt(KeyConstants._sql, row, qe.getSQL().toString());
            qryQueries.setAt(KeyConstants._src, row, qe.getSrc());
            qryQueries.setAt(KeyConstants._count, row, Integer.valueOf(qe.getRecordcount()));
            qryQueries.setAt(KeyConstants._datasource, row, qe.getDatasource());
            qryQueries.setAt(CACHE_TYPE, row, qe.getCacheType());
            Struct usage = getUsage(qe);
            if (usage != null)
                qryQueries.setAt(KeyConstants._usage, row, usage);
            Object o = qryExe.get(KeyImpl.init(qe.getSrc()), null);
            if (o == null)
                qryExe.setEL(KeyImpl.init(qe.getSrc()), Long.valueOf(qe.getExecutionTime()));
            else
                qryExe.setEL(KeyImpl.init(qe.getSrc()), Long.valueOf(((Long) o).longValue() + qe.getExecutionTime()));
        }
    } catch (PageException dbe) {
    }
    // Pages
    // src,load,app,query,total
    row = 0;
    ArrayList<DebugEntryTemplate> arrPages = toArray();
    int len = arrPages.size();
    Query qryPage = new QueryImpl(new Collection.Key[] { KeyConstants._id, KeyConstants._count, KeyConstants._min, KeyConstants._max, KeyConstants._avg, KeyConstants._app, KeyConstants._load, KeyConstants._query, KeyConstants._total, KeyConstants._src }, len, "query");
    try {
        DebugEntryTemplate de;
        // PageSource ps;
        for (int i = 0; i < len; i++) {
            row++;
            de = arrPages.get(i);
            // ps = de.getPageSource();
            qryPage.setAt(KeyConstants._id, row, de.getId());
            qryPage.setAt(KeyConstants._count, row, _toString(de.getCount()));
            qryPage.setAt(KeyConstants._min, row, _toString(de.getMin()));
            qryPage.setAt(KeyConstants._max, row, _toString(de.getMax()));
            qryPage.setAt(KeyConstants._avg, row, _toString(de.getExeTime() / de.getCount()));
            qryPage.setAt(KeyConstants._app, row, _toString(de.getExeTime() - de.getQueryTime()));
            qryPage.setAt(KeyConstants._load, row, _toString(de.getFileLoadTime()));
            qryPage.setAt(KeyConstants._query, row, _toString(de.getQueryTime()));
            qryPage.setAt(KeyConstants._total, row, _toString(de.getFileLoadTime() + de.getExeTime()));
            qryPage.setAt(KeyConstants._src, row, de.getSrc());
        }
    } catch (PageException dbe) {
    }
    // Pages Parts
    List<DebugEntryTemplatePart> filteredPartEntries = null;
    boolean hasParts = partEntries != null && !partEntries.isEmpty() && !arrPages.isEmpty();
    int qrySize = 0;
    if (hasParts) {
        String slowestTemplate = arrPages.get(0).getPath();
        filteredPartEntries = new ArrayList();
        java.util.Collection<DebugEntryTemplatePartImpl> col = partEntries.values();
        for (DebugEntryTemplatePart detp : col) {
            if (detp.getPath().equals(slowestTemplate))
                filteredPartEntries.add(detp);
        }
        qrySize = Math.min(filteredPartEntries.size(), MAX_PARTS);
    }
    Query qryPart = new QueryImpl(new Collection.Key[] { KeyConstants._id, KeyConstants._count, KeyConstants._min, KeyConstants._max, KeyConstants._avg, KeyConstants._total, KeyConstants._path, KeyConstants._start, KeyConstants._end, KeyConstants._startLine, KeyConstants._endLine, KeyConstants._snippet }, qrySize, "query");
    if (hasParts) {
        row = 0;
        Collections.sort(filteredPartEntries, DEBUG_ENTRY_TEMPLATE_PART_COMPARATOR);
        DebugEntryTemplatePart[] parts = new DebugEntryTemplatePart[qrySize];
        if (filteredPartEntries.size() > MAX_PARTS)
            parts = filteredPartEntries.subList(0, MAX_PARTS).toArray(parts);
        else
            parts = filteredPartEntries.toArray(parts);
        try {
            DebugEntryTemplatePart de;
            // PageSource ps;
            for (int i = 0; i < parts.length; i++) {
                row++;
                de = parts[i];
                qryPart.setAt(KeyConstants._id, row, de.getId());
                qryPart.setAt(KeyConstants._count, row, _toString(de.getCount()));
                qryPart.setAt(KeyConstants._min, row, _toString(de.getMin()));
                qryPart.setAt(KeyConstants._max, row, _toString(de.getMax()));
                qryPart.setAt(KeyConstants._avg, row, _toString(de.getExeTime() / de.getCount()));
                qryPart.setAt(KeyConstants._start, row, _toString(de.getStartPosition()));
                qryPart.setAt(KeyConstants._end, row, _toString(de.getEndPosition()));
                qryPart.setAt(KeyConstants._total, row, _toString(de.getExeTime()));
                qryPart.setAt(KeyConstants._path, row, de.getPath());
                if (de instanceof DebugEntryTemplatePartImpl) {
                    qryPart.setAt(KeyConstants._startLine, row, _toString(((DebugEntryTemplatePartImpl) de).getStartLine()));
                    qryPart.setAt(KeyConstants._endLine, row, _toString(((DebugEntryTemplatePartImpl) de).getEndLine()));
                    qryPart.setAt(KeyConstants._snippet, row, ((DebugEntryTemplatePartImpl) de).getSnippet());
                }
            }
        } catch (PageException dbe) {
        }
    }
    // exceptions
    len = exceptions == null ? 0 : exceptions.size();
    Array arrExceptions = new ArrayImpl();
    if (len > 0) {
        Iterator<CatchBlock> it = exceptions.iterator();
        row = 0;
        while (it.hasNext()) {
            arrExceptions.appendEL(it.next());
        }
    }
    // output log
    // Query qryOutputLog=getOutputText();
    // timers
    len = timers == null ? 0 : timers.size();
    Query qryTimers = new QueryImpl(new Collection.Key[] { KeyConstants._label, KeyConstants._time, KeyConstants._template }, len, "timers");
    if (len > 0) {
        try {
            Iterator<DebugTimerImpl> it = timers.iterator();
            DebugTimer timer;
            row = 0;
            while (it.hasNext()) {
                timer = it.next();
                row++;
                qryTimers.setAt(KeyConstants._label, row, timer.getLabel());
                qryTimers.setAt(KeyConstants._template, row, timer.getTemplate());
                qryTimers.setAt(KeyConstants._time, row, Caster.toDouble(timer.getTime()));
            }
        } catch (PageException dbe) {
        }
    }
    // dumps
    len = dumps == null ? 0 : dumps.size();
    if (!((ConfigImpl) pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DUMP))
        len = 0;
    Query qryDumps = new QueryImpl(new Collection.Key[] { KeyConstants._output, KeyConstants._template, KeyConstants._line }, len, "dumps");
    if (len > 0) {
        try {
            Iterator<DebugDump> it = dumps.iterator();
            DebugDump dd;
            row = 0;
            while (it.hasNext()) {
                dd = it.next();
                row++;
                qryDumps.setAt(KeyConstants._output, row, dd.getOutput());
                if (!StringUtil.isEmpty(dd.getTemplate()))
                    qryDumps.setAt(KeyConstants._template, row, dd.getTemplate());
                if (dd.getLine() > 0)
                    qryDumps.setAt(KeyConstants._line, row, new Double(dd.getLine()));
            }
        } catch (PageException dbe) {
        }
    }
    // traces
    len = traces == null ? 0 : traces.size();
    if (!((ConfigImpl) pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_TRACING))
        len = 0;
    Query qryTraces = new QueryImpl(new Collection.Key[] { KeyConstants._type, KeyConstants._category, KeyConstants._text, KeyConstants._template, KeyConstants._line, KeyConstants._action, KeyConstants._varname, KeyConstants._varvalue, KeyConstants._time }, len, "traces");
    if (len > 0) {
        try {
            Iterator<DebugTraceImpl> it = traces.iterator();
            DebugTraceImpl trace;
            row = 0;
            while (it.hasNext()) {
                trace = it.next();
                row++;
                qryTraces.setAt(KeyConstants._type, row, DebugTraceImpl.toType(trace.getType(), "INFO"));
                if (!StringUtil.isEmpty(trace.getCategory()))
                    qryTraces.setAt(KeyConstants._category, row, trace.getCategory());
                if (!StringUtil.isEmpty(trace.getText()))
                    qryTraces.setAt(KeyConstants._text, row, trace.getText());
                if (!StringUtil.isEmpty(trace.getTemplate()))
                    qryTraces.setAt(KeyConstants._template, row, trace.getTemplate());
                if (trace.getLine() > 0)
                    qryTraces.setAt(KeyConstants._line, row, new Double(trace.getLine()));
                if (!StringUtil.isEmpty(trace.getAction()))
                    qryTraces.setAt(KeyConstants._action, row, trace.getAction());
                if (!StringUtil.isEmpty(trace.getVarName()))
                    qryTraces.setAt(KeyImpl.init("varname"), row, trace.getVarName());
                if (!StringUtil.isEmpty(trace.getVarValue()))
                    qryTraces.setAt(KeyImpl.init("varvalue"), row, trace.getVarValue());
                qryTraces.setAt(KeyConstants._time, row, new Double(trace.getTime()));
            }
        } catch (PageException dbe) {
        }
    }
    // scope access
    len = implicitAccesses == null ? 0 : implicitAccesses.size();
    Query qryImplicitAccesseses = new QueryImpl(new Collection.Key[] { KeyConstants._template, KeyConstants._line, KeyConstants._scope, KeyConstants._count, KeyConstants._name }, len, "implicitAccess");
    if (len > 0) {
        try {
            Iterator<ImplicitAccessImpl> it = implicitAccesses.values().iterator();
            ImplicitAccessImpl das;
            row = 0;
            while (it.hasNext()) {
                das = it.next();
                row++;
                qryImplicitAccesseses.setAt(KeyConstants._template, row, das.getTemplate());
                qryImplicitAccesseses.setAt(KeyConstants._line, row, new Double(das.getLine()));
                qryImplicitAccesseses.setAt(KeyConstants._scope, row, das.getScope());
                qryImplicitAccesseses.setAt(KeyConstants._count, row, new Double(das.getCount()));
                qryImplicitAccesseses.setAt(KeyConstants._name, row, das.getName());
            }
        } catch (PageException dbe) {
        }
    }
    Query history = new QueryImpl(new Collection.Key[] {}, 0, "history");
    try {
        history.addColumn(KeyConstants._id, historyId);
        history.addColumn(KeyConstants._level, historyLevel);
    } catch (PageException e) {
    }
    if (addAddionalInfo) {
        debugging.setEL(KeyConstants._cgi, pc.cgiScope());
        debugging.setEL(KeyImpl.init("starttime"), new DateTimeImpl(starttime, false));
        debugging.setEL(KeyConstants._id, pc.getId());
    }
    debugging.setEL(KeyConstants._pages, qryPage);
    debugging.setEL(PAGE_PARTS, qryPart);
    debugging.setEL(KeyConstants._queries, qryQueries);
    debugging.setEL(KeyConstants._timers, qryTimers);
    debugging.setEL(KeyConstants._traces, qryTraces);
    debugging.setEL("dumps", qryDumps);
    debugging.setEL(IMPLICIT_ACCESS, qryImplicitAccesseses);
    // debugging.setEL(OUTPUT_LOG,qryOutputLog);
    debugging.setEL(KeyConstants._history, history);
    debugging.setEL(KeyConstants._exceptions, arrExceptions);
    return debugging;
}
Also used : Query(lucee.runtime.type.Query) ArrayImpl(lucee.runtime.type.ArrayImpl) ArrayList(java.util.ArrayList) Struct(lucee.runtime.type.Struct) QueryImpl(lucee.runtime.type.QueryImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) PageException(lucee.runtime.exp.PageException) Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) CatchBlock(lucee.runtime.exp.CatchBlock) Collection(lucee.runtime.type.Collection) DatabaseException(lucee.runtime.exp.DatabaseException) ConfigImpl(lucee.runtime.config.ConfigImpl) Key(lucee.runtime.type.Collection.Key)

Example 37 with Array

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

the class DumpUtil method toArray2.

private static Array toArray2(List<PackageQuery> list) {
    Struct sct, _sct;
    Array arr = new ArrayImpl(), _arr;
    Iterator<PackageQuery> it = list.iterator();
    PackageQuery pd;
    Iterator<VersionDefinition> _it;
    VersionDefinition vd;
    while (it.hasNext()) {
        pd = it.next();
        sct = new StructImpl();
        sct.setEL(KeyConstants._package, pd.getName());
        sct.setEL("versions", _arr = new ArrayImpl());
        _it = pd.getVersionDefinitons().iterator();
        while (_it.hasNext()) {
            vd = _it.next();
            _sct = new StructImpl();
            _sct.setEL(KeyConstants._bundleVersion, vd.getVersion().toString());
            _sct.setEL("operator", vd.getOpAsString());
            _arr.appendEL(_sct);
        }
        arr.appendEL(sct);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) VersionDefinition(lucee.runtime.osgi.OSGiUtil.VersionDefinition) StructImpl(lucee.runtime.type.StructImpl) PackageQuery(lucee.runtime.osgi.OSGiUtil.PackageQuery) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

Example 38 with Array

use of lucee.runtime.type.Array 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;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) 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)

Example 39 with Array

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

the class Every method invoke.

private static boolean invoke(PageContext pc, StringListData sld, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws CasterException, PageException {
    Array arr = ListUtil.listToArray(sld.list, sld.delimiter, sld.includeEmptyFieldsx, sld.multiCharacterDelimiter);
    Iterator it = (arr instanceof ArrayPro ? ((ArrayPro) arr).entryArrayIterator() : arr.entryIterator());
    Entry e;
    boolean async = es != null;
    Object res;
    while (it.hasNext()) {
        e = (Entry) it.next();
        res = _inv(pc, udf, new Object[] { e.getValue(), Caster.toDoubleValue(e.getKey()), sld.list, sld.delimiter }, e.getKey(), e.getValue(), es, futures);
        if (!async && !Caster.toBooleanValue(res)) {
            return false;
        }
    }
    return true;
}
Also used : Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) ArrayPro(lucee.runtime.type.ArrayPro)

Example 40 with Array

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

the class Filter method invoke.

private static Array invoke(PageContext pc, Iterator it, UDF udf, ExecutorService es, List<Future<Data<Pair<Object, Object>>>> futures) throws PageException {
    Array rtn = new ArrayImpl();
    Object v;
    boolean async = es != null;
    Object res;
    int count = 0;
    ArgumentIntKey k;
    while (it.hasNext()) {
        v = it.next();
        k = ArgumentIntKey.init(++count);
        res = _inv(pc, udf, new Object[] { v }, k, v, es, futures);
        if (!async && Caster.toBooleanValue(res))
            rtn.append(v);
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Aggregations

Array (lucee.runtime.type.Array)169 ArrayImpl (lucee.runtime.type.ArrayImpl)79 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)25 Iterator (java.util.Iterator)24 PageException (lucee.runtime.exp.PageException)23 Entry (java.util.Map.Entry)22 ArrayList (java.util.ArrayList)20 Key (lucee.runtime.type.Collection.Key)20 ListIterator (java.util.ListIterator)16 Query (lucee.runtime.type.Query)16 List (java.util.List)14 ApplicationException (lucee.runtime.exp.ApplicationException)14 FunctionException (lucee.runtime.exp.FunctionException)14 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)14 Resource (lucee.commons.io.res.Resource)13 IOException (java.io.IOException)12 Collection (lucee.runtime.type.Collection)10 QueryImpl (lucee.runtime.type.QueryImpl)10 JavaObject (lucee.runtime.java.JavaObject)8