Search in sources :

Example 81 with ApplicationException

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

the class StorageScopeDatasource method _loadData.

protected static Struct _loadData(PageContext pc, String datasourceName, String strType, int type, Log log, boolean mxStyle) throws PageException {
    ConfigImpl config = (ConfigImpl) ThreadLocalPageContext.getConfig(pc);
    DatasourceConnectionPool pool = config.getDatasourceConnectionPool();
    DatasourceConnection dc = pool.getDatasourceConnection(config, pc.getDataSource(datasourceName), null, null);
    SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
    Query query;
    try {
        if (!dc.getDatasource().isStorage())
            throw new ApplicationException("storage usage for this datasource is disabled, you can enable this in the Lucee administrator.");
        query = executor.select(config, pc.getCFID(), pc.getApplicationContext().getName(), dc, type, log, true);
    } catch (SQLException se) {
        throw Caster.toPageException(se);
    } finally {
        if (dc != null)
            pool.releaseDatasourceConnection(dc);
    }
    if (query != null && config.debug()) {
        boolean debugUsage = DebuggerUtil.debugQueryUsage(pc, query);
        pc.getDebugger().addQuery(debugUsage ? query : null, datasourceName, "", query.getSql(), query.getRecordcount(), ((PageContextImpl) pc).getCurrentPageSource(null), query.getExecutionTime());
    }
    boolean _isNew = query.getRecordcount() == 0;
    if (_isNew) {
        ScopeContext.info(log, "create new " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID() + " in datasource [" + datasourceName + "]");
        return null;
    }
    String str = Caster.toString(query.get(KeyConstants._data));
    if (str != null && str.startsWith("struct:"))
        str = str.substring(7);
    if (mxStyle)
        return null;
    try {
        Struct s = (Struct) pc.evaluate(str);
        ScopeContext.info(log, "load existing data from [" + datasourceName + "." + PREFIX + "_" + strType + "_data] to create " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
        return s;
    } catch (Exception e) {
        ScopeContext.error(log, e);
        return null;
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) DatasourceConnectionPool(lucee.runtime.db.DatasourceConnectionPool) DatasourceConnection(lucee.runtime.db.DatasourceConnection) Query(lucee.runtime.type.Query) SQLExecutor(lucee.runtime.type.scope.storage.db.SQLExecutor) SQLException(java.sql.SQLException) ConfigImpl(lucee.runtime.config.ConfigImpl) SQLException(java.sql.SQLException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException) Struct(lucee.runtime.type.Struct)

Example 82 with ApplicationException

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

the class UDFUtil method toDumpData.

public static DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp, UDF udf, short type) {
    if (!dp.getShowUDFs()) {
        if (TYPE_UDF == type)
            return new SimpleDumpData("<UDF>");
        if (TYPE_BIF == type)
            return new SimpleDumpData("<BIF>");
        if (TYPE_CLOSURE == type)
            return new SimpleDumpData("<Closure>");
        if (TYPE_LAMBDA == type)
            return new SimpleDumpData("<Lambda>");
    }
    // arguments
    FunctionArgument[] args = udf.getFunctionArguments();
    DumpTable atts;
    if (TYPE_UDF == type)
        atts = new DumpTable("udf", "#ca5095", "#e9accc", "#000000");
    else if (TYPE_CLOSURE == type)
        atts = new DumpTable("udf", "#9cb770", "#c7e1ba", "#000000");
    else if (TYPE_BIF == type)
        atts = new DumpTable("udf", "#e1c039", "#f1e2a3", "#000000");
    else
        atts = new DumpTable("udf", "#f3d5bd", "#f6e4cc", "#000000");
    atts.appendRow(new DumpRow(63, new DumpData[] { new SimpleDumpData("label"), new SimpleDumpData("name"), new SimpleDumpData("required"), new SimpleDumpData("type"), new SimpleDumpData("default"), new SimpleDumpData("hint") }));
    for (int i = 0; i < args.length; i++) {
        FunctionArgument arg = args[i];
        DumpData def;
        try {
            Object oa = udf.getDefaultValue(pageContext, i, null);
            if (oa == null)
                oa = "null";
            def = new SimpleDumpData(Caster.toString(oa));
        } catch (PageException e) {
            def = new SimpleDumpData("");
        }
        atts.appendRow(new DumpRow(0, new DumpData[] { new SimpleDumpData(arg.getDisplayName()), new SimpleDumpData(arg.getName().getString()), new SimpleDumpData(arg.isRequired()), new SimpleDumpData(arg.getTypeAsString()), def, new SimpleDumpData(arg.getHint()) }));
    // atts.setRow(0,arg.getHint());
    }
    DumpTable func;
    String label = udf.getDisplayName();
    if (TYPE_CLOSURE == type) {
        func = new DumpTable("#9cb770", "#c7e1ba", "#000000");
        func.setTitle(StringUtil.isEmpty(label) ? "Closure" : "Closure " + label);
    } else if (TYPE_UDF == type) {
        func = new DumpTable("#ca5095", "#e9accc", "#000000");
        String f = "Function ";
        try {
            f = StringUtil.ucFirst(ComponentUtil.toStringAccess(udf.getAccess()).toLowerCase()) + " " + f;
        } catch (ApplicationException e) {
        }
        f += udf.getFunctionName();
        if (udf instanceof UDFGSProperty)
            f += " (generated)";
        func.setTitle(f);
    } else if (TYPE_BIF == type) {
        String f = "Build in Function " + (!StringUtil.isEmpty(label) ? label : udf.getFunctionName());
        func = new DumpTable("#e1c039", "#f1e2a3", "#000000");
        func.setTitle(f);
    } else {
        func = new DumpTable("#f3d5bd", "#f6e4cc", "#000000");
        func.setTitle(StringUtil.isEmpty(label) ? "Lambda" : "Lambda " + label);
    }
    // Source
    String src = udf.getSource();
    if (!StringUtil.isEmpty(src))
        func.setComment("source:" + src);
    String hint = udf.getHint();
    String desc = udf.getDescription();
    if (!StringUtil.isEmpty(desc))
        addComment(func, desc);
    if (!StringUtil.isEmpty(hint))
        addComment(func, hint);
    if (Component.MODIFIER_NONE != udf.getModifier())
        func.appendRow(1, new SimpleDumpData("modifier"), new SimpleDumpData(ComponentUtil.toModifier(udf.getModifier(), "")));
    func.appendRow(1, new SimpleDumpData("arguments"), atts);
    func.appendRow(1, new SimpleDumpData("return type"), new SimpleDumpData(udf.getReturnTypeAsString()));
    return func;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException) DumpRow(lucee.runtime.dump.DumpRow) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) UDFGSProperty(lucee.runtime.type.UDFGSProperty) FunctionArgument(lucee.runtime.type.FunctionArgument) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) DumpData(lucee.runtime.dump.DumpData)

Example 83 with ApplicationException

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

the class DBUtilImpl method releaseDatasourceConnection.

public void releaseDatasourceConnection(PageContext pc, DatasourceConnection dc, boolean managed) {
    pc = ThreadLocalPageContext.get(pc);
    if (managed) {
        if (pc == null)
            throw new PageRuntimeException(new ApplicationException("missing PageContext to access the Database Connection Manager"));
        DatasourceManagerImpl manager = (DatasourceManagerImpl) pc.getDataSourceManager();
        manager.releaseConnection(pc, dc);
        return;
    }
    releaseDatasourceConnection(ThreadLocalPageContext.getConfig(pc), dc);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DatasourceManagerImpl(lucee.runtime.db.DatasourceManagerImpl)

Example 84 with ApplicationException

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

the class BundleInfo method call.

public static Struct call(PageContext pc, Object obj) throws PageException {
    if (obj == null)
        throw new FunctionException(pc, "bundleInfo", 1, "object", "value is null");
    Class<?> clazz;
    if (obj instanceof JavaObject)
        clazz = ((JavaObject) obj).getClazz();
    else if (obj instanceof ObjectWrap)
        clazz = ((ObjectWrap) obj).getEmbededObject().getClass();
    else
        clazz = obj.getClass();
    ClassLoader cl = clazz.getClassLoader();
    if (cl instanceof BundleClassLoader) {
        BundleClassLoader bcl = (BundleClassLoader) cl;
        Bundle b = bcl.getBundle();
        Struct sct = new StructImpl();
        sct.setEL(KeyConstants._id, b.getBundleId());
        sct.setEL(KeyConstants._name, b.getSymbolicName());
        sct.setEL("location", b.getLocation());
        sct.setEL(KeyConstants._version, b.getVersion().toString());
        sct.setEL(KeyConstants._state, OSGiUtil.toState(b.getState(), null));
        try {
            sct.setEL("requiredBundles", toArray1(OSGiUtil.getRequiredBundles(b)));
            sct.setEL("requiredPackages", toArray2(OSGiUtil.getRequiredPackages(b)));
        } catch (BundleException be) {
            throw Caster.toPageException(be);
        }
        return sct;
    }
    throw new ApplicationException(obj + "given object is not from a OSGi bundle");
}
Also used : ObjectWrap(lucee.runtime.type.ObjectWrap) StructImpl(lucee.runtime.type.StructImpl) ApplicationException(lucee.runtime.exp.ApplicationException) JavaObject(lucee.runtime.java.JavaObject) BundleClassLoader(org.apache.felix.framework.BundleWiringImpl.BundleClassLoader) Bundle(org.osgi.framework.Bundle) FunctionException(lucee.runtime.exp.FunctionException) BundleClassLoader(org.apache.felix.framework.BundleWiringImpl.BundleClassLoader) BundleException(org.osgi.framework.BundleException) Struct(lucee.runtime.type.Struct)

Example 85 with ApplicationException

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

the class ModernApplicationContext method toCacheConnection.

public static CacheConnection toCacheConnection(Config config, String name, Struct data) throws ApplicationException, CacheException, ClassException, BundleException {
    // class definition
    String className = Caster.toString(data.get(KeyConstants._class, null), null);
    if (StringUtil.isEmpty(className))
        throw new ApplicationException("missing key class in struct the defines a cachec connection");
    ClassDefinition cd = new ClassDefinitionImpl(className, Caster.toString(data.get(KeyConstants._bundleName, null), null), Caster.toString(data.get(KeyConstants._bundleVersion, null), null), config.getIdentification());
    CacheConnectionImpl cc = new CacheConnectionImpl(config, name, cd, Caster.toStruct(data.get(KeyConstants._custom, null), null), Caster.toBooleanValue(data.get(KeyConstants._readonly, null), false), Caster.toBooleanValue(data.get(KeyConstants._storage, null), false));
    String id = cc.id();
    CacheConnection icc = initCacheConnections.get(id);
    if (icc != null)
        return icc;
    try {
        Method m = cd.getClazz().getMethod("init", new Class[] { Config.class, String[].class, Struct[].class });
        if (Modifier.isStatic(m.getModifiers()))
            m.invoke(null, new Object[] { config, new String[] { cc.getName() }, new Struct[] { cc.getCustom() } });
        else
            SystemOut.print(config.getErrWriter(), "method [init(Config,String[],Struct[]):void] for class [" + cd.toString() + "] is not static");
        initCacheConnections.put(id, cc);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    return cc;
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ApplicationException(lucee.runtime.exp.ApplicationException) CacheConnectionImpl(lucee.runtime.cache.CacheConnectionImpl) Method(java.lang.reflect.Method) ClassDefinition(lucee.runtime.db.ClassDefinition) CacheConnection(lucee.runtime.cache.CacheConnection) Struct(lucee.runtime.type.Struct)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)173 IOException (java.io.IOException)41 Resource (lucee.commons.io.res.Resource)36 PageException (lucee.runtime.exp.PageException)30 Struct (lucee.runtime.type.Struct)25 SecurityException (lucee.runtime.exp.SecurityException)17 BundleException (org.osgi.framework.BundleException)16 StructImpl (lucee.runtime.type.StructImpl)15 MalformedURLException (java.net.MalformedURLException)13 Element (org.w3c.dom.Element)13 Array (lucee.runtime.type.Array)12 Key (lucee.runtime.type.Collection.Key)12 Iterator (java.util.Iterator)11 InputStream (java.io.InputStream)10 Query (lucee.runtime.type.Query)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ExpressionException (lucee.runtime.exp.ExpressionException)9 Entry (java.util.Map.Entry)8 PageContextImpl (lucee.runtime.PageContextImpl)8 ClassDefinition (lucee.runtime.db.ClassDefinition)8