use of lucee.runtime.type.Query in project Lucee by lucee.
the class Some method _call.
public static boolean _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Object>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Object>>>();
}
boolean res;
// Array
if (type == TYPE_ARRAY) {
res = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
res = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (type == TYPE_STRUCT) {
res = invoke(pc, (Struct) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
res = invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
res = invoke(pc, (Query) obj, udf, execute, futures);
} else // Struct
if (obj instanceof Struct) {
res = invoke(pc, (Struct) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
res = invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof java.util.Map) {
res = invoke(pc, (java.util.Map) obj, udf, execute, futures);
} else // List
if (obj instanceof List) {
res = invoke(pc, (List) obj, udf, execute, futures);
} else // Iterator
if (obj instanceof Iterator) {
res = invoke(pc, (Iterator) obj, udf, execute, futures);
} else // Enumeration
if (obj instanceof Enumeration) {
res = invoke(pc, (Enumeration) obj, udf, execute, futures);
} else // String List
if (obj instanceof StringListData) {
res = invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Some", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
res = afterCall(pc, futures, execute);
return res;
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class VariableReference method touchEL.
@Override
public Object touchEL(PageContext pc) {
Object o;
if (coll instanceof Query) {
o = ((Query) coll).getColumn(key, null);
if (o != null)
return o;
return setEL(pc, new StructImpl());
}
o = coll.get(key, null);
if (o != null)
return o;
return setEL(pc, new StructImpl());
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class IKHandlerDatasource method loadData.
@Override
public IKStorageValue loadData(PageContext pc, String appName, String name, String strType, int type, Log log) throws PageException {
ConfigImpl config = (ConfigImpl) ThreadLocalPageContext.getConfig(pc);
DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
DatasourceConnection dc = pool.getDatasourceConnection(config, pc.getDataSource(name), null, null);
SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
Query query;
try {
if (!dc.getDatasource().isStorage())
throw new ApplicationException("storage usage for this datasource is disabled, you can enable this in the Lucee administrator.");
query = executor.select(config, pc.getCFID(), pc.getApplicationContext().getName(), dc, type, log, true);
} catch (SQLException se) {
throw Caster.toPageException(se);
} finally {
if (dc != null)
pool.releaseDatasourceConnection(dc);
}
if (query != null && config.debug()) {
boolean debugUsage = DebuggerUtil.debugQueryUsage(pc, query);
pc.getDebugger().addQuery(debugUsage ? query : null, name, "", query.getSql(), query.getRecordcount(), ((PageContextImpl) pc).getCurrentPageSource(null), query.getExecutionTime());
}
boolean _isNew = query.getRecordcount() == 0;
if (_isNew) {
ScopeContext.info(log, "create new " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID() + " in datasource [" + name + "]");
return null;
}
String str = Caster.toString(query.getAt(KeyConstants._data, 1));
if (str.startsWith("struct:"))
return null;
try {
IKStorageValue data = (IKStorageValue) JavaConverter.deserialize(str);
ScopeContext.info(log, "load existing data from [" + name + "." + PREFIX + "_" + strType + "_data] to create " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
return data;
} catch (Exception e) {
ScopeContext.error(log, e);
return null;
// throw Caster.toPageException(e);
}
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class StorageScopeDatasource method _loadData.
protected static Struct _loadData(PageContext pc, String datasourceName, String strType, int type, Log log, boolean mxStyle) throws PageException {
ConfigImpl config = (ConfigImpl) ThreadLocalPageContext.getConfig(pc);
DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
DatasourceConnection dc = pool.getDatasourceConnection(config, pc.getDataSource(datasourceName), null, null);
SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
Query query;
try {
if (!dc.getDatasource().isStorage())
throw new ApplicationException("storage usage for this datasource is disabled, you can enable this in the Lucee administrator.");
query = executor.select(config, pc.getCFID(), pc.getApplicationContext().getName(), dc, type, log, true);
} catch (SQLException se) {
throw Caster.toPageException(se);
} finally {
if (dc != null)
pool.releaseDatasourceConnection(dc);
}
if (query != null && config.debug()) {
boolean debugUsage = DebuggerUtil.debugQueryUsage(pc, query);
pc.getDebugger().addQuery(debugUsage ? query : null, datasourceName, "", query.getSql(), query.getRecordcount(), ((PageContextImpl) pc).getCurrentPageSource(null), query.getExecutionTime());
}
boolean _isNew = query.getRecordcount() == 0;
if (_isNew) {
ScopeContext.info(log, "create new " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID() + " in datasource [" + datasourceName + "]");
return null;
}
String str = Caster.toString(query.get(KeyConstants._data));
if (str != null && str.startsWith("struct:"))
str = str.substring(7);
if (mxStyle)
return null;
try {
Struct s = (Struct) pc.evaluate(str);
ScopeContext.info(log, "load existing data from [" + datasourceName + "." + PREFIX + "_" + strType + "_data] to create " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
return s;
} catch (Exception e) {
ScopeContext.error(log, e);
return null;
}
}
use of lucee.runtime.type.Query in project Lucee by lucee.
the class Ansi92 method clean.
@Override
public void clean(Config config, DatasourceConnection dc, int type, StorageScopeEngine engine, DatasourceStorageScopeCleaner cleaner, StorageScopeListener listener, Log log) throws PageException {
String strType = VariableInterpreter.scopeInt2String(type);
// select
SQL sqlSelect = new SQLImpl("select cfid,name from " + PREFIX + "_" + strType + "_data where expires<=?", new SQLItem[] { new SQLItemImpl(System.currentTimeMillis(), Types.VARCHAR) });
Query query;
try {
query = new QueryImpl(ThreadLocalPageContext.get(), dc, sqlSelect, -1, -1, null, "query");
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
// possible that the table not exist, if not there is nothing to clean
return;
}
int recordcount = query.getRecordcount();
String cfid, name;
for (int row = 1; row <= recordcount; row++) {
cfid = Caster.toString(query.getAt(KeyConstants._cfid, row, null), null);
name = Caster.toString(query.getAt(KeyConstants._name, row, null), null);
if (listener != null)
listener.doEnd(engine, cleaner, name, cfid);
ScopeContext.info(log, "remove " + strType + "/" + name + "/" + cfid + " from datasource " + dc.getDatasource().getName());
engine.remove(type, name, cfid);
SQLImpl sql = new SQLImpl("delete from " + StorageScopeDatasource.PREFIX + "_" + strType + "_data where cfid=? and name=?", new SQLItem[] { new SQLItemImpl(cfid, Types.VARCHAR), new SQLItemImpl(name, Types.VARCHAR) });
new QueryImpl(ThreadLocalPageContext.get(), dc, sql, -1, -1, null, "query");
}
}
Aggregations