use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class StorageScopeDatasource method unstore.
@Override
public void unstore(PageContext pc) {
ConfigImpl ci = (ConfigImpl) ThreadLocalPageContext.getConfig(pc);
DatasourceConnection dc = null;
DatasourceConnectionPool pool = ci.getDatasourceConnectionPool();
Log log = ci.getLog("scope");
try {
// FUTURE change method interface
pc = ThreadLocalPageContext.get(pc);
DataSource ds;
if (pc != null)
ds = pc.getDataSource(datasourceName);
else
ds = ci.getDataSource(datasourceName);
dc = pool.getDatasourceConnection(null, ds, null, null);
SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
executor.delete(ci, cfid, appName, dc, getType(), log);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
ScopeContext.error(log, t);
} finally {
if (dc != null)
pool.releaseDatasourceConnection(dc);
}
}
use of lucee.runtime.config.ConfigImpl 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.config.ConfigImpl in project Lucee by lucee.
the class DatasourceStorageScopeCleaner method clean.
private void clean(ConfigWeb config, DataSource dataSource) throws PageException, SQLException {
ConfigWebImpl cwi = (ConfigWebImpl) config;
DatasourceConnection dc = null;
DatasourceConnectionPool pool = cwi.getDatasourceConnectionPool();
try {
dc = pool.getDatasourceConnection(null, dataSource, null, null);
Log log = ((ConfigImpl) config).getLog("scope");
SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
executor.clean(config, dc, type, engine, this, listener, log);
} finally {
if (dc != null)
pool.releaseDatasourceConnection(dc);
}
}
use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class Import method executePT.
private TagLib executePT(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, SourceCode sc) throws TemplateException {
// Attribute prefix
String nameSpace = ASMUtil.getAttributeString(tag, "prefix", null);
if (nameSpace == null)
throw new TemplateException(sc, "attribute [prefix] must be a constant value");
nameSpace = nameSpace.trim();
String nameSpaceSeparator = StringUtil.isEmpty(nameSpace) ? "" : ":";
// Attribute taglib
String textTagLib = ASMUtil.getAttributeString(tag, "taglib", null);
if (textTagLib == null)
throw new TemplateException(sc, "attribute [taglib] must be a constant value");
textTagLib = textTagLib.replace('\\', '/');
textTagLib = ConfigWebUtil.replacePlaceholder(textTagLib, config);
// File TagLib
String ext = ResourceUtil.getExtension(textTagLib, null);
boolean hasTldExtension = "tld".equalsIgnoreCase(ext) || "tldx".equalsIgnoreCase(ext);
Resource absFile = config.getResource(textTagLib);
// TLD
if (absFile.isFile())
return _executeTLD(config, absFile, nameSpace, nameSpaceSeparator, sc);
// Second Change
if (textTagLib.startsWith("/")) {
// config.getPhysical(textTagLib);
PageSource ps = ((ConfigImpl) config).getPageSourceExisting(null, null, textTagLib, false, false, true, false);
// config.getConfigDir()
if (ps != null) {
if (ps.physcalExists()) {
Resource file = ps.getPhyscalFile();
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
}
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
} else {
PageSource ps = sc instanceof PageSourceCode ? ((PageSourceCode) sc).getPageSource() : null;
Resource sourceFile = ps == null ? null : ps.getPhyscalFile();
if (sourceFile != null) {
Resource file = sourceFile.getParentResource().getRealResource(textTagLib);
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
}
throw new TemplateException(sc, "invalid definition of the attribute taglib [" + textTagLib + "]");
}
use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.
the class Loop method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException {
TagLoop loop = (TagLoop) tag;
// attribute maxrows and endrow not allowd at the same time
if (tag.containsAttribute("maxrows") && tag.containsAttribute("endrow"))
throw new EvaluatorException("Wrong Context, you cannot use attribute maxrows and endrow at the same time.");
// file loop
if (tag.containsAttribute("file")) {
if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute file you must also use attribute index and/or item");
loop.setType(TagLoop.TYPE_FILE);
return;
}
// list loop
if (tag.containsAttribute("list")) {
if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute list,you must define attribute index and/or item");
loop.setType(TagLoop.TYPE_LIST);
return;
}
// array loop
if (tag.containsAttribute("array")) {
if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute array, you must define attribute index and/or item");
loop.setType(TagLoop.TYPE_ARRAY);
return;
}
// array loop
if (tag.containsAttribute("times")) {
if (tag.getAttributes().size() > 1)
throw new EvaluatorException("Wrong Context, when you use attribute times, no other attributes are allowed");
loop.setType(TagLoop.TYPE_TIMES);
return;
}
// struct loop
if (tag.containsAttribute("struct")) {
if (!tag.containsAttribute("index") && !tag.containsAttribute("item") && !tag.containsAttribute("key") && !tag.containsAttribute("value"))
throw new EvaluatorException("Wrong Context, when you use attribute struct, you must define attribute index (alias key) and/or item (alias value)");
loop.setType(TagLoop.TYPE_STRUCT);
return;
}
// collection loop
if (tag.containsAttribute("collection")) {
if (!tag.containsAttribute("index") && !tag.containsAttribute("item") && !tag.containsAttribute("key") && !tag.containsAttribute("value"))
throw new EvaluatorException("Wrong Context, when you use attribute struct, you must define attribute index (alias key) and/or item (alias value)");
loop.setType(TagLoop.TYPE_COLLECTION);
return;
}
/*if(tag.containsAttribute("index")) {
if(!tag.containsAttribute("from") || !tag.containsAttribute("to"))
throw new EvaluatorException("Wrong Context, when you use attribute index you must also use attribute from and to or list or file");
loop.setType(TagLoop.TYPE_INDEX);
return;
}*/
if (tag.containsAttribute("from") || tag.containsAttribute("to")) {
if (!tag.containsAttribute("from"))
throw new EvaluatorException("Wrong Context, when you use attribute to, you must also use attribute from.");
if (!tag.containsAttribute("to"))
throw new EvaluatorException("Wrong Context, when you use attribute from, you must also use attribute to.");
if (!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute from and to, you must define attribute index or item.");
if (tag.containsAttribute("index") && tag.containsAttribute("item"))
throw new EvaluatorException("For this type of loop, you cannot use attribute index and item at the same time.");
loop.setType(TagLoop.TYPE_FROM_TO);
return;
}
// condition loop
if (tag.containsAttribute("condition")) {
if (tag.isScriptBase())
throw new EvaluatorException("tag loop-condition is not supported within cfscript, use instead a while statement.");
TagLib tagLib = tagLibTag.getTagLib();
ExprTransformer transformer;
String text = ASMUtil.getAttributeString(tag, "condition");
try {
transformer = tagLib.getExprTransfomer();
Page page = ASMUtil.getAncestorPage(tag);
ConfigImpl config = (ConfigImpl) page.getConfig();
Expression expr = transformer.transform(BytecodeFactory.getInstance(config), page, new EvaluatorPool(), null, flibs, config.getCoreTagLib(page.getSourceCode().getDialect()).getScriptTags(), new SourceCode(text, false, page.getSourceCode().getDialect()), new TransfomerSettings(page.getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML && config.getDotNotationUpperCase(), page.getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML && config.getHandleUnQuotedAttrValueAsString(), page.ignoreScopes));
tag.addAttribute(new Attribute(false, "condition", page.getFactory().toExprBoolean(expr), "boolean"));
} catch (Exception e) {
throw new EvaluatorException(e.getMessage());
}
loop.setType(TagLoop.TYPE_CONDITION);
return;
}
// query loop
if (tag.containsAttribute("query")) {
loop.setType(TagLoop.TYPE_QUERY);
return;
}
Info info = getParentInfo(loop);
// query group
if (tag.containsAttribute("group") && info.hasParentWithQuery) {
loop.setType(TagLoop.TYPE_GROUP);
return;
}
if (info.hasParentWithQuery) {
if (info.hasParentWithGroup)
loop.setType(TagLoop.TYPE_INNER_GROUP);
else
loop.setType(TagLoop.TYPE_INNER_QUERY);
return;
}
/*
if(hasQuery)
output.setType(TagOutput.TYPE_QUERY);
else if(tag.containsAttribute("group") && hasParentWithQuery)
output.setType(TagOutput.TYPE_GROUP);
else if(hasParentWithQuery) {
if(hasParentWithGroup) output.setType(TagOutput.TYPE_INNER_GROUP);
else output.setType(TagOutput.TYPE_INNER_QUERY);
}
else
output.setType(TagOutput.TYPE_NORMAL);
*/
loop.setType(TagLoop.TYPE_NOTHING);
// throw new EvaluatorException("Wrong Context, invalid attributes in tag cfloop");
}
Aggregations