Search in sources :

Example 26 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class DatasourceManagerImpl method end.

public void end(boolean onlyORM) {
    autoCommit = true;
    Pair<DatasourceConnection, Exception> pair = null;
    if (transConns.size() > 0) {
        Map<DataSource, DatasourceConnection> tmp = null;
        if (onlyORM)
            tmp = new HashMap<DataSource, DatasourceConnection>();
        Iterator<Entry<DataSource, DatasourceConnection>> it = this.transConns.entrySet().iterator();
        DatasourceConnection dc;
        Entry<DataSource, DatasourceConnection> entry;
        while (it.hasNext()) {
            entry = it.next();
            dc = entry.getValue();
            try {
                if (onlyORM && !(dc.getConnection() instanceof ORMConnection)) {
                    tmp.put(entry.getKey(), entry.getValue());
                    continue;
                }
                dc.getConnection().setAutoCommit(true);
            } catch (Exception e) {
                // we only keep the first exception
                if (pair == null) {
                    pair = new Pair<DatasourceConnection, Exception>(dc, e);
                }
            }
            releaseConnection(null, dc);
        }
        transConns.clear();
        if (onlyORM)
            transConns = tmp;
    }
    this.isolation = Connection.TRANSACTION_NONE;
    if (pair != null) {
        if (pair.getValue() instanceof SQLException) {
            throw new PageRuntimeException(new DatabaseException((SQLException) pair.getValue(), pair.getName()));
        }
        throw new PageRuntimeException(pair.getValue());
    }
}
Also used : ORMDatasourceConnection(lucee.runtime.orm.ORMDatasourceConnection) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) DatabaseException(lucee.runtime.exp.DatabaseException) DeprecatedException(lucee.runtime.exp.DeprecatedException) SQLException(java.sql.SQLException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) Entry(java.util.Map.Entry) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DatabaseException(lucee.runtime.exp.DatabaseException) ORMConnection(lucee.runtime.orm.ORMConnection) Pair(lucee.commons.lang.Pair)

Example 27 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class DatasourceManagerImpl method savepoint.

@Override
public void savepoint() 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().setSavepoint();
        } 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 28 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class FunctionLib method duplicate.

/**
 * duplcate a hashmap with FunctionLibFunction's
 * @param funcs
 * @param deepCopy
 * @return cloned map
 */
private HashMap duplicate(HashMap funcs, boolean deepCopy) {
    if (deepCopy)
        throw new PageRuntimeException(new ExpressionException("deep copy not supported"));
    Iterator it = funcs.entrySet().iterator();
    Map.Entry entry;
    HashMap cm = new HashMap();
    while (it.hasNext()) {
        entry = (Entry) it.next();
        cm.put(entry.getKey(), deepCopy ? // TODO add support for deepcopy ((FunctionLibFunction)entry.getValue()).duplicate(deepCopy):
        entry.getValue() : entry.getValue());
    }
    return cm;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Iterator(java.util.Iterator) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) Map(java.util.Map) HashMap(java.util.HashMap) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 29 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class Sprite method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException {
    String id = "sprite_" + IDGenerator.intId();
    try {
        Page page = ASMUtil.getAncestorPage(tag);
        SourceCode sc = page.getSourceCode();
        String key = sc.id();
        key = HashUtil.create64BitHashAsString(Thread.currentThread().getId() + ":" + key);
        Expression src = tag.getAttribute("src").getValue();
        // get data from previous sprites
        Previous previous = sprites.get(key);
        if (previous != null) {
            previous.tag.removeAttribute("_ids");
            previous.tag.removeAttribute("_srcs");
            previous.tag = tag;
        } else {
            sprites.put(key, previous = new Previous(tag));
        }
        previous.ids.add(id);
        if (previous.src == null)
            previous.src = src;
        else {
            previous.src = tag.getFactory().opString(previous.src, tag.getFactory().createLitString(","));
            previous.src = tag.getFactory().opString(previous.src, src);
        }
        tag.addAttribute(new Attribute(false, "_id", tag.getFactory().createLitString(id), "string"));
        tag.addAttribute(new Attribute(false, "_ids", tag.getFactory().createLitString(lucee.runtime.type.util.ListUtil.listToList(previous.ids, ",")), "string"));
        tag.addAttribute(new Attribute(false, "_srcs", previous.src, "string"));
    } catch (Throwable e) {
        // TODO handle Excpetion much more precise
        ExceptionUtil.rethrowIfNecessary(e);
        throw new PageRuntimeException(Caster.toPageException(e));
    }
}
Also used : SourceCode(lucee.transformer.util.SourceCode) Expression(lucee.transformer.expression.Expression) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Page(lucee.transformer.bytecode.Page) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 30 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method funcStatement.

/**
 * Liest ein function Statement ein.
 * <br />
 * EBNF:<br />
 * <code>identifier spaces "(" spaces identifier spaces {"," spaces identifier spaces} ")" spaces block;</code>
 * @return function Statement
 * @throws TemplateException
 */
private final Statement funcStatement(ExprData data, Body parent) throws TemplateException {
    int pos = data.srcCode.getPos();
    // read 5 tokens (returntype,access modifier,"abstract|final|static","function", function name)
    String str = variableDec(data, false);
    // if there is no token at all we have no function
    if (str == null) {
        data.srcCode.setPos(pos);
        return null;
    }
    comments(data);
    String[] tokens = new String[] { str, null, null, null, null };
    tokens[1] = variableDec(data, false);
    comments(data);
    if (tokens[1] != null) {
        tokens[2] = variableDec(data, false);
        comments(data);
        if (tokens[2] != null) {
            tokens[3] = variableDec(data, false);
            comments(data);
            if (tokens[3] != null) {
                tokens[4] = identifier(data, false);
                comments(data);
            }
        }
    }
    // function name
    String functionName = null;
    for (int i = tokens.length - 1; i >= 0; i--) {
        // first from right is the function name
        if (tokens[i] != null) {
            functionName = tokens[i];
            tokens[i] = null;
            break;
        }
    }
    if (functionName == null || functionName.indexOf(',') != -1 || functionName.indexOf('[') != -1) {
        data.srcCode.setPos(pos);
        return null;
    }
    // throw new TemplateException(data.srcCode, "invalid syntax");
    String returnType = null;
    // search for "function"
    boolean hasOthers = false, first = true;
    for (int i = tokens.length - 1; i >= 0; i--) {
        if ("function".equalsIgnoreCase(tokens[i])) {
            // if it is the first "function" (from right) and we had already something else, the syntax is broken!
            if (hasOthers && first)
                throw new TemplateException(data.srcCode, "invalid syntax");
            else // we already have a return type,so this is the 3th "function"!
            if (returnType != null)
                throw new TemplateException(data.srcCode, "invalid syntax");
            else if (!first)
                returnType = tokens[i];
            first = false;
            tokens[i] = null;
        } else if (tokens[i] != null) {
            hasOthers = true;
        }
    }
    // no "function" found
    if (first) {
        data.srcCode.setPos(pos);
        return null;
    }
    // access modifier
    int _access, access = -1;
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i] != null && (_access = ComponentUtil.toIntAccess(tokens[i], -1)) != -1) {
            // we already have an access modifier
            if (access != -1) {
                // we already have a return type
                if (returnType != null)
                    throw new TemplateException(data.srcCode, "invalid syntax");
                returnType = tokens[i];
            } else
                access = _access;
            tokens[i] = null;
        }
    }
    // no access defined
    if (access == -1)
        access = Component.ACCESS_PUBLIC;
    // Non access modifier
    int _modifier, modifier = Component.MODIFIER_NONE;
    boolean isStatic = false;
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i] != null) {
            _modifier = ComponentUtil.toModifier(tokens[i], Component.MODIFIER_NONE, Component.MODIFIER_NONE);
            // abstract|final
            if (_modifier != Component.MODIFIER_NONE) {
                // we already have an Non access modifier
                if (modifier != Component.MODIFIER_NONE || isStatic) {
                    // we already have a return type
                    if (returnType != null)
                        throw new TemplateException(data.srcCode, "invalid syntax");
                    returnType = tokens[i];
                } else
                    modifier = _modifier;
                tokens[i] = null;
            } else // static
            if (tokens[i].equalsIgnoreCase("static")) {
                // we already have an Non access modifier
                if (modifier != Component.MODIFIER_NONE || isStatic) {
                    // we already have a return type
                    if (returnType != null)
                        throw new TemplateException(data.srcCode, "invalid syntax");
                    returnType = tokens[i];
                } else
                    isStatic = true;
                tokens[i] = null;
            }
        }
    }
    // return type
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i] != null) {
            if (returnType != null)
                throw new TemplateException(data.srcCode, "invalid syntax");
            returnType = tokens[i];
        }
    }
    Position line = data.srcCode.getPosition();
    // Name
    if (!data.isCFC && !data.isInterface) {
        FunctionLibFunction flf = getFLF(data, functionName);
        try {
            if (flf != null && flf.getFunctionClassDefinition().getClazz() != CFFunction.class) {
                PageSource ps = null;
                if (data.srcCode instanceof PageSourceCode) {
                    ps = ((PageSourceCode) data.srcCode).getPageSource();
                }
                String path = null;
                if (ps != null) {
                    path = ps.getDisplayPath();
                    path = path.replace('\\', '/');
                }
                if (// TODO make better
                path == null || path.indexOf("/library/function/") == -1)
                    throw new TemplateException(data.srcCode, "The name [" + functionName + "] is already used by a built in Function");
            }
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            throw new PageRuntimeException(Caster.toPageException(t));
        }
    }
    Function res = closurePart(data, functionName, access, modifier, returnType, line, false);
    if (isStatic) {
        if (data.context == CTX_INTERFACE)
            throw new TemplateException(data.srcCode, "static functions are not allowed within the interface body");
        TagOther tag = createStaticTag(data, res.getStart());
        tag.getBody().addStatement(res);
        return tag;
    }
    return res;
}
Also used : CFFunction(lucee.runtime.functions.system.CFFunction) PageSourceCode(lucee.transformer.util.PageSourceCode) TemplateException(lucee.runtime.exp.TemplateException) Position(lucee.transformer.Position) TagOther(lucee.transformer.bytecode.statement.tag.TagOther) PageSource(lucee.runtime.PageSource) Function(lucee.transformer.bytecode.statement.udf.Function) CFFunction(lucee.runtime.functions.system.CFFunction) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Aggregations

PageRuntimeException (lucee.runtime.exp.PageRuntimeException)37 PageException (lucee.runtime.exp.PageException)17 Method (java.lang.reflect.Method)7 SQLException (java.sql.SQLException)7 DOMException (org.w3c.dom.DOMException)7 IOException (java.io.IOException)4 Entry (java.util.Map.Entry)4 Pair (lucee.commons.lang.Pair)4 DatasourceConnection (lucee.runtime.db.DatasourceConnection)4 DatabaseException (lucee.runtime.exp.DatabaseException)4 DeprecatedException (lucee.runtime.exp.DeprecatedException)4 ORMDatasourceConnection (lucee.runtime.orm.ORMDatasourceConnection)4 HashMap (java.util.HashMap)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 TemplateException (lucee.runtime.exp.TemplateException)3 Array (lucee.runtime.type.Array)3 Struct (lucee.runtime.type.Struct)3 BIF (lucee.transformer.bytecode.expression.var.BIF)3 Iterator (java.util.Iterator)2 Resource (lucee.commons.io.res.Resource)2