当前位置: 首页>>代码示例>>Java>>正文


Java SQLBinaryOpExpr类代码示例

本文整理汇总了Java中com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr的典型用法代码示例。如果您正苦于以下问题:Java SQLBinaryOpExpr类的具体用法?Java SQLBinaryOpExpr怎么用?Java SQLBinaryOpExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SQLBinaryOpExpr类属于com.alibaba.druid.sql.ast.expr包,在下文中一共展示了SQLBinaryOpExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: splitUntilNoOr

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
/**
	 * 递归拆分OR
	 * 
	 * @param whereUnit
	 * TODO:考虑嵌套or语句,条件中有子查询、 exists等很多种复杂情况是否能兼容
	 */
	private void splitUntilNoOr(WhereUnit whereUnit) {
		if(whereUnit.isFinishedParse()) {
			if(whereUnit.getSubWhereUnit().size() > 0) {
				for(int i = 0; i < whereUnit.getSubWhereUnit().size(); i++) {
					splitUntilNoOr(whereUnit.getSubWhereUnit().get(i));
				}
			} 
		} else {
			SQLBinaryOpExpr expr = whereUnit.getCanSplitExpr();
			if(expr.getOperator() == SQLBinaryOperator.BooleanOr) {
//				whereUnit.addSplitedExpr(expr.getRight());
				addExprIfNotFalse(whereUnit, expr.getRight());
				if(expr.getLeft() instanceof SQLBinaryOpExpr) {
					whereUnit.setCanSplitExpr((SQLBinaryOpExpr)expr.getLeft());
					splitUntilNoOr(whereUnit);
				} else {
					addExprIfNotFalse(whereUnit, expr.getLeft());
				}
			} else {
				addExprIfNotFalse(whereUnit, expr);
				whereUnit.setFinishedParse(true);
			}
		}
    }
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:31,代码来源:MycatSchemaStatVisitor.java

示例2: visit

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
@Override
public boolean visit(SQLBinaryOpExpr x) {
       x.getLeft().setParent(x);
       x.getRight().setParent(x);

       if (!SQLBinaryOperator.BooleanOr.equals(x.getOperator())) {
           return super.visit(x);
       }

       // true * (a and b) = (a and b) 没有意义
       if (Boolean.TRUE.equals(WallVisitorUtils.getValue(x))) {
           return false;
       }

       // 这是一个Or表达式 这个or代表的集合是要和当前已经获取的Condition列表 相乘的.
       orEntity.add(new OrEntity(this, x));
       return false;
   }
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:19,代码来源:OrVisitor.java

示例3: opSQLExpr

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
private void opSQLExpr(SQLBinaryOpExpr expr,String Operator) {
	   if (expr==null) {
		   return;
	   }
	   SQLExpr exprL=expr.getLeft();
	   if (!(exprL instanceof SQLBinaryOpExpr))
	   {
		   String field=exprL.toString();
		   String value=getExpValue(expr.getRight()).toString();
		   if (expr.getOperator()==SQLBinaryOperator.Equality) {  
			 if (checkJoinField(value)) {
				//joinLkey=field;
				//joinRkey=value; 
				tableFilter.setJoinKey(field,value);
			 }
			 else {
				 tableFilter.addWhere(field, value, expr.getOperator().getName(), Operator);
			 }
		   }
		   else {
			   tableFilter.addWhere(field, value, expr.getOperator().getName(), Operator);
		   }
	   }		
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:25,代码来源:JoinParser.java

示例4: genDuplicate

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
private void genDuplicate(boolean isGlobalCheck, StringBuilder sb, List<SQLExpr> dku) throws SQLNonTransientException {
    boolean flag = false;
    sb.append(" on duplicate key update ");
    for (int i = 0; i < dku.size(); i++) {
        SQLExpr exp = dku.get(i);
        if (!(exp instanceof SQLBinaryOpExpr)) {
            String msg = "not supported! on duplicate key update exp is " + exp.getClass();
            LOGGER.info(msg);
            throw new SQLNonTransientException(msg);
        }
        SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) exp;
        if (isGlobalCheck && !flag && GlobalTableUtil.GLOBAL_TABLE_CHECK_COLUMN.equals(binaryOpExpr.getLeft().toString())) {
            flag = true;
            onDuplicateGlobalColumn(sb);
        } else {
            sb.append(binaryOpExpr.toString());
        }
        if (i < dku.size() - 1) {
            sb.append(",");
        }
    }
    if (isGlobalCheck && !flag) {
        sb.append(",");
        onDuplicateGlobalColumn(sb);
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:27,代码来源:DruidInsertParser.java

示例5: visit

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
/**
    * 二元表达
    * @param x
    * @return
    */
   @Override
public boolean visit(SQLBinaryOpExpr x) {
       x.getLeft().setParent(x);
       x.getRight().setParent(x);
       switch (x.getOperator()) {
           case Equality:
               // a=1 and a=2 or a=3
               handleCondition(x.getLeft(), x.getOperator().name, x.getRight());
               // a=b 转化为 b=a
               // a=1 不用转化
               handleCondition(x.getRight(), x.getOperator().name, x.getLeft());
               handleRelationship(x.getLeft(), x.getOperator().name, x.getRight());
               break;
           case BooleanOr:
               this.hasOrCondition = true;
               break;
           default:
               break;
       }
       return true;
   }
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:27,代码来源:SqlVisitor.java

示例6: visit

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
/**
 * 将表名替换成占位符.
 * 
 * <p>
 * 1. 如果二元表达式使用别名, 如: {@code FROM order o WHERE o.column_name = 't' },
 * 则Column中的tableName为o.
 * </p>
 * 
 * <p>
 * 2. 如果二元表达式使用表名, 如: {@code FROM order WHERE order.column_name = 't' },
 * 则Column中的tableName为order.
 * </p>
 * 
 * @param x
 *            SQL属性表达式
 * @return true表示继续遍历AST, false表示终止遍历AST
 */
@Override
// TODO SELECT [别名.xxx]的情况,目前都是替换成token,解析之后应该替换回去
public final boolean visit(final SQLPropertyExpr x) {
	if (!(x.getParent() instanceof SQLBinaryOpExpr) && !(x.getParent() instanceof SQLSelectItem)) {
		return super.visit(x);
	}
	if (!(x.getOwner() instanceof SQLIdentifierExpr)) {
		return super.visit(x);
	}
	String tableOrAliasName = ((SQLIdentifierExpr) x.getOwner()).getLowerName();
	if (isBinaryOperateWithAlias(x, tableOrAliasName)) {
		return super.visit(x);
	}
	printToken(tableOrAliasName);
	print(".");
	print(x.getName());
	return false;
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:36,代码来源:AbstractPGSQLVisitor.java

示例7: visit

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
/**
 * 逻辑OR访问器, 每次只解析一层OR条件.
 * 
 * @param x 二元表达式
 * @return false 停止访问AST
 */
@Override
public boolean visit(final SQLBinaryOpExpr x) {
    if (!SQLBinaryOperator.BooleanOr.equals(x.getOperator())) {
        return super.visit(x);
    }
    if (Boolean.TRUE.equals(WallVisitorUtils.getValue(x))) {
        return false;
    }
    if (orASTNode == null) {
        orASTNode = new SimpleOrASTNode(x, new OrPgsqlVisitor(this));
    } else {
        CompositeOrASTNode existingOutConditionOrASTNode = new CompositeOrASTNode();
        existingOutConditionOrASTNode.addSubNode(orASTNode);
        existingOutConditionOrASTNode.addSubNode(new SimpleOrASTNode(x, new OrPgsqlVisitor(this)));
        orASTNode = existingOutConditionOrASTNode;
    }
    return false;
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:25,代码来源:OrPgsqlVisitor.java

示例8: visit

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
/**
 * 逻辑OR访问器, 每次只解析一层OR条件.
 * 
 * @param x 二元表达式
 * @return false 停止访问AST
 */
@Override
public boolean visit(final SQLBinaryOpExpr x) {
    if (!SQLBinaryOperator.BooleanOr.equals(x.getOperator())) {
        return super.visit(x);
    }
    if (Boolean.TRUE.equals(WallVisitorUtils.getValue(x))) {
        return false;
    }
    if (orASTNode == null) {
        orASTNode = new SimpleOrASTNode(x, new OrOracleVisitor(this));
    } else {
        CompositeOrASTNode existingOutConditionOrASTNode = new CompositeOrASTNode();
        existingOutConditionOrASTNode.addSubNode(orASTNode);
        existingOutConditionOrASTNode.addSubNode(new SimpleOrASTNode(x, new OrOracleVisitor(this)));
        orASTNode = existingOutConditionOrASTNode;
    }
    return false;
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:25,代码来源:OrOracleVisitor.java

示例9: visit

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
/**
 * 逻辑OR访问器, 每次只解析一层OR条件.
 * 
 * @param x 二元表达式
 * @return false 停止访问AST
 */
@Override
public boolean visit(final SQLBinaryOpExpr x) {
    if (!SQLBinaryOperator.BooleanOr.equals(x.getOperator())) {
        return super.visit(x);
    }
    if (Boolean.TRUE.equals(WallVisitorUtils.getValue(x))) {
        return false;
    }
    if (orASTNode == null) {
        orASTNode = new SimpleOrASTNode(x, new OrMySQLVisitor(this));
    } else {
        CompositeOrASTNode existingOutConditionOrASTNode = new CompositeOrASTNode();
        existingOutConditionOrASTNode.addSubNode(orASTNode);
        existingOutConditionOrASTNode.addSubNode(new SimpleOrASTNode(x, new OrMySQLVisitor(this)));
        orASTNode = existingOutConditionOrASTNode;
    }
    return false;
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:25,代码来源:OrMySQLVisitor.java

示例10: visit

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
/**
 * 将表名替换成占位符.
 * 
 * <p>
 * 1. 如果二元表达式使用别名, 如: {@code FROM order o WHERE o.column_name = 't' },
 * 则Column中的tableName为o.
 * </p>
 * 
 * <p>
 * 2. 如果二元表达式使用表名, 如: {@code FROM order WHERE order.column_name = 't' },
 * 则Column中的tableName为order.
 * </p>
 * 
 * @param x
 *            SQL属性表达式
 * @return true表示继续遍历AST, false表示终止遍历AST
 */
@Override
public final boolean visit(final SQLPropertyExpr x) {
	if (!(x.getParent() instanceof SQLBinaryOpExpr) && !(x.getParent() instanceof SQLSelectItem)) {
		return super.visit(x);
	}
	if (!(x.getOwner() instanceof SQLIdentifierExpr)) {
		return super.visit(x);
	}
	String tableOrAliasName = ((SQLIdentifierExpr) x.getOwner()).getLowerName();
	if (isBinaryOperateWithAlias(x, tableOrAliasName)) {
		return super.visit(x);
	}
	printToken(tableOrAliasName);
	print(".");
	print(x.getName());
	return false;
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:35,代码来源:AbstractOracleVisitor.java

示例11: explanSpecialCondWithBothSidesAreLiterals

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
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;
}
 
开发者ID:NLPchina,项目名称:elasticsearch-sql,代码行数:21,代码来源:WhereParser.java

示例12: parserWhere

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
private void parserWhere(SQLExpr aexpr,String Operator){
	 if (aexpr==null) {
		 return;
	 }
     if (aexpr instanceof SQLBinaryOpExpr){
	   SQLBinaryOpExpr expr=(SQLBinaryOpExpr)aexpr;  
	   SQLExpr exprL=expr.getLeft();
	   if (!(exprL instanceof SQLBinaryOpExpr))
	   {
		  opSQLExpr((SQLBinaryOpExpr)aexpr,Operator);			  
	   }
	   else {
		// if (expr.getOperator().getName().equals("AND")) { 
		 if (expr.getOperator()==SQLBinaryOperator.BooleanAnd) { 	 
		   //parserWhere(exprL); 
		   //parserWhere(expr.getRight());
		   andorWhere(exprL,expr.getOperator().getName(),expr.getRight());
		 }
		 else if (expr.getOperator()==SQLBinaryOperator.BooleanOr){//.getName().equals("OR")) {  
			andorWhere(exprL,expr.getOperator().getName(),expr.getRight()); 				
		 }
		 else {
			 throw new RuntimeException("Can't identify the operation of  of where"); 
		 }
	   }
   }		
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:28,代码来源:JoinParser.java

示例13: parseThreeLevelPageSql

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
private void parseThreeLevelPageSql(SQLStatement stmt, RouteResultset rrs, SchemaConfig schema, SQLSubqueryTableSource from, SQLBinaryOpExpr one, SQLBinaryOperator operator)
{
       SQLIntegerExpr right = (SQLIntegerExpr) one.getRight();
	int firstrownum = right.getNumber().intValue();
	if (operator == SQLBinaryOperator.GreaterThanOrEqual&&firstrownum!=0) {
		firstrownum = firstrownum - 1;
	}
	SQLSelectQuery subSelect = from.getSelect().getQuery();
	if (subSelect instanceof OracleSelectQueryBlock)
       {  //第二层子查询
           OracleSelectQueryBlock twoSubSelect = (OracleSelectQueryBlock) subSelect;
           if (twoSubSelect.getWhere() instanceof SQLBinaryOpExpr && twoSubSelect.getFrom() instanceof SQLSubqueryTableSource)
           {
               SQLBinaryOpExpr twoWhere = (SQLBinaryOpExpr) twoSubSelect.getWhere();
               boolean isRowNum = "rownum".equalsIgnoreCase(twoWhere.getLeft().toString());
               boolean isLess = twoWhere.getOperator() == SQLBinaryOperator.LessThanOrEqual || twoWhere.getOperator() == SQLBinaryOperator.LessThan;
               if (isRowNum && twoWhere.getRight() instanceof SQLIntegerExpr && isLess)
               {
                   int lastrownum = ((SQLIntegerExpr) twoWhere.getRight()).getNumber().intValue();
                   if (operator == SQLBinaryOperator.LessThan&&lastrownum!=0) {
					lastrownum = lastrownum - 1;
				}
                   SQLSelectQuery finalQuery = ((SQLSubqueryTableSource) twoSubSelect.getFrom()).getSelect().getQuery();
                   if (finalQuery instanceof OracleSelectQueryBlock)
                   {
					setLimitIFChange(stmt, rrs, schema, one, firstrownum, lastrownum);
                       parseOrderAggGroupOracle(stmt,rrs, (OracleSelectQueryBlock) finalQuery, schema);
                       isNeedParseOrderAgg=false;
                   }

               }

           }

       }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:37,代码来源:DruidSelectOracleParser.java

示例14: printWhereClauseAST

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
public static void printWhereClauseAST(SQLExpr sqlExpr) {
    // where子句的AST sqlExpr可以通过 MySqlUpdateStatement.getWhere(); 获得
    if (sqlExpr == null)
        return;
    ArrayList<SQLExpr> exprNode = new ArrayList<>();
    int i = 0, curLevel = 1, nextLevel = 0;
    SQLExpr iterExpr;
    exprNode.add(sqlExpr);
    while (true) {
        iterExpr = exprNode.get(i++);
        if (iterExpr == null)
            break;

        if (iterExpr instanceof SQLBinaryOpExpr) {
            System.out.print(((SQLBinaryOpExpr) iterExpr).getOperator());
        } else {
            System.out.print(iterExpr.toString());
        }
        System.out.print("\t");
        curLevel--;

        if (iterExpr instanceof SQLBinaryOpExpr) {
            if (((SQLBinaryOpExpr) iterExpr).getLeft() != null) {
                exprNode.add(((SQLBinaryOpExpr) iterExpr).getLeft());
                nextLevel++;
            }
            if (((SQLBinaryOpExpr) iterExpr).getRight() != null) {
                exprNode.add(((SQLBinaryOpExpr) iterExpr).getRight());
                nextLevel++;
            }
        }
        if (curLevel == 0) {
            System.out.println("\t\tNum of nodes in next level: " + nextLevel);
            curLevel = nextLevel;
            nextLevel = 0;
        }
        if (exprNode.size() == i)
            break;
    }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:41,代码来源:DruidUpdateParserTest.java

示例15: containsCondition

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入依赖的package包/类
public boolean containsCondition(SQLExpr condition) {
    if (this.condition == null) {
        return false;
    }

    if (this.condition.equals(condition)) {
        return false;
    }

    if (this.condition instanceof SQLBinaryOpExpr) {
        return ((SQLBinaryOpExpr) this.condition).contains(condition);
    }

    return false;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:16,代码来源:SQLJoinTableSource.java


注:本文中的com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。