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