Search in sources :

Example 81 with QueryImpl

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

the class Query_ method call.

public static Query call(PageContext pc, Object[] arr) throws DatabaseException {
    String[] names = new String[arr.length];
    Array[] columns = new Array[arr.length];
    int count = 0;
    for (int i = 0; i < arr.length; i++) {
        if (arr[i] instanceof FunctionValue) {
            FunctionValue vf = (FunctionValue) arr[i];
            if (vf.getValue() instanceof Array) {
                names[count] = vf.getNameAsString();
                columns[count] = (Array) vf.getValue();
                count++;
            } else
                throw new DatabaseException("invalid argument for function query, only array as value are allowed", "example: query(column1:array(1,2,3))", null, null);
        } else
            throw new DatabaseException("invalid argument for function query, only named argument are allowed", "example: query(column1:array(1,2,3))", null, null);
    }
    Query query = new QueryImpl(names, columns, "query");
    return query;
}
Also used : Array(lucee.runtime.type.Array) QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) FunctionValue(lucee.runtime.type.FunctionValue) DatabaseException(lucee.runtime.exp.DatabaseException)

Example 82 with QueryImpl

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

the class MacAddressWrap method getMemoryUsageAsQuery.

public static Query getMemoryUsageAsQuery(int type) throws DatabaseException {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();
    Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._name, KeyConstants._type, KeyConstants._used, KeyConstants._max, KeyConstants._init }, 0, "memory");
    int row = 0;
    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    while (it.hasNext()) {
        bean = it.next();
        usage = bean.getUsage();
        _type = bean.getType();
        if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP)
            continue;
        if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP)
            continue;
        row++;
        qry.addRow();
        qry.setAtEL(KeyConstants._name, row, bean.getName());
        qry.setAtEL(KeyConstants._type, row, _type.name());
        qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
        qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
        qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
    }
    return qry;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Collection(lucee.runtime.type.Collection) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) MemoryType(java.lang.management.MemoryType)

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