use of lucee.runtime.type.QueryColumn in project Lucee by lucee.
the class QoQ method executeSingle.
private void executeSingle(PageContext pc, Select select, Query qr, QueryImpl target, int maxrows, SQL sql, boolean hasOrders) throws PageException {
ValueNumber oTop = select.getTop();
if (oTop != null) {
int top = (int) oTop.getValueAsDouble();
if (maxrows == -1 || maxrows > top)
maxrows = top;
}
int recCount = qr.getRecordcount();
Expression[] expSelects = select.getSelects();
int selCount = expSelects.length;
Map<Collection.Key, Object> selects = new HashMap<Collection.Key, Object>();
Iterator<Key> it;
Key k;
// headers
for (int i = 0; i < selCount; i++) {
Expression expSelect = expSelects[i];
if (expSelect.getAlias().equals("*")) {
it = qr.keyIterator();
while (it.hasNext()) {
k = it.next();
selects.put(k, k);
queryAddColumn(target, k, qr.getColumn(k).getType());
}
} else {
Key alias = Caster.toKey(expSelect.getAlias());
selects.put(alias, expSelect);
int type = Types.OTHER;
if (expSelect instanceof ColumnExpression)
type = qr.getColumn(Caster.toKey(((ColumnExpression) expSelect).getColumnName())).getType();
queryAddColumn(target, alias, type);
}
}
Collection.Key[] headers = selects.keySet().toArray(new Collection.Key[selects.size()]);
// loop records
Operation where = select.getWhere();
boolean hasMaxrow = maxrows > -1 && !hasOrders;
// get target columns
QueryColumn[] trgColumns = new QueryColumn[headers.length];
Object[] trgValues = new Object[headers.length];
for (int cell = 0; cell < headers.length; cell++) {
trgColumns[cell] = target.getColumn(headers[cell]);
trgValues[cell] = selects.get(headers[cell]);
}
for (int row = 1; row <= recCount; row++) {
sql.setPosition(0);
if (hasMaxrow && maxrows <= target.getRecordcount())
break;
boolean useRow = where == null || Caster.toBooleanValue(executeExp(pc, sql, qr, where, row));
if (useRow) {
target.addRow(1);
for (int cell = 0; cell < headers.length; cell++) {
// Object value = selects.get(headers[cell]);
trgColumns[cell].set(target.getRecordcount(), getValue(pc, sql, qr, row, headers[cell], trgValues[cell]));
/*target.setAt(
headers[cell],
target.getRecordcount(),
getValue(pc,sql,qr,row,headers[cell],trgValues[cell])
);*/
}
}
}
// Group By
if (select.getGroupbys().length > 0)
throw new DatabaseException("group by are not supported at the moment", null, sql, null);
if (select.getHaving() != null)
throw new DatabaseException("having is not supported at the moment", null, sql, null);
}
use of lucee.runtime.type.QueryColumn in project Lucee by lucee.
the class DebugEntryTemplatePartComparator method getUsage.
private static Struct getUsage(QueryEntry qe) throws PageException {
Query qry = qe.getQry();
QueryColumn c;
DebugQueryColumn dqc;
outer: if (qry != null) {
Struct usage = null;
Collection.Key[] columnNames = qry.getColumnNames();
Collection.Key columnName;
for (int i = 0; i < columnNames.length; i++) {
columnName = columnNames[i];
c = qry.getColumn(columnName);
if (!(c instanceof DebugQueryColumn))
break outer;
dqc = (DebugQueryColumn) c;
if (usage == null)
usage = new StructImpl();
usage.setEL(columnName, Caster.toBoolean(dqc.isUsed()));
}
return usage;
}
return null;
}
use of lucee.runtime.type.QueryColumn in project Lucee by lucee.
the class JavaProxy method _toCFML.
public static Object _toCFML(Object value) throws PageException {
if (value instanceof Date || value instanceof Calendar) {
// do not change to caster.isDate
return Caster.toDate(value, null);
}
if (value instanceof Object[]) {
Object[] arr = (Object[]) value;
if (!ArrayUtil.isEmpty(arr)) {
boolean allTheSame = true;
// byte
if (arr[0] instanceof Byte) {
for (int i = 1; i < arr.length; i++) {
if (!(arr[i] instanceof Byte)) {
allTheSame = false;
break;
}
}
if (allTheSame) {
byte[] bytes = new byte[arr.length];
for (int i = 0; i < arr.length; i++) {
bytes[i] = Caster.toByteValue(arr[i]);
}
return bytes;
}
}
}
}
if (value instanceof Byte[]) {
Byte[] arr = (Byte[]) value;
if (!ArrayUtil.isEmpty(arr)) {
byte[] bytes = new byte[arr.length];
for (int i = 0; i < arr.length; i++) {
bytes[i] = arr[i].byteValue();
}
return bytes;
}
}
if (value instanceof byte[]) {
return value;
}
if (Decision.isArray(value)) {
Array a = Caster.toArray(value);
int len = a.size();
Object o;
for (int i = 1; i <= len; i++) {
o = a.get(i, null);
if (o != null)
a.setEL(i, toCFML(o));
}
return a;
}
if (value instanceof Map) {
Struct sct = new StructImpl();
Iterator it = ((Map) value).entrySet().iterator();
Map.Entry entry;
while (it.hasNext()) {
entry = (Entry) it.next();
sct.setEL(Caster.toString(entry.getKey()), toCFML(entry.getValue()));
}
return sct;
// return StructUtil.copyToStruct((Map)value);
}
if (Decision.isQuery(value)) {
Query q = Caster.toQuery(value);
int recorcount = q.getRecordcount();
String[] strColumns = q.getColumns();
QueryColumn col;
int row;
for (int i = 0; i < strColumns.length; i++) {
col = q.getColumn(strColumns[i]);
for (row = 1; row <= recorcount; row++) {
col.set(row, toCFML(col.get(row, null)));
}
}
return q;
}
return value;
}
use of lucee.runtime.type.QueryColumn 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");
}
Aggregations