public static List<SQLExpr> split(SQLBinaryOpExpr x, SQLBinaryOperator op) { if (x.getOperator() != op) { List<SQLExpr> groupList = new ArrayList<SQLExpr>(1); groupList.add(x); return groupList; } List<SQLExpr> groupList = new ArrayList<SQLExpr>(); split(groupList, x, op); return groupList; }
public static SQLExpr getFirst(SQLExpr x) { if (x instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr binary = (SQLBinaryOpExpr) x; if (binary.getOperator() == SQLBinaryOperator.BooleanAnd || binary.getOperator() == SQLBinaryOperator.BooleanOr) { return getFirst(((SQLBinaryOpExpr) x).getLeft()); } } return x; }
public static List<SQLExpr> split(SQLBinaryOpExpr x) { return split(x, x.getOperator()); }
public static List<SQLExpr> partExpr(List<SQLExpr> exprs) { List<SQLExpr> partList = new ArrayList<SQLExpr>(); for (SQLExpr x : exprs) { if (x instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr binary = (SQLBinaryOpExpr) x; if (binary.getOperator() == SQLBinaryOperator.BooleanAnd || binary.getOperator() == SQLBinaryOperator.BooleanOr) { partList.add(((SQLBinaryOpExpr) x).getLeft()); partList.add(((SQLBinaryOpExpr) x).getRight()); continue; } } partList.add(x); } return partList; }
SQLBinaryOperator operator = binaryOpWhere.getOperator(); if (operator == SQLBinaryOperator.BooleanAnd || operator == SQLBinaryOperator.BooleanOr) { List<SQLExpr> items = SQLBinaryOpExpr.split(binaryOpWhere);
public static boolean check(WallVisitor visitor, SQLBinaryOpExpr x) { if (x.getOperator() == SQLBinaryOperator.BooleanOr || x.getOperator() == SQLBinaryOperator.BooleanAnd) { List<SQLExpr> groupList = SQLBinaryOpExpr.split(x); for (SQLExpr item : groupList) { if (x.getOperator() == SQLBinaryOperator.Add || x.getOperator() == SQLBinaryOperator.Concat) { List<SQLExpr> groupList = SQLBinaryOpExpr.split(x); if (groupList.size() >= 4) {
private boolean isCond(SQLBinaryOpExpr expr) { SQLExpr leftSide = expr.getLeft(); if (leftSide instanceof SQLMethodInvokeExpr) { return isAllowedMethodOnConditionLeft((SQLMethodInvokeExpr) leftSide, expr.getOperator()); } return leftSide instanceof SQLIdentifierExpr || leftSide instanceof SQLPropertyExpr || leftSide instanceof SQLVariantRefExpr; }
SQLBinaryOperator operator = binaryOpWhere.getOperator(); if (operator == SQLBinaryOperator.BooleanAnd || operator == SQLBinaryOperator.BooleanOr) { List<SQLExpr> items = SQLBinaryOpExpr.split(binaryOpWhere);
SQLBinaryOpExpr binaryB = (SQLBinaryOpExpr) b; if (binaryA.getOperator() != SQLBinaryOperator.Equality) { return false; if (binaryB.getOperator() != SQLBinaryOperator.Equality) { return false;
private void routeCond(SQLBinaryOpExpr bExpr, SQLExpr sub, Where where) throws SqlParseException { if (sub instanceof SQLBinaryOpExpr && !isCond((SQLBinaryOpExpr) sub)) { SQLBinaryOpExpr binarySub = (SQLBinaryOpExpr) sub; if (binarySub.getOperator().priority != bExpr.getOperator().priority) { Where subWhere = new Where(bExpr.getOperator().name); where.addWhere(subWhere); parseWhere(binarySub, subWhere);//zhongshu-comment 递归调用parseWhere(),解析出where子句中的多个条件 } else { parseWhere(binarySub, where);//zhongshu-comment 递归调用parseWhere(),解析出where子句中的多个条件 } } else if (sub instanceof SQLNotExpr) { Where subWhere = new Where(bExpr.getOperator().name); where.addWhere(subWhere); parseWhere(((SQLNotExpr) sub).getExpr(), subWhere);//zhongshu-comment 递归调用parseWhere(),解析出where子句中的多个条件 negateWhere(subWhere); } else { explanCond(bExpr.getOperator().name, sub, where); } }
public boolean visit(SQLIdentifierExpr x) { String name = x.getName(); if ("+".equalsIgnoreCase(name)) { return false; } long hashCode64 = x.hashCode64(); if (hashCode64 == FnvHash.Constants.ROWNUM || hashCode64 == FnvHash.Constants.SYSDATE || hashCode64 == FnvHash.Constants.LEVEL || hashCode64 == FnvHash.Constants.SQLCODE) { return false; } if (hashCode64 == FnvHash.Constants.ISOPEN && x.getParent() instanceof SQLBinaryOpExpr && ((SQLBinaryOpExpr) x.getParent()).getOperator() == SQLBinaryOperator.Modulus) { return false; } return super.visit(x); }
private static Field makeScriptMethodField(SQLBinaryOpExpr binaryExpr, String alias, String tableAlias) throws SqlParseException { List<SQLExpr> params = new ArrayList<>(); String scriptFieldAlias; if (alias == null || alias.equals("")) scriptFieldAlias = binaryExpr.toString(); else scriptFieldAlias = alias; params.add(new SQLCharExpr(scriptFieldAlias)); Object left = getScriptValue(binaryExpr.getLeft()); Object right = getScriptValue(binaryExpr.getRight()); String script = String.format("%s %s %s", left, binaryExpr.getOperator().getName(), right); params.add(new SQLCharExpr(script)); return makeMethodField("script", params, null, null, tableAlias, false); }
public static boolean isValue(SQLExpr expr) { if (expr instanceof SQLLiteralExpr) { return true; } if (expr instanceof SQLVariantRefExpr) { return true; } if (expr instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) expr; SQLBinaryOperator op = binaryOpExpr.getOperator(); if (op == SQLBinaryOperator.Add || op == SQLBinaryOperator.Subtract || op == SQLBinaryOperator.Multiply) { return isValue(binaryOpExpr.getLeft()) && isValue(binaryOpExpr.getRight()); } } return false; }
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) parent; SQLExpr left = binaryOpExpr.getLeft(); SQLBinaryOperator op = binaryOpExpr.getOperator(); if (left instanceof SQLIdentifierExpr && op == SQLBinaryOperator.Equality) {
} else if (parent instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) parent; if (binaryOpExpr.getOperator() == SQLBinaryOperator.Equality) { in = true; } else {
public boolean visit(SQLNotExpr x) { print0(ucase ? "NOT " : "not "); SQLExpr expr = x.getExpr(); boolean needQuote = false; if (expr instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) expr; needQuote = binaryOpExpr.getOperator().isLogical(); } else if (expr instanceof SQLInListExpr || expr instanceof SQLNotExpr) { needQuote = true; } if (needQuote) { print('('); } printExpr(expr); if (needQuote) { print(')'); } return false; }
private void visitBinaryLeft(SQLExpr left, SQLBinaryOperator op) { if (left instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr binaryLeft = (SQLBinaryOpExpr) left; SQLBinaryOperator leftOp = binaryLeft.getOperator(); boolean leftRational = leftOp == SQLBinaryOperator.BooleanAnd || leftOp == SQLBinaryOperator.BooleanOr; if (leftOp.priority > op.priority || (binaryLeft.isBracket() && leftOp != op && leftOp.isLogical() && op.isLogical() )) { if (leftRational) { this.indentCount++; } print('('); printExpr(left); print(')'); if (leftRational) { this.indentCount--; } } else { printExpr(left); } } else { printExpr(left); } }
public static void exportParameter(final List<Object> parameters, SQLBinaryOpExpr x) { if (x.getLeft() instanceof SQLLiteralExpr && x.getRight() instanceof SQLLiteralExpr && x.getOperator().isRelational()) { return; } { SQLExpr leftResult = ExportParameterVisitorUtils.exportParameter(parameters, x.getLeft()); if (leftResult != x.getLeft()) { x.setLeft(leftResult); } } { SQLExpr rightResult = exportParameter(parameters, x.getRight()); if (rightResult != x.getRight()) { x.setRight(rightResult); } } }
private boolean explanSpecialCondWithBothSidesAreLiterals(SQLBinaryOpExpr bExpr, Where where) throws SqlParseException { if ((bExpr.getLeft() instanceof SQLNumericLiteralExpr || bExpr.getLeft() instanceof SQLCharExpr) && (bExpr.getRight() instanceof SQLNumericLiteralExpr || bExpr.getRight() instanceof SQLCharExpr) ) { SQLMethodInvokeExpr sqlMethodInvokeExpr = new SQLMethodInvokeExpr("script", null); String operator = bExpr.getOperator().getName(); if (operator.equals("=")) { operator = "=="; } sqlMethodInvokeExpr.addParameter( new SQLCharExpr(Util.expr2Object(bExpr.getLeft(), "'") + " " + operator + " " + Util.expr2Object(bExpr.getRight(), "'")) ); explanCond("AND", sqlMethodInvokeExpr, where); return true; } return false; }
SQLBinaryOperator rightOp = right.getOperator(); SQLBinaryOperator op = x.getOperator(); boolean rightRational = rightOp == SQLBinaryOperator.BooleanAnd || rightOp == SQLBinaryOperator.BooleanOr;