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


Java SQLExpr.getClass方法代码示例

本文整理汇总了Java中com.alibaba.druid.sql.ast.SQLExpr.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java SQLExpr.getClass方法的具体用法?Java SQLExpr.getClass怎么用?Java SQLExpr.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.druid.sql.ast.SQLExpr的用法示例。


在下文中一共展示了SQLExpr.getClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: genDuplicate

import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的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

示例2: columnInExpr

import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private static boolean columnInExpr(SQLExpr sqlExpr, String colName) throws SQLNonTransientException {
    String column;
    if (sqlExpr instanceof SQLIdentifierExpr) {
        column = StringUtil.removeBackquote(((SQLIdentifierExpr) sqlExpr).getName()).toUpperCase();
    } else if (sqlExpr instanceof SQLPropertyExpr) {
        column = StringUtil.removeBackquote(((SQLPropertyExpr) sqlExpr).getName()).toUpperCase();
    } else {
        throw new SQLNonTransientException("Unhandled SQL AST node type encountered: " + sqlExpr.getClass());
    }

    return column.equals(colName.toUpperCase());
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:13,代码来源:DruidUpdateParser.java

示例3: columnInExpr

import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private static boolean columnInExpr(SQLExpr sqlExpr, String colName) throws SQLNonTransientException {
    String column;
    if (sqlExpr instanceof SQLIdentifierExpr) {
        column = StringUtil.removeBackQuote(((SQLIdentifierExpr) sqlExpr).getName()).toUpperCase();
    } else if (sqlExpr instanceof SQLPropertyExpr) {
        column = StringUtil.removeBackQuote(((SQLPropertyExpr) sqlExpr).getName()).toUpperCase();
    } else {
        throw new SQLNonTransientException("Unhandled SQL AST node type encountered: " + sqlExpr.getClass());
    }

    return column.equals(colName.toUpperCase());
}
 
开发者ID:actiontech,项目名称:dble,代码行数:13,代码来源:DruidUpdateParser.java

示例4: shardColCanBeUpdated

import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private boolean shardColCanBeUpdated(SQLExpr whereClauseExpr, String column, SQLExpr value, boolean hasOR)
        throws SQLNonTransientException {
    boolean canUpdate = false;
    boolean parentHasOR = false;

    if (whereClauseExpr == null)
        return false;

    if (whereClauseExpr instanceof SQLBinaryOpExpr) {
        SQLBinaryOpExpr nodeOpExpr = (SQLBinaryOpExpr) whereClauseExpr;
        /*
        * 条件中有or或者xor的,如果分片字段出现在or/xor的一个子句中,则此update
        * 语句无法执行
         */
        if ((nodeOpExpr.getOperator() == SQLBinaryOperator.BooleanOr) ||
                (nodeOpExpr.getOperator() == SQLBinaryOperator.BooleanXor)) {
            parentHasOR = true;
        }
        // 发现类似 col = value 的子句
        if (nodeOpExpr.getOperator() == SQLBinaryOperator.Equality) {
            boolean foundCol;
            SQLExpr leftExpr = nodeOpExpr.getLeft();
            SQLExpr rightExpr = nodeOpExpr.getRight();

            foundCol = columnInExpr(leftExpr, column);

            // 发现col = value子句,col刚好是分片字段,比较value与update要更新的值是否一样,并且是否在or/xor子句中
            if (foundCol) {
                if (rightExpr.getClass() != value.getClass()) {
                    throw new SQLNonTransientException("SQL AST nodes type mismatch!");
                }

                canUpdate = rightExpr.toString().equals(value.toString()) && (!hasOR) && (!parentHasOR);
            }
        } else if (nodeOpExpr.getOperator().isLogical()) {
            if (nodeOpExpr.getLeft() != null) {
                if (nodeOpExpr.getLeft() instanceof SQLBinaryOpExpr) {
                    canUpdate = shardColCanBeUpdated(nodeOpExpr.getLeft(), column, value, parentHasOR);
                }
                // else
                // 此子语句不是 =,>,<等关系运算符(对应的类是SQLBinaryOpExpr)。比如between X and Y
                // 或者 NOT,或者单独的子查询,这些情况,我们不做处理
            }
            if ((!canUpdate) && nodeOpExpr.getRight() != null) {
                if (nodeOpExpr.getRight() instanceof SQLBinaryOpExpr) {
                    canUpdate = shardColCanBeUpdated(nodeOpExpr.getRight(), column, value, parentHasOR);
                }
                // else
                // 此子语句不是 =,>,<等关系运算符(对应的类是SQLBinaryOpExpr)。比如between X and Y
                // 或者 NOT,或者单独的子查询,这些情况,我们不做处理
            }
        } else if (isSubQueryClause(nodeOpExpr)){
            // 对于子查询的检查有点复杂,这里暂时不支持
            return false;
        }
        // else
        // 其他类型的子句,忽略, 如果分片字段在这类子句中,此类情况目前不做处理,将返回false
    }
    // else
    //此处说明update的where只有一个条件,并且不是 =,>,<等关系运算符(对应的类是SQLBinaryOpExpr)。比如between X and Y
    // 或者 NOT,或者单独的子查询,这些情况,我们都不做处理

    return canUpdate;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:65,代码来源:DruidUpdateParser.java

示例5: shardColCanBeUpdated

import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
/**
 * check shardColCanBeUpdated
 * o the partition col is in OR/XOR filter,it will Failed.
 * eg :update mytab set ptn_col = val, col1 = val1 where col1 = val11 or ptn_col = val;
 * o if the set statement has the same value with the where condition,and we can router to some node
 * eg1:update mytab set ptn_col = val, col1 = val1 where ptn_col = val and (col1 = val11 or col2 = val2);
 * eg2 :update mytab set ptn_col = val, col1 = val1 where ptn_col = val and col1 = val11 and col2 = val2;
 * o update the partition column but partition column is not not in where filter. Failed
 * eg:update mytab set ptn_col = val, col1 = val1 where col1 = val11 and col2 = val22;
 * o the other operator, like between,not, Just Failed.
 *
 * @param whereClauseExpr
 * @param column
 * @param value
 * @return true Passed, false Failed
 * @hasOR the parent of whereClauseExpr hasOR/XOR
 */
private boolean shardColCanBeUpdated(SQLExpr whereClauseExpr, String column, SQLExpr value, boolean hasOR)
        throws SQLNonTransientException {
    boolean canUpdate = false;
    boolean parentHasOR = false;

    if (whereClauseExpr == null)
        return false;

    if (whereClauseExpr instanceof SQLBinaryOpExpr) {
        SQLBinaryOpExpr nodeOpExpr = (SQLBinaryOpExpr) whereClauseExpr;
        /*
         * partition column exists in or/xor expr
         */
        if ((nodeOpExpr.getOperator() == SQLBinaryOperator.BooleanOr) ||
                (nodeOpExpr.getOperator() == SQLBinaryOperator.BooleanXor)) {
            parentHasOR = true;
        }
        if (nodeOpExpr.getOperator() == SQLBinaryOperator.Equality) {
            boolean foundCol;
            SQLExpr leftExpr = nodeOpExpr.getLeft();
            SQLExpr rightExpr = nodeOpExpr.getRight();

            foundCol = columnInExpr(leftExpr, column);

            // col is partition column, 1.check it is in OR expr or not
            // 2.check the value is the same to update set expr
            if (foundCol) {
                if (rightExpr.getClass() != value.getClass()) {
                    throw new SQLNonTransientException("SQL AST nodes type mismatch!");
                }

                canUpdate = rightExpr.toString().equals(value.toString()) && (!hasOR) && (!parentHasOR);
            }
        } else if (nodeOpExpr.getOperator().isLogical()) {
            if (nodeOpExpr.getLeft() != null) {
                if (nodeOpExpr.getLeft() instanceof SQLBinaryOpExpr) {
                    canUpdate = shardColCanBeUpdated(nodeOpExpr.getLeft(), column, value, parentHasOR);
                }
                // else  !=,>,< between X and Y ,NOT ,just Failed
            }
            if ((!canUpdate) && nodeOpExpr.getRight() != null) {
                if (nodeOpExpr.getRight() instanceof SQLBinaryOpExpr) {
                    canUpdate = shardColCanBeUpdated(nodeOpExpr.getRight(), column, value, parentHasOR);
                }
                // else  !=,>,< between X and Y ,NOT ,just Failed
            }
        } else if (isSubQueryClause(nodeOpExpr)) {
            // subQuery ,just Failed
            return false;
        }
        // else other expr,just Failed
    }
    // else  single condition but is not = ,just Failed
    return canUpdate;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:73,代码来源:DruidUpdateParser.java


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