Search in sources :

Example 21 with PageRuntimeException

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

the class DatasourceResourceProvider method delete.

public void delete(ConnectionData data, int fullPathHash, String path, String name) throws IOException {
    Attr attr = getAttr(data, fullPathHash, path, name);
    if (attr == null)
        throw new IOException("can't delete resource " + path + name + ", resource does not exist");
    DatasourceConnection dc = null;
    try {
        dc = getDatasourceConnection(data);
        getCore(data).delete(dc, data.getPrefix(), attr);
    } catch (SQLException e) {
        throw new IOException(e.getMessage());
    } catch (PageException e) {
        throw new PageRuntimeException(e);
    } finally {
        removeFromCache(data, path, name);
        release(dc);
    // manager.releaseConnection(CONNECTION_ID,dc);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) SQLException(java.sql.SQLException) IOException(java.io.IOException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 22 with PageRuntimeException

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

the class ArraySupport method toArray.

@Override
public final Object[] toArray(Object[] a) {
    if (a == null)
        return toArray();
    Class trgClass = a.getClass().getComponentType();
    short type = TYPE_OBJECT;
    if (trgClass == Boolean.class)
        type = TYPE_BOOLEAN;
    else if (trgClass == Byte.class)
        type = TYPE_BYTE;
    else if (trgClass == Short.class)
        type = TYPE_SHORT;
    else if (trgClass == Integer.class)
        type = TYPE_INT;
    else if (trgClass == Long.class)
        type = TYPE_LONG;
    else if (trgClass == Float.class)
        type = TYPE_FLOAT;
    else if (trgClass == Double.class)
        type = TYPE_DOUBLE;
    else if (trgClass == Character.class)
        type = TYPE_CHARACTER;
    else if (trgClass == String.class)
        type = TYPE_STRING;
    Iterator it = iterator();
    int i = 0;
    Object o;
    try {
        while (it.hasNext()) {
            o = it.next();
            switch(type) {
                case TYPE_BOOLEAN:
                    o = Caster.toBoolean(o);
                    break;
                case TYPE_BYTE:
                    o = Caster.toByte(o);
                    break;
                case TYPE_CHARACTER:
                    o = Caster.toCharacter(o);
                    break;
                case TYPE_DOUBLE:
                    o = Caster.toDouble(o);
                    break;
                case TYPE_FLOAT:
                    o = Caster.toFloat(o);
                    break;
                case TYPE_INT:
                    o = Caster.toInteger(o);
                    break;
                case TYPE_LONG:
                    o = Caster.toLong(o);
                    break;
                case TYPE_SHORT:
                    o = Caster.toShort(o);
                    break;
                case TYPE_STRING:
                    o = Caster.toString(o);
                    break;
            }
            a[i++] = o;
        }
    } catch (PageException pe) {
        throw new PageRuntimeException(pe);
    }
    return a;
}
Also used : PageException(lucee.runtime.exp.PageException) Iterator(java.util.Iterator) EntryArrayIterator(lucee.runtime.type.it.EntryArrayIterator) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 23 with PageRuntimeException

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

the class ForEachQueryIterator method next.

@Override
public Object next() {
    try {
        if (qry.go(++current, pid)) {
            Struct sct = new StructImpl();
            Object empty = NullSupportHelper.full() ? null : "";
            for (int i = 0; i < names.length; i++) {
                sct.setEL(names[i], qry.get(names[i], empty));
            }
            return sct;
        }
    } catch (PageException pe) {
        throw new PageRuntimeException(pe);
    }
    return null;
}
Also used : PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) Struct(lucee.runtime.type.Struct)

Example 24 with PageRuntimeException

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

the class UDFComparator method compare.

@Override
public int compare(Object oLeft, Object oRight) {
    try {
        args[0] = oLeft;
        args[1] = oRight;
        Object res = udf.call(pc, args, false);
        Integer i = Caster.toInteger(res, null);
        if (i == null)
            throw new FunctionException(pc, "ArraySort", 2, "function", "return value of the " + (udf instanceof Closure ? "closure" : "function [" + udf.getFunctionName() + "]") + " cannot be casted to a integer.", CasterException.createMessage(res, "integer"));
        return i.intValue();
    } catch (PageException pe) {
        throw new PageRuntimeException(pe);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Closure(lucee.runtime.type.Closure) FunctionException(lucee.runtime.exp.FunctionException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 25 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException 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

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