private int whichArg(final FunCall node, final Exp arg) { final Exp[] children = node.getArgs(); for (int i = 0; i < children.length; i++) { if (children[i] == arg) { return i; } } return -1; }
/** * Registers all arguments of a function that are named sets. * * @param call Function call */ private void registerAliasArgs(FunCall call) { for (Exp exp : call.getArgs()) { registerAlias((QueryPart) call, exp); } }
/** * @return true if exp is a matching FunCall */ protected boolean match(Exp exp) { if ((exp.getCategory() & category) == 0) { return false; } if (!(exp instanceof FunCall)) { return false; } FunCall fc = (FunCall) exp; if (!mdx.equalsIgnoreCase(fc.getFunName())) { return false; } Exp[] args = fc.getArgs(); if (args.length != argCount) { return false; } return true; }
/** * compiles the arguments of a FunCall * * @return array of expressions or null if either exp does not match or * any argument could not be compiled. */ protected String[] compileArgs(Exp exp, SqlCompiler compiler) { if (!match(exp)) { return null; } Exp[] args = ((FunCall) exp).getArgs(); String[] sqls = new String[args.length]; for (int i = 0; i < args.length; i++) { sqls[i] = compiler.compile(args[i]); if (sqls[i] == null) { return null; } } return sqls; } }
private boolean hasCyclicReference(Exp expr, List<MemberExpr> expList) { if (expr instanceof MemberExpr) { MemberExpr memberExpr = (MemberExpr) expr; if (expList.contains(expr)) { return true; } expList.add(memberExpr); Member member = memberExpr.getMember(); if (member instanceof RolapCalculatedMember) { RolapCalculatedMember calculatedMember = (RolapCalculatedMember) member; Exp exp1 = calculatedMember.getExpression().accept(validator); return hasCyclicReference(exp1, expList); } } if (expr instanceof FunCall) { FunCall funCall = (FunCall) expr; Exp[] exps = funCall.getArgs(); for (int i = 0; i < exps.length; i++) { if (hasCyclicReference( exps[i], cloneForEachBranch(expList))) { return true; } } } return false; }
public String compile(Exp exp) { if (!match(exp)) { return null; } Exp[] args = ((FunCall) exp).getArgs(); String cond = booleanCompiler.compile(args[0]); String val1 = valueCompiler.compile(args[1]); String val2 = valueCompiler.compile(args[2]); if (cond == null || val1 == null || val2 == null) { return null; } return sqlQuery.getDialect().caseWhenElse(cond, val1, val2); } }