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");
}
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;
}
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;
}
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;
}
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;
}
Aggregations