use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class GenericDbmsTransformer method transformExtractExpression.
protected void transformExtractExpression(AstExtract extract) {
String dateField = extract.getDateField().toUpperCase();
SimpleNode child = extract.child(0);
if (AstFunNode.isFunction("age").test(child)) {
SimpleNode parent = extract.jjtGetParent();
if ("YEAR".equals(dateField)) {
SimpleNode grandParent = parent.jjtGetParent();
SimpleNode toReplace = extract;
if (AstFunNode.isFunction("*").test(parent) && AstFunNode.isFunction("+").test(grandParent) && AstExtract.isExtract("MONTH").test(grandParent.other(parent))) {
dateField = "MONTH";
toReplace = parent.jjtGetParent();
}
toReplace.replaceWith(getDateTimeDiff(child.child(1), child.child(0), dateField));
} else if ("MONTH".equals(dateField) && AstFunNode.isFunction("+").test(parent) && AstFunNode.isFunction("*").test(parent.child(1)) && parent.child(1).children().anyMatch(AstExtract.isExtract("YEAR"))) {
parent.jjtGetParent().replaceWith(getDateTimeDiff(child.child(1), child.child(0), dateField));
}
} else if (child instanceof AstParenthesis && AstFunNode.isFunction("-").test(child.child(0)) && ("DAY".equals(dateField) || "EPOCH".equals(dateField))) {
AstFunNode date = (AstFunNode) child.child(0);
extract.replaceWith(getDateTimeDiff(date.child(1), date.child(0), "EPOCH".equals(dateField) ? "SECOND" : "DAY"));
} else
transformExtract(extract);
}
use of com.developmentontheedge.sql.model.AstParenthesis 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