use of com.developmentontheedge.sql.model.AstInValueList in project be5 by DevelopmentOnTheEdge.
the class ContextApplier method applyPlaceHolder.
private void applyPlaceHolder(AstBePlaceHolder placeholderNode) {
String ph = placeholderNode.getPlaceHolder();
SimpleNode replacement;
if (placeholderNode instanceof AstBeListPlaceHolder) {
AstInValueList list = new AstInValueList(SqlParserTreeConstants.JJTINVALUELIST);
context.roles().map(AstStringConstant::new).forEach(list::addChild);
replacement = list;
} else {
String rawResult;
switch(ph) {
case "username":
rawResult = context.getUserName();
break;
case "timestamp":
rawResult = String.valueOf(System.currentTimeMillis());
break;
default:
throw new UnsupportedOperationException("Unsupported placeholder: " + ph);
}
replacement = new AstStringConstant(rawResult);
}
replacement.inheritFrom(placeholderNode);
placeholderNode.replaceWith(replacement);
}
use of com.developmentontheedge.sql.model.AstInValueList in project be5 by DevelopmentOnTheEdge.
the class ContextApplier method applyParameterTag.
private void applyParameterTag(SimpleNode newTree, int i, String key, Function<String, String> varResolver) {
String value;
SimpleNode replacement;
AstBeParameterTag paramNode = (AstBeParameterTag) newTree.child(i);
String multiple = paramNode.getMultiple();
boolean tableRefAddend = newTree instanceof AstTableRef && i == 1;
if (multiple == null) {
value = context.getParameter(paramNode.getName());
Map<String, String> propertyMap = getSubQueryPropertyMap(key, varResolver);
if (value == null && propertyMap.containsKey(paramNode.getName())) {
value = propertyMap.get(paramNode.getName());
}
replacement = applyParameters(paramNode, value, tableRefAddend);
} else {
if (newTree instanceof AstInValueList) {
List<String> values = context.getListParameter(paramNode.getName());
paramNode.replaceWith(StreamEx.of(values).map(val -> applyParameters(paramNode, val, tableRefAddend)).toArray(SimpleNode[]::new));
return;
}
if (!(newTree instanceof AstInPredicate))
throw new IllegalArgumentException("Parameter Multiple can only be put inside InPredicate");
AstInValueList list = new AstInValueList(SqlParserTreeConstants.JJTINVALUELIST);
List<String> values = context.getListParameter(paramNode.getName());
if (values != null) {
for (String val : values) {
list.addChild(applyParameters(paramNode, val, tableRefAddend));
}
}
replacement = list;
}
replacement.inheritFrom(paramNode);
if (tableRefAddend) {
AstTableRef tableRef = (AstTableRef) newTree;
tableRef.setTable(tableRef.getTable() + replacement.format());
tableRef.removeChild(i);
} else {
newTree.jjtAddChild(replacement, i);
}
}
use of com.developmentontheedge.sql.model.AstInValueList in project be5 by DevelopmentOnTheEdge.
the class ContextApplier method applySqlTag.
private void applySqlTag(AstBeSql sql) {
if (sql.getExec().equals("include")) {
String entityName = sql.getEntityName();
String queryName = sql.getQueryName();
String subQuery = context.resolveQuery(entityName, queryName);
sql.replaceWith(SqlQuery.parse(subQuery).getQuery());
return;
}
List<String> beautifiers = Arrays.asList("com.beanexplorer.web.html.HtmlLineGlueBeautifier");
if (sql.jjtGetParent() instanceof AstInValueList) {
beautifiers = Arrays.asList("com.beanexplorer.web.html.SqlInClauseQuotedBeautifier", "com.beanexplorer.web.html.SqlInClauseBeautifier");
} else {
List<String> inValueAttr = Arrays.asList("entity", "queryName", "filterKeyProperty", "filterKey", "filterValProperty", "filterVal", "outColumns");
for (String attr : inValueAttr) if (sql.getParameter(attr) != null)
throw new IllegalArgumentException("Unsupported attribute: " + attr);
}
if (!sql.getExec().equals("pre") || !beautifiers.contains(sql.getBeautifier()))
throw new IllegalArgumentException("Unsupported attributes: exec=\"" + sql.getExec() + "\" beautifier=\"" + sql.getBeautifier() + "\"");
if (sql.getDistinct().equalsIgnoreCase("yes"))
new DistinctApplier().transformQuery(sql.getQuery());
if (sql.getLimit() != null)
new LimitsApplier(0, sql.getLimit()).transformQuery(sql.getQuery());
sql.replaceWith(new AstParenthesis(sql.getQuery()));
}
Aggregations