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;
}
}
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;
}
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);
}
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");
}
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;
}
Aggregations