Search in sources :

Example 51 with QueryImpl

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

the class Schedule method doList.

/**
 * @throws PageException
 */
private void doList() throws PageException {
    // if(tr ue) throw new PageRuntimeException("qqq");
    ScheduleTask[] tasks = scheduler.getAllScheduleTasks();
    final String v = "VARCHAR";
    String[] cols = new String[] { "task", "path", "file", "startdate", "starttime", "enddate", "endtime", "url", "port", "interval", "timeout", "username", "password", "proxyserver", "proxyport", "proxyuser", "proxypassword", "resolveurl", "publish", "valid", "paused", "autoDelete" };
    String[] types = new String[] { v, v, v, "DATE", "OTHER", "DATE", "OTHER", v, v, v, v, v, v, v, v, v, v, v, "BOOLEAN", v, "BOOLEAN", "BOOLEAN" };
    lucee.runtime.type.Query query = new QueryImpl(cols, types, tasks.length, "query");
    try {
        for (int i = 0; i < tasks.length; i++) {
            int row = i + 1;
            ScheduleTask task = tasks[i];
            query.setAt(KeyConstants._task, row, task.getTask());
            if (task.getResource() != null) {
                query.setAt(KeyConstants._path, row, task.getResource().getParent());
                query.setAt(KeyConstants._file, row, task.getResource().getName());
            }
            query.setAt("publish", row, Caster.toBoolean(task.isPublish()));
            query.setAt("startdate", row, task.getStartDate());
            query.setAt("starttime", row, task.getStartTime());
            query.setAt("enddate", row, task.getEndDate());
            query.setAt("endtime", row, task.getEndTime());
            query.setAt(KeyConstants._url, row, printUrl(task.getUrl()));
            query.setAt(KeyConstants._port, row, Caster.toString(HTTPUtil.getPort(task.getUrl())));
            query.setAt("interval", row, task.getStringInterval());
            query.setAt("timeout", row, Caster.toString(task.getTimeout() / 1000));
            query.setAt("valid", row, Caster.toString(task.isValid()));
            if (task.hasCredentials()) {
                query.setAt("username", row, task.getCredentials().getUsername());
                query.setAt("password", row, task.getCredentials().getPassword());
            }
            ProxyData pd = task.getProxyData();
            if (ProxyDataImpl.isValid(pd)) {
                query.setAt("proxyserver", row, pd.getServer());
                if (pd.getPort() > 0)
                    query.setAt("proxyport", row, Caster.toString(pd.getPort()));
                if (ProxyDataImpl.hasCredentials(pd)) {
                    query.setAt("proxyuser", row, pd.getUsername());
                    query.setAt("proxypassword", row, pd.getPassword());
                }
            }
            query.setAt("resolveurl", row, Caster.toString(task.isResolveURL()));
            query.setAt("paused", row, Caster.toBoolean(task.isPaused()));
            query.setAt("autoDelete", row, Caster.toBoolean(((ScheduleTaskImpl) task).isAutoDelete()));
        }
        pageContext.setVariable(result, query);
    } catch (DatabaseException e) {
    }
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) ProxyData(lucee.runtime.net.proxy.ProxyData) ScheduleTaskImpl(lucee.runtime.schedule.ScheduleTaskImpl) ScheduleTask(lucee.runtime.schedule.ScheduleTask) DatabaseException(lucee.runtime.exp.DatabaseException)

Example 52 with QueryImpl

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

the class Ansi92 method select.

@Override
public Query select(Config config, String cfid, String applicationName, DatasourceConnection dc, int type, Log log, boolean createTableIfNotExist) throws PageException {
    String strType = VariableInterpreter.scopeInt2String(type);
    Query query = null;
    SQL sqlSelect = new SQLImpl("select data from " + PREFIX + "_" + strType + "_data where cfid=? and name=? and expires > ?", new SQLItem[] { new SQLItemImpl(cfid, Types.VARCHAR), new SQLItemImpl(applicationName, Types.VARCHAR), new SQLItemImpl(now(config), Types.VARCHAR) });
    PageContext pc = ThreadLocalPageContext.get();
    try {
        query = new QueryImpl(pc, dc, sqlSelect, -1, -1, null, "query");
    } catch (DatabaseException de) {
        if (dc == null || !createTableIfNotExist)
            throw de;
        // table does not exist???
        try {
            SQL sql = createSQL(dc, DataSourceUtil.isMySQL(dc) ? "longtext" : "ntext", strType);
            ScopeContext.info(log, sql.toString());
            new QueryImpl(pc, dc, sql, -1, -1, null, "query");
        } catch (DatabaseException _de) {
            // don't like "ntext", try text
            try {
                SQL sql = createSQL(dc, "text", strType);
                ScopeContext.info(log, sql.toString());
                new QueryImpl(pc, dc, sql, -1, -1, null, "query");
            } catch (DatabaseException __de) {
                // don't like text, try "memo"
                try {
                    SQL sql = createSQL(dc, "memo", strType);
                    ScopeContext.info(log, sql.toString());
                    new QueryImpl(pc, dc, sql, -1, -1, null, "query");
                } catch (DatabaseException ___de) {
                    // don't like "memo", try clob
                    try {
                        SQL sql = createSQL(dc, "clob", strType);
                        ScopeContext.info(log, sql.toString());
                        new QueryImpl(pc, dc, sql, -1, -1, null, "query");
                    } catch (DatabaseException ____de) {
                        ___de.initCause(__de);
                        __de.initCause(_de);
                        _de.initCause(de);
                        // we could not create the table, so there seem to be an other ecception we cannot solve
                        DatabaseException exp = new DatabaseException("Unable to select from your client storage database, and was also unable to create the tables. Here's the exceptions we encountered.", null, null, dc);
                        exp.initCause(de);
                        throw exp;
                    }
                }
            }
        }
        query = new QueryImpl(pc, dc, sqlSelect, -1, -1, null, "query");
    }
    ScopeContext.info(log, sqlSelect.toString());
    return query;
}
Also used : SQLImpl(lucee.runtime.db.SQLImpl) QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) SQLItemImpl(lucee.runtime.db.SQLItemImpl) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) DatabaseException(lucee.runtime.exp.DatabaseException) SQL(lucee.runtime.db.SQL)

Example 53 with QueryImpl

use of lucee.runtime.type.QueryImpl 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 54 with QueryImpl

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

the class RSSHandler method init.

private void init(InputSource is) throws SAXException, IOException, DatabaseException {
    properties = new StructImpl();
    items = new QueryImpl(COLUMNS, 0, "query");
    xmlReader = XMLUtil.createXMLReader();
    xmlReader.setContentHandler(this);
    xmlReader.setErrorHandler(this);
    // xmlReader.setEntityResolver(new TagLibEntityResolver());
    xmlReader.parse(is);
// properties.setEL("encoding",is.getEncoding());
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) StructImpl(lucee.runtime.type.StructImpl)

Example 55 with QueryImpl

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

the class Admin method doGetJars.

private void doGetJars() throws PageException {
    Resource lib = config.getLibraryDirectory();
    lucee.runtime.type.Query qry = new QueryImpl(new Key[] { KeyConstants._name, KeyConstants._source, KeyConstants._info }, new String[] { "varchar", "varchar", "varchar" }, 0, "jars");
    if (lib.isDirectory()) {
        Resource[] children = lib.listResources(new ExtensionResourceFilter(new String[] { ".jar", ".zip" }, false, true));
        for (int i = 0; i < children.length; i++) {
            qry.addRow();
            qry.setAt(KeyConstants._name, i + 1, children[i].getName());
            qry.setAt(KeyConstants._source, i + 1, children[i].getAbsolutePath());
            try {
                qry.setAt(KeyConstants._info, i + 1, new BundleFile(children[i]).info());
            } catch (Exception e) {
            }
        }
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) BundleFile(lucee.runtime.osgi.BundleFile) Query(lucee.runtime.type.Query) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException)

Aggregations

QueryImpl (lucee.runtime.type.QueryImpl)82 Query (lucee.runtime.type.Query)65 Collection (lucee.runtime.type.Collection)17 Struct (lucee.runtime.type.Struct)16 StructImpl (lucee.runtime.type.StructImpl)13 PageException (lucee.runtime.exp.PageException)12 Key (lucee.runtime.type.Collection.Key)12 Iterator (java.util.Iterator)11 Map (java.util.Map)10 ApplicationException (lucee.runtime.exp.ApplicationException)10 Array (lucee.runtime.type.Array)10 DatabaseException (lucee.runtime.exp.DatabaseException)9 Stopwatch (lucee.runtime.timer.Stopwatch)9 HashMap (java.util.HashMap)8 Resource (lucee.commons.io.res.Resource)7 BundleCollection (lucee.loader.osgi.BundleCollection)7 Entry (java.util.Map.Entry)6 IOException (java.io.IOException)5 ResultSet (java.sql.ResultSet)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5