Search in sources :

Example 56 with Query

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

the class FeedQuery method toQuery.

public static Query toQuery(Struct data, boolean hasDC) throws DatabaseException {
    Query qry = new QueryImpl(hasDC ? COLUMNS_WITH_DC : COLUMNS, 0, "");
    String version = Caster.toString(data.get(VERSION, ""), "");
    Array items = null;
    if (StringUtil.startsWithIgnoreCase(version, "rss") || StringUtil.startsWithIgnoreCase(version, "rdf")) {
        items = Caster.toArray(data.get(ITEM, null), null);
        if (items == null) {
            Struct sct = Caster.toStruct(data.get(version, null), null, false);
            if (sct != null) {
                items = Caster.toArray(sct.get(ITEM, null), null);
            }
        }
        return toQuery(true, qry, items);
    } else if (StringUtil.startsWithIgnoreCase(version, "atom")) {
        items = Caster.toArray(data.get(ENTRY, null), null);
        return toQuery(false, qry, items);
    }
    return qry;
}
Also used : CastableArray(lucee.runtime.type.CastableArray) Array(lucee.runtime.type.Array) QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Struct(lucee.runtime.type.Struct)

Example 57 with Query

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

the class Admin method doGetBundles.

private void doGetBundles() throws PageException {
    CFMLEngine engine = ConfigWebUtil.getEngine(config);
    BundleCollection coreBundles = engine.getBundleCollection();
    java.util.Collection<BundleDefinition> extBundles = config.getAllExtensionBundleDefintions();
    List<BundleDefinition> bds = OSGiUtil.getBundleDefinitions(engine.getBundleContext());
    Iterator<BundleDefinition> it = bds.iterator();
    BundleDefinition bd;
    Bundle b;
    String str;
    Query qry = new QueryImpl(new Key[] { SYMBOLIC_NAME, KeyConstants._title, KeyConstants._description, KeyConstants._version, VENDOR, KeyConstants._state, PATH, USED_BY, KeyConstants._id, FRAGMENT, HEADERS }, bds.size(), "bundles");
    int row = 0;
    while (it.hasNext()) {
        row++;
        bd = it.next();
        b = bd.getLoadedBundle();
        qry.setAt(SYMBOLIC_NAME, row, bd.getName());
        qry.setAt(KeyConstants._title, row, bd.getName());
        qry.setAt(KeyConstants._version, row, bd.getVersionAsString());
        qry.setAt(USED_BY, row, _usedBy(bd.getName(), bd.getVersion(), coreBundles, extBundles));
        BundleFile bf = null;
        try {
            if (b != null) {
                qry.setAt(PATH, row, b.getLocation());
            } else {
                bf = bd.getBundleFile(false);
                qry.setAt(PATH, row, bf.getFile());
            }
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
        Map<String, Object> headers = null;
        if (b != null) {
            qry.setAt(KeyConstants._version, row, bd.getVersion().toString());
            qry.setAt(KeyConstants._id, row, b.getBundleId());
            qry.setAt(KeyConstants._state, row, OSGiUtil.toState(b.getState(), null));
            qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(b));
            headers = OSGiUtil.getHeaders(b);
        } else {
            qry.setAt(KeyConstants._state, row, "notinstalled");
            try {
                if (b != null) {
                    qry.setAt(KeyConstants._version, row, b.getVersion().toString());
                    qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(b));
                    Dictionary<String, String> dic = b.getHeaders();
                    Enumeration<String> keys = dic.keys();
                    headers = new HashMap<String, Object>();
                    String key;
                    while (keys.hasMoreElements()) {
                        key = keys.nextElement();
                        headers.put(key, dic.get(key));
                    }
                } else {
                    if (bf != null)
                        bf = bd.getBundleFile(false);
                    qry.setAt(KeyConstants._version, row, bf.getVersionAsString());
                    // qry.setAt(KeyConstants._id, row, bf.getBundleId());
                    qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(bf));
                    headers = bf.getHeaders();
                }
            } catch (BundleException e) {
            }
        }
        if (headers != null) {
            Struct h = Caster.toStruct(headers, false);
            qry.setAt(HEADERS, row, h);
            // title
            str = Caster.toString(h.get("Bundle-Title", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Implementation-Title", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Specification-Title", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Bundle-Name", null), null);
            if (!StringUtil.isEmpty(str))
                qry.setAt(KeyConstants._title, row, str);
            // description
            str = Caster.toString(h.get("Bundle-Description", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Implementation-Description", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Specification-Description", null), null);
            if (!StringUtil.isEmpty(str))
                qry.setAt(KeyConstants._description, row, str);
            // Vendor
            str = Caster.toString(h.get("Bundle-Vendor", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Implementation-Vendor", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Specification-Vendor", null), null);
            if (!StringUtil.isEmpty(str))
                qry.setAt(VENDOR, row, str);
        // Specification-Vendor,Bundle-Vendor
        }
    }
    QuerySort.call(pageContext, qry, "title");
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : Query(lucee.runtime.type.Query) Bundle(org.osgi.framework.Bundle) Struct(lucee.runtime.type.Struct) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) BundleCollection(lucee.loader.osgi.BundleCollection) QueryImpl(lucee.runtime.type.QueryImpl) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleException(org.osgi.framework.BundleException) BundleFile(lucee.runtime.osgi.BundleFile)

Example 58 with Query

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

the class Admin method doGetRemoteClients.

private void doGetRemoteClients() throws PageException {
    RemoteClient[] clients = config.getRemoteClients();
    RemoteClient client;
    ProxyData pd;
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "label", "usage", "securityKey", "adminPassword", "serverUsername", "serverPassword", "type", "url", "proxyServer", "proxyUsername", "proxyPassword", "proxyPort" }, clients.length, "query");
    int row = 0;
    for (int i = 0; i < clients.length; i++) {
        client = clients[i];
        pd = client.getProxyData();
        row = i + 1;
        qry.setAt("label", row, client.getLabel());
        qry.setAt("usage", row, client.getUsage());
        qry.setAt("securityKey", row, client.getSecurityKey());
        qry.setAt("adminPassword", row, client.getAdminPassword());
        qry.setAt("ServerUsername", row, client.getServerUsername());
        qry.setAt("ServerPassword", row, client.getServerPassword());
        qry.setAt("type", row, client.getType());
        qry.setAt("url", row, client.getUrl());
        qry.setAt("proxyServer", row, pd == null ? "" : pd.getServer());
        qry.setAt("proxyUsername", row, pd == null ? "" : pd.getUsername());
        qry.setAt("proxyPassword", row, pd == null ? "" : pd.getPassword());
        qry.setAt("proxyPort", row, pd == null ? "" : Caster.toString(pd.getPort()));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) ProxyData(lucee.runtime.net.proxy.ProxyData) RemoteClient(lucee.runtime.config.RemoteClient) Query(lucee.runtime.type.Query)

Example 59 with Query

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

the class Admin method doGetCacheConnections.

private void doGetCacheConnections() throws PageException {
    Map conns = config.getCacheConnections();
    Iterator it = conns.entrySet().iterator();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "class", "bundleName", "bundleVersion", "name", "custom", "default", "readOnly", "storage" }, 0, "connections");
    Map.Entry entry;
    CacheConnection cc;
    CacheConnection defObj = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_OBJECT);
    CacheConnection defTmp = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_TEMPLATE);
    CacheConnection defQry = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_QUERY);
    CacheConnection defRes = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_RESOURCE);
    CacheConnection defUDF = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_FUNCTION);
    CacheConnection defInc = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_INCLUDE);
    CacheConnection defHTT = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_HTTP);
    CacheConnection defFil = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_FILE);
    CacheConnection defWSe = config.getCacheDefaultConnection(ConfigImpl.CACHE_TYPE_WEBSERVICE);
    int row = 0;
    String def;
    while (it.hasNext()) {
        row++;
        entry = (Entry) it.next();
        cc = (CacheConnection) entry.getValue();
        qry.addRow();
        def = "";
        if (cc == defObj)
            def = "object";
        if (cc == defTmp)
            def = "template";
        if (cc == defQry)
            def = "query";
        if (cc == defRes)
            def = "resource";
        if (cc == defUDF)
            def = "function";
        if (cc == defInc)
            def = "include";
        if (cc == defHTT)
            def = "http";
        if (cc == defFil)
            def = "file";
        if (cc == defWSe)
            def = "webservice";
        qry.setAtEL(KeyConstants._class, row, cc.getClassDefinition().getClassName());
        qry.setAtEL(KeyConstants._bundleName, row, cc.getClassDefinition().getName());
        qry.setAtEL(KeyConstants._bundleVersion, row, cc.getClassDefinition().getVersionAsString());
        qry.setAtEL(KeyConstants._name, row, cc.getName());
        qry.setAtEL(KeyConstants._custom, row, cc.getCustom());
        qry.setAtEL(KeyConstants._default, row, def);
        qry.setAtEL(KeyConstants._readonly, row, Caster.toBoolean(cc.isReadOnly()));
        qry.setAtEL(KeyConstants._storage, row, Caster.toBoolean(cc.isStorage()));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : Entry(java.util.Map.Entry) QueryImpl(lucee.runtime.type.QueryImpl) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) CacheConnection(lucee.runtime.cache.CacheConnection) Query(lucee.runtime.type.Query)

Example 60 with Query

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

the class Admin method doGetDatasources.

/**
 * @throws PageException
 */
private void doGetDatasources() throws PageException {
    Map ds = config.getDataSourcesAsMap();
    Iterator it = ds.keySet().iterator();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "name", "host", "classname", "bundleName", "bundleVersion", "dsn", "DsnTranslated", "database", "port", "timezone", "username", "password", "passwordEncrypted", "readonly", "grant", "drop", "create", "revoke", "alter", "select", "delete", "update", "insert", "connectionLimit", "openConnections", "connectionTimeout", "clob", "blob", "validate", "storage", "customSettings", "metaCacheTimeout" }, ds.size(), "query");
    int row = 0;
    while (it.hasNext()) {
        Object key = it.next();
        DataSource d = (DataSource) ds.get(key);
        row++;
        qry.setAt(KeyConstants._name, row, key);
        qry.setAt(KeyConstants._host, row, d.getHost());
        qry.setAt("classname", row, d.getClassDefinition().getClassName());
        qry.setAt("bundleName", row, d.getClassDefinition().getName());
        qry.setAt("bundleVersion", row, d.getClassDefinition().getVersionAsString());
        qry.setAt("dsn", row, d.getDsnOriginal());
        qry.setAt("database", row, d.getDatabase());
        qry.setAt(KeyConstants._port, row, d.getPort() < 1 ? "" : Caster.toString(d.getPort()));
        qry.setAt("dsnTranslated", row, d.getDsnTranslated());
        qry.setAt("timezone", row, toStringTimeZone(d.getTimeZone()));
        qry.setAt(KeyConstants._password, row, d.getPassword());
        qry.setAt("passwordEncrypted", row, ConfigWebUtil.encrypt(d.getPassword()));
        qry.setAt(KeyConstants._username, row, d.getUsername());
        qry.setAt(KeyConstants._readonly, row, Caster.toBoolean(d.isReadOnly()));
        qry.setAt(KeyConstants._select, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_SELECT)));
        qry.setAt(KeyConstants._delete, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DELETE)));
        qry.setAt(KeyConstants._update, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_UPDATE)));
        qry.setAt(KeyConstants._create, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_CREATE)));
        qry.setAt(KeyConstants._insert, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
        qry.setAt(KeyConstants._drop, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DROP)));
        qry.setAt(KeyConstants._grant, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_GRANT)));
        qry.setAt(KeyConstants._revoke, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_REVOKE)));
        qry.setAt(KeyConstants._alter, row, Boolean.valueOf(d.hasAllow(DataSource.ALLOW_ALTER)));
        int oc = config.getDatasourceConnectionPool().openConnections(key.toString());
        qry.setAt("openConnections", row, oc < 0 ? 0 : oc);
        qry.setAt("connectionLimit", row, d.getConnectionLimit() < 1 ? "" : Caster.toString(d.getConnectionLimit()));
        qry.setAt("connectionTimeout", row, d.getConnectionTimeout() < 1 ? "" : Caster.toString(d.getConnectionTimeout()));
        qry.setAt("customSettings", row, d.getCustoms());
        qry.setAt("blob", row, Boolean.valueOf(d.isBlob()));
        qry.setAt("clob", row, Boolean.valueOf(d.isClob()));
        qry.setAt("validate", row, Boolean.valueOf(d.validate()));
        qry.setAt("storage", row, Boolean.valueOf(d.isStorage()));
        qry.setAt("metaCacheTimeout", row, Caster.toDouble(d.getMetaCacheTimeout()));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) Query(lucee.runtime.type.Query) DataSource(lucee.runtime.db.DataSource)

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