Search in sources :

Example 76 with Query

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

the class Caster method toQuery.

/**
 * cast a Object to a Query Object
 * @param o Object to cast
 * @param duplicate duplicate the object or not
 * @return casted Query Object
 * @throws PageException
 */
public static Query toQuery(Object o, boolean duplicate) throws PageException {
    if (o instanceof Query) {
        if (duplicate) {
            Query src = (Query) o;
            Query trg = new QueryImpl(src.getColumnNames(), src.getRowCount(), "query");
            Collection.Key[] keys = src.getColumnNames();
            QueryColumn[] columnsSrc = new QueryColumn[keys.length];
            for (int i = 0; i < columnsSrc.length; i++) {
                columnsSrc[i] = src.getColumn(keys[i]);
            }
            keys = trg.getColumnNames();
            QueryColumn[] columnsTrg = new QueryColumn[keys.length];
            for (int i = 0; i < columnsTrg.length; i++) {
                columnsTrg[i] = trg.getColumn(keys[i]);
            }
            int i;
            for (int row = trg.getRecordcount(); row > 0; row--) {
                for (i = 0; i < columnsTrg.length; i++) {
                    columnsTrg[i].set(row, columnsSrc[i].get(row, null));
                }
            }
            return trg;
        }
        return (Query) o;
    } else if (o instanceof ObjectWrap) {
        return toQuery(((ObjectWrap) o).getEmbededObject(), duplicate);
    }
    throw new CasterException(o, "query");
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) CasterException(lucee.runtime.exp.CasterException) ObjectWrap(lucee.runtime.type.ObjectWrap) Query(lucee.runtime.type.Query) QueryColumn(lucee.runtime.type.QueryColumn) Key(lucee.runtime.type.Collection.Key)

Example 77 with Query

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

the class DumpStruct method toCFML.

private static Struct toCFML(DumpTable dt, Object object, RefBoolean hasReference, Struct colors) {
    Struct sct = new StructImpl();
    if (colors == null) {
        colors = new StructImpl();
        sct.setEL("colors", colors);
    }
    Collection.Key type;
    if (dt.getType() != null)
        type = KeyImpl.init(dt.getType());
    else if (object != null)
        type = KeyImpl.init(object.getClass().getName());
    else
        type = KeyConstants._null;
    // colors
    String borderColor = toShortColor(dt.getBorderColor());
    String fontColor = toShortColor(dt.getFontColor());
    String highLightColor = toShortColor(dt.getHighLightColor());
    String normalColor = toShortColor(dt.getNormalColor());
    // create color id
    Key colorId = KeyImpl.init(Long.toString(HashUtil.create64BitHash(new StringBuilder(borderColor).append(':').append(fontColor).append(':').append(highLightColor).append(':').append(normalColor)), Character.MAX_RADIX));
    if (!colors.containsKey(colorId)) {
        Struct color = new StructImpl();
        StructUtil.setELIgnoreWhenNull(color, "borderColor", borderColor);
        StructUtil.setELIgnoreWhenNull(color, "fontColor", fontColor);
        StructUtil.setELIgnoreWhenNull(color, "highLightColor", highLightColor);
        StructUtil.setELIgnoreWhenNull(color, "normalColor", normalColor);
        colors.setEL(colorId, color);
    }
    /*StructUtil.setELIgnoreWhenNull(sct,"borderColor", borderColor);
		StructUtil.setELIgnoreWhenNull(sct,"fontColor", fontColor);
		StructUtil.setELIgnoreWhenNull(sct,"highLightColor", highLightColor);
		StructUtil.setELIgnoreWhenNull(sct,"normalColor", normalColor);
		*/
    StructUtil.setELIgnoreWhenNull(sct, "colorId", colorId.getString());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._comment, dt.getComment());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._height, dt.getHeight());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._width, dt.getWidth());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._title, dt.getTitle());
    sct.setEL(KeyConstants._type, type.getString());
    if (!StringUtil.isEmpty(dt.getId()))
        sct.setEL(KeyConstants._id, dt.getId());
    if ("ref".equals(dt.getType())) {
        hasReference.setValue(true);
        sct.setEL(KeyConstants._ref, dt.getRef());
    }
    DumpRow[] drs = dt.getRows();
    DumpRow dr;
    Query qry = null;
    DumpData[] items;
    for (int r = 0; r < drs.length; r++) {
        dr = drs[r];
        items = dr.getItems();
        if (qry == null)
            qry = new QueryImpl(toColumns(items), drs.length, "data");
        for (int c = 1; c <= items.length; c++) {
            qry.setAtEL("data" + c, r + 1, toCFML(items[c - 1], object, hasReference, colors));
        }
        qry.setAtEL("highlight", r + 1, new Double(dr.getHighlightType()));
    }
    if (qry != null)
        sct.setEL(KeyConstants._data, qry);
    return sct;
}
Also used : DumpRow(lucee.runtime.dump.DumpRow) Query(lucee.runtime.type.Query) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) DumpData(lucee.runtime.dump.DumpData) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) QueryImpl(lucee.runtime.type.QueryImpl) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) Key(lucee.runtime.type.Collection.Key)

Example 78 with Query

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

the class QueryConvertForGrid method call.

public static Struct call(PageContext pc, Query src, double dpage, double dpageSize) throws PageException {
    int page = (int) dpage;
    int pageSize = (int) dpageSize;
    if (page < 1) {
        throw new FunctionException(pc, "QueryConvertForGrid", 2, "page", "page must be a positive number now (" + page + ")");
    }
    int start = ((page - 1) * pageSize) + 1;
    int end = start + pageSize;
    Collection.Key[] srcColumns = src.getColumnNames();
    int srcRows = src.getRowCount();
    int trgRows = srcRows - start + 1;
    if (trgRows > pageSize)
        trgRows = pageSize;
    if (trgRows < 0)
        trgRows = 0;
    Query trg = new QueryImpl(srcColumns, trgRows, src.getName());
    int trgRow = 0;
    for (int srcRow = start; (srcRow <= end) && (srcRow <= srcRows); srcRow++) {
        trgRow++;
        for (int col = 0; col < srcColumns.length; col++) {
            trg.setAtEL(srcColumns[col], trgRow, src.getAt(srcColumns[col], srcRow, null));
        }
    }
    Struct sct = new StructImpl();
    sct.setEL(KeyConstants._QUERY, trg);
    sct.setEL("TOTALROWCOUNT", new Integer(srcRows));
    return sct;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) StructImpl(lucee.runtime.type.StructImpl) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct)

Example 79 with Query

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

the class QuerySlice method get.

private static Query get(Query qry, int from, int to) throws PageException {
    Collection.Key[] columns;
    // print.out(from+"::"+to);
    Query nq = new QueryImpl(columns = qry.getColumnNames(), 0, qry.getName());
    int row = 1;
    for (int i = from; i <= to; i++) {
        nq.addRow();
        for (int y = 0; y < columns.length; y++) {
            nq.setAt(columns[y], row, qry.getAt(columns[y], i));
        }
        row++;
    }
    return nq;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query)

Example 80 with Query

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

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