Search in sources :

Example 71 with Query

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

the class Filter method _call.

public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
    ExecutorService execute = null;
    List<Future<Data<Pair<Object, Object>>>> futures = null;
    if (parallel) {
        execute = Executors.newFixedThreadPool(maxThreads);
        futures = new ArrayList<Future<Data<Pair<Object, Object>>>>();
    }
    Collection coll;
    // Array
    if (type == TYPE_ARRAY) {
        coll = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (type == TYPE_QUERY) {
        coll = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (type == TYPE_STRUCT) {
        coll = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // Array
    if (obj instanceof Array) {
        coll = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (obj instanceof Query) {
        coll = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (obj instanceof Struct) {
        coll = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // other Iteratorable
    if (obj instanceof Iteratorable) {
        coll = invoke(pc, (Iteratorable) obj, udf, execute, futures);
    } else // Map
    if (obj instanceof java.util.Map) {
        coll = invoke(pc, (java.util.Map) obj, udf, execute, futures);
    } else // List
    if (obj instanceof List) {
        coll = invoke(pc, (List) obj, udf, execute, futures);
    } else // Iterator
    if (obj instanceof Iterator) {
        coll = invoke(pc, (Iterator) obj, udf, execute, futures);
    } else // Enumeration
    if (obj instanceof Enumeration) {
        coll = invoke(pc, (Enumeration) obj, udf, execute, futures);
    } else // String List
    if (obj instanceof StringListData) {
        coll = invoke(pc, (StringListData) obj, udf, execute, futures);
    } else
        throw new FunctionException(pc, "Filter", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
    if (parallel)
        afterCall(pc, coll, futures, execute);
    return coll;
}
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) Collection(lucee.runtime.type.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Pair(lucee.commons.lang.Pair)

Example 72 with Query

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

the class MailClient method listAllFolder.

public Query listAllFolder(String folderName, boolean recurse, int startrow, int maxrows) throws MessagingException, PageException {
    Query qry = new QueryImpl(new Collection.Key[] { FULLNAME, KeyConstants._NAME, TOTALMESSAGES, UNREAD, PARENT, NEW }, 0, "folders");
    // if(StringUtil.isEmpty(folderName)) folderName="INBOX";
    Folder folder = (StringUtil.isEmpty(folderName)) ? _store.getDefaultFolder() : _store.getFolder(folderName);
    // Folder folder=_store.getFolder(folderName);
    if (!folder.exists())
        throw new ApplicationException("there is no folder with name [" + folderName + "].");
    list(folder, qry, recurse, startrow, maxrows, 0);
    return qry;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) ApplicationException(lucee.runtime.exp.ApplicationException) Query(lucee.runtime.type.Query) Collection(lucee.runtime.type.Collection) Folder(javax.mail.Folder)

Example 73 with Query

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

the class MailClient method getMails.

/**
 * return all messages from inbox
 * @param messageNumbers all messages with this ids
 * @param uIds all messages with this uids
 * @param withBody also return body
 * @return all messages from inbox
 * @throws MessagingException
 * @throws IOException
 */
public Query getMails(String[] messageNumbers, String[] uids, boolean all) throws MessagingException, IOException {
    Query qry = new QueryImpl(all ? _fldnew : _flddo, 0, "query");
    Folder folder = _store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);
    try {
        getMessages(qry, folder, uids, messageNumbers, startrow, maxrows, all);
    } finally {
        folder.close(false);
    }
    return qry;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Folder(javax.mail.Folder)

Example 74 with Query

use of lucee.runtime.type.Query 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;
}
Also used : Entry(java.util.Map.Entry) Query(lucee.runtime.type.Query) Calendar(java.util.Calendar) Date(java.util.Date) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) QueryColumn(lucee.runtime.type.QueryColumn) Iterator(java.util.Iterator) Map(java.util.Map)

Example 75 with Query

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

the class GetUsageData method call.

public static Struct call(PageContext pc) throws PageException {
    ConfigWeb cw = pc.getConfig();
    ConfigServer cs = cw.getConfigServer("server");
    ConfigWeb[] webs = cs.getConfigWebs();
    CFMLEngineFactory.getInstance();
    CFMLEngineImpl engine = (CFMLEngineImpl) cs.getCFMLEngine();
    Struct sct = new StructImpl();
    // Locks
    /*LockManager manager = pc.getConfig().getLockManager();
        String[] locks = manager.getOpenLockNames();
        for(int i=0;i<locks.length;i++){
        	locks[i].
        }
        if(!ArrayUtil.isEmpty(locks)) 
        	strLocks=" open locks at this time ("+List.arrayToList(locks, ", ")+").";
		*/
    // Requests
    Query req = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._uri, START_TIME, KeyConstants._timeout }, 0, "requests");
    sct.setEL(KeyConstants._requests, req);
    // Template Cache
    Query tc = new QueryImpl(new Collection.Key[] { KeyConstants._web, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    sct.setEL(KeyImpl.init("templateCache"), tc);
    // Scopes
    Struct scopes = new StructImpl();
    sct.setEL(KeyConstants._scopes, scopes);
    Query app = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    scopes.setEL(KeyConstants._application, app);
    Query sess = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, USERS, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    scopes.setEL(KeyConstants._session, sess);
    // Query
    Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, START_TIME, KeyConstants._sql }, 0, "requests");
    sct.setEL(QUERIES, qry);
    // Locks
    Query lck = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, KeyConstants._name, START_TIME, KeyConstants._timeout, KeyConstants._type }, 0, "requests");
    sct.setEL(LOCKS, lck);
    // Loop webs
    ConfigWebImpl web;
    Map<Integer, PageContextImpl> pcs;
    PageContextImpl _pc;
    int row, openConnections = 0;
    CFMLFactoryImpl factory;
    ActiveQuery[] queries;
    ActiveQuery aq;
    ActiveLock[] locks;
    ActiveLock al;
    for (int i = 0; i < webs.length; i++) {
        // Loop requests
        web = (ConfigWebImpl) webs[i];
        factory = (CFMLFactoryImpl) web.getFactory();
        pcs = factory.getActivePageContexts();
        Iterator<PageContextImpl> it = pcs.values().iterator();
        while (it.hasNext()) {
            _pc = it.next();
            if (_pc.isGatewayContext())
                continue;
            // Request
            row = req.addRow();
            req.setAt(KeyConstants._web, row, web.getLabel());
            req.setAt(KeyConstants._uri, row, getPath(_pc.getHttpServletRequest()));
            req.setAt(START_TIME, row, new DateTimeImpl(pc.getStartTime(), false));
            req.setAt(KeyConstants._timeout, row, new Double(pc.getRequestTimeout()));
            // Query
            queries = _pc.getActiveQueries();
            if (queries != null) {
                for (int y = 0; y < queries.length; y++) {
                    aq = queries[y];
                    row = qry.addRow();
                    qry.setAt(KeyConstants._web, row, web.getLabel());
                    qry.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
                    qry.setAt(START_TIME, row, new DateTimeImpl(web, aq.startTime, true));
                    qry.setAt(KeyConstants._sql, row, aq.sql);
                }
            }
            // Lock
            locks = _pc.getActiveLocks();
            if (locks != null) {
                for (int y = 0; y < locks.length; y++) {
                    al = locks[y];
                    row = lck.addRow();
                    lck.setAt(KeyConstants._web, row, web.getLabel());
                    lck.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
                    lck.setAt(KeyConstants._name, row, al.name);
                    lck.setAt(START_TIME, row, new DateTimeImpl(web, al.startTime, true));
                    lck.setAt(KeyConstants._timeout, row, Caster.toDouble(al.timeoutInMillis / 1000));
                    lck.setAt(KeyConstants._type, row, al.type == LockManager.TYPE_EXCLUSIVE ? "exclusive" : "readonly");
                }
            }
        }
        Iterator<Integer> _it = web.getDatasourceConnectionPool().openConnections().values().iterator();
        while (_it.hasNext()) {
            openConnections += _it.next().intValue();
        }
        // Template Cache
        Mapping[] mappings = ConfigWebUtil.getAllMappings(web);
        long[] tce = templateCacheElements(mappings);
        row = tc.addRow();
        tc.setAt(KeyConstants._web, row, web.getLabel());
        tc.setAt(KeyConstants._size, row, new Double(tce[1]));
        tc.setAt(ELEMENTS, row, new Double(tce[0]));
        // Scope Application
        getAllApplicationScopes(web, factory.getScopeContext(), app);
        getAllCFSessionScopes(web, factory.getScopeContext(), sess);
    }
    // Datasource
    Struct ds = new StructImpl();
    sct.setEL(KeyConstants._datasources, ds);
    // there is only one cache for all contexts
    ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null).size(pc)));
    // ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getQueryCache().size(pc))); // there is only one cache for all contexts
    ds.setEL(OPEN_CONNECTIONS, Caster.toDouble(openConnections));
    // Memory
    Struct mem = new StructImpl();
    sct.setEL(KeyConstants._memory, mem);
    mem.setEL("heap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_HEAP));
    mem.setEL("nonheap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_NON_HEAP));
    // uptime
    sct.set("uptime", new DateTimeImpl(engine.uptime(), true));
    // now
    sct.set("now", new DateTimeImpl(pc));
    return sct;
}
Also used : ActiveQuery(lucee.runtime.debug.ActiveQuery) Query(lucee.runtime.type.Query) Mapping(lucee.runtime.Mapping) Struct(lucee.runtime.type.Struct) QueryImpl(lucee.runtime.type.QueryImpl) ActiveLock(lucee.runtime.debug.ActiveLock) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigServer(lucee.runtime.config.ConfigServer) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) StructImpl(lucee.runtime.type.StructImpl) ActiveQuery(lucee.runtime.debug.ActiveQuery) Collection(lucee.runtime.type.Collection)

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