Search in sources :

Example 6 with Pair

use of lucee.commons.lang.Pair in project Lucee by lucee.

the class DatasourceManagerImpl method rollback.

@Override
public void rollback() throws DatabaseException {
    if (autoCommit || transConns.size() == 0)
        return;
    Iterator<DatasourceConnection> it = this.transConns.values().iterator();
    DatasourceConnection dc = null;
    Pair<DatasourceConnection, Exception> pair = null;
    while (it.hasNext()) {
        dc = it.next();
        try {
            dc.getConnection().rollback();
        } catch (Exception e) {
            // we only keep the first exception
            if (pair == null) {
                pair = new Pair<DatasourceConnection, Exception>(dc, e);
            }
        }
    }
    if (pair != null) {
        if (pair.getValue() instanceof SQLException) {
            throw new DatabaseException((SQLException) pair.getValue(), pair.getName());
        }
        throw new PageRuntimeException(pair.getValue());
    }
}
Also used : ORMDatasourceConnection(lucee.runtime.orm.ORMDatasourceConnection) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DatabaseException(lucee.runtime.exp.DatabaseException) DatabaseException(lucee.runtime.exp.DatabaseException) DeprecatedException(lucee.runtime.exp.DeprecatedException) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) Pair(lucee.commons.lang.Pair)

Example 7 with Pair

use of lucee.commons.lang.Pair in project Lucee by lucee.

the class Feed method propTag.

private boolean propTag(StringBuffer xml, int count, Object value, String trgName, String[][] attrNames, boolean childrenAsTag) throws PageException {
    if (!StringUtil.isEmpty(value)) {
        Pair[] attrs;
        if (value instanceof Struct && attrNames != null) {
            Struct sct = (Struct) value;
            Object attrValue;
            ArrayList al = new ArrayList();
            for (int i = 0; i < attrNames.length; i++) {
                attrValue = sct.get(attrNames[i][0], null);
                if (attrValue != null) {
                    al.add(new Pair<String, Object>(attrNames[i][1], attrValue));
                }
            }
            attrs = (Pair[]) al.toArray(new Pair[al.size()]);
        } else
            attrs = null;
        tag(xml, count, new Pair<String, Object>(trgName, FeedQuery.getValue(value)), attrs, false, false, childrenAsTag);
        return true;
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) GetHttpTimeString(lucee.runtime.functions.dateTime.GetHttpTimeString) Pair(lucee.commons.lang.Pair) Struct(lucee.runtime.type.Struct)

Example 8 with Pair

use of lucee.commons.lang.Pair in project Lucee by lucee.

the class CFMLSpoolerTaskListener method listen.

@Override
public void listen(Config config, Exception e) {
    if (!(config instanceof ConfigWeb))
        return;
    ConfigWeb cw = (ConfigWeb) config;
    PageContext pc = ThreadLocalPageContext.get();
    boolean pcCreated = false;
    if (pc == null) {
        pcCreated = true;
        Pair[] parr = new Pair[0];
        DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
        pc = ThreadUtil.createPageContext(cw, os, "localhost", "/", "", new Cookie[0], parr, null, parr, new StructImpl(), true, -1);
        pc.setRequestTimeout(config.getRequestTimeout().getMillis());
    }
    try {
        Struct args = new StructImpl();
        long l = task.lastExecution();
        if (l > 0)
            args.set("lastExecution", new DateTimeImpl(pc, l, true));
        l = task.nextExecution();
        if (l > 0)
            args.set("nextExecution", new DateTimeImpl(pc, l, true));
        args.set("created", new DateTimeImpl(pc, task.getCreation(), true));
        args.set(KeyConstants._id, task.getId());
        args.set(KeyConstants._type, task.getType());
        args.set(KeyConstants._detail, task.detail());
        args.set(KeyConstants._tries, task.tries());
        args.set("remainingtries", e == null ? 0 : task.getPlans().length - task.tries());
        args.set("closed", task.closed());
        args.set("passed", e == null);
        if (e != null)
            args.set("exception", new CatchBlockImpl(Caster.toPageException(e)));
        Struct curr = new StructImpl();
        args.set("caller", curr);
        curr.set("template", currTemplate.template);
        curr.set("line", new Double(currTemplate.line));
        Struct adv = new StructImpl();
        args.set("advanced", adv);
        adv.set("exceptions", task.getExceptions());
        adv.set("executedPlans", task.getPlans());
        _listen(pc, args);
    } catch (PageException pe) {
        SystemOut.printDate(pe);
    } finally {
        if (pcCreated)
            ThreadLocalPageContext.release();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) PageException(lucee.runtime.exp.PageException) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) Struct(lucee.runtime.type.Struct) StructImpl(lucee.runtime.type.StructImpl) CatchBlockImpl(lucee.runtime.exp.CatchBlockImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) Pair(lucee.commons.lang.Pair)

Example 9 with Pair

use of lucee.commons.lang.Pair in project Lucee by lucee.

the class ComponentImpl method readExternal.

// MUST more native impl
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    boolean pcCreated = false;
    PageContext pc = ThreadLocalPageContext.get();
    try {
        if (pc == null) {
            pcCreated = true;
            ConfigWeb config = (ConfigWeb) ThreadLocalPageContext.getConfig();
            Pair[] parr = new Pair[0];
            pc = ThreadUtil.createPageContext(config, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", new Cookie[0], parr, null, parr, new StructImpl(), true, -1);
        }
        // reading fails for serialized data from Lucee version 4.1.2.002
        String name = in.readUTF();
        if (name.startsWith("evaluateComponent('") && name.endsWith("})")) {
            readExternalOldStyle(pc, name);
            return;
        }
        String md5 = in.readUTF();
        Struct _this = Caster.toStruct(in.readObject(), null);
        Struct _var = Caster.toStruct(in.readObject(), null);
        try {
            ComponentImpl other = (ComponentImpl) EvaluateComponent.invoke(pc, name, md5, _this, _var);
            _readExternal(other);
        } catch (PageException e) {
            throw ExceptionUtil.toIOException(e);
        }
    } finally {
        if (pcCreated)
            ThreadLocalPageContext.release();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) ConfigWeb(lucee.runtime.config.ConfigWeb) Pair(lucee.commons.lang.Pair) Struct(lucee.runtime.type.Struct)

Example 10 with Pair

use of lucee.commons.lang.Pair in project Lucee by lucee.

the class DatasourceManagerImpl method commit.

@Override
public void commit() throws DatabaseException {
    if (autoCommit || transConns.size() == 0)
        return;
    Iterator<DatasourceConnection> it = this.transConns.values().iterator();
    DatasourceConnection dc = null;
    Pair<DatasourceConnection, Exception> pair = null;
    while (it.hasNext()) {
        dc = it.next();
        try {
            dc.getConnection().commit();
        } catch (Exception e) {
            // we only keep the first exception
            if (pair == null) {
                pair = new Pair<DatasourceConnection, Exception>(dc, e);
            }
        }
    }
    if (pair != null) {
        if (pair.getValue() instanceof SQLException) {
            throw new DatabaseException((SQLException) pair.getValue(), pair.getName());
        }
        throw new PageRuntimeException(pair.getValue());
    }
}
Also used : ORMDatasourceConnection(lucee.runtime.orm.ORMDatasourceConnection) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DatabaseException(lucee.runtime.exp.DatabaseException) DatabaseException(lucee.runtime.exp.DatabaseException) DeprecatedException(lucee.runtime.exp.DeprecatedException) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) Pair(lucee.commons.lang.Pair)

Aggregations

Pair (lucee.commons.lang.Pair)15 PageException (lucee.runtime.exp.PageException)7 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)5 Struct (lucee.runtime.type.Struct)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 Entry (java.util.Map.Entry)4 Cookie (javax.servlet.http.Cookie)4 PageContext (lucee.runtime.PageContext)4 DatabaseException (lucee.runtime.exp.DatabaseException)4 DeprecatedException (lucee.runtime.exp.DeprecatedException)4 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)4 ORMDatasourceConnection (lucee.runtime.orm.ORMDatasourceConnection)4 StructImpl (lucee.runtime.type.StructImpl)4 Enumeration (java.util.Enumeration)3 ConfigWeb (lucee.runtime.config.ConfigWeb)3 DevNullOutputStream (lucee.commons.io.DevNullOutputStream)2 Log (lucee.commons.io.log.Log)2 PageContextImpl (lucee.runtime.PageContextImpl)2 HttpServletResponseDummy (lucee.runtime.net.http.HttpServletResponseDummy)2