use of net.sf.jsqlparser.expression.WhenClause in project herddb by diennea.
the class CompiledCaseExpression method create.
public static CompiledCaseExpression create(String validatedTableAlias, CaseExpression caseExpression) {
Expression switchExpression = caseExpression.getSwitchExpression();
if (switchExpression != null) {
throw new StatementExecutionException("unhandled expression CASE SWITCH, type " + caseExpression.getClass() + ": " + caseExpression);
}
List<Entry<CompiledSQLExpression, CompiledSQLExpression>> whens = null;
if (caseExpression.getWhenClauses() != null) {
whens = new ArrayList<>();
for (Expression when : caseExpression.getWhenClauses()) {
WhenClause whenClause = (WhenClause) when;
CompiledSQLExpression whenCondition = compileExpression(validatedTableAlias, whenClause.getWhenExpression());
if (whenCondition == null) {
return null;
}
CompiledSQLExpression thenExpr = compileExpression(validatedTableAlias, whenClause.getThenExpression());
whens.add(new AbstractMap.SimpleImmutableEntry<>(whenCondition, thenExpr));
}
}
Expression elseExp = caseExpression.getElseExpression();
if (elseExp != null) {
CompiledSQLExpression elseExpression = compileExpression(validatedTableAlias, elseExp);
if (elseExpression == null) {
return null;
}
return new CompiledCaseExpression(whens, elseExpression);
} else {
return new CompiledCaseExpression(whens, null);
}
}
Aggregations