Search in sources :

Example 26 with Query

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;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with Query

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());
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Query(lucee.runtime.type.Query)

Example 28 with Query

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);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) DatasourceConnectionPool(lucee.runtime.db.DatasourceConnectionPool) DatasourceConnection(lucee.runtime.db.DatasourceConnection) Query(lucee.runtime.type.Query) SQLExecutor(lucee.runtime.type.scope.storage.db.SQLExecutor) SQLException(java.sql.SQLException) ConfigImpl(lucee.runtime.config.ConfigImpl) SQLException(java.sql.SQLException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException)

Example 29 with Query

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;
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) DatasourceConnectionPool(lucee.runtime.db.DatasourceConnectionPool) DatasourceConnection(lucee.runtime.db.DatasourceConnection) Query(lucee.runtime.type.Query) SQLExecutor(lucee.runtime.type.scope.storage.db.SQLExecutor) SQLException(java.sql.SQLException) ConfigImpl(lucee.runtime.config.ConfigImpl) SQLException(java.sql.SQLException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException) Struct(lucee.runtime.type.Struct)

Example 30 with Query

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");
    }
}
Also used : SQLImpl(lucee.runtime.db.SQLImpl) QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) SQLItemImpl(lucee.runtime.db.SQLItemImpl) SQL(lucee.runtime.db.SQL)

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