Search in sources :

Example 76 with QueryImpl

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

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

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

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

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

the class QuerySort method _call.

public static boolean _call(PageContext pc, Query query, UDF udf) throws PageException {
    int recordcount = query.getRecordcount();
    Key[] columns = query.getColumnNames();
    QueryRow[] rows = new QueryRow[recordcount];
    Struct sct;
    Object empty = NullSupportHelper.full() ? null : "";
    for (int row = 1; row <= recordcount; row++) {
        sct = new StructImpl();
        for (int col = 0; col < columns.length; col++) {
            sct.setEL(columns[col], query.getAt(columns[col], row, empty));
        }
        rows[row - 1] = new QueryRow(query, row, sct);
    }
    Arrays.sort(rows, new QueryRowComparator(pc, udf));
    ((QueryImpl) query).sort(toInt(rows));
    return true;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) StructImpl(lucee.runtime.type.StructImpl) Key(lucee.runtime.type.Collection.Key) Struct(lucee.runtime.type.Struct)

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