Search in sources :

Example 1 with OrderByType

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn.OrderByType in project sharding-jdbc by dangdangdotcom.

the class MySQLSelectVisitor method visit.

public boolean visit(final SQLOrderBy x) {
    for (SQLSelectOrderByItem each : x.getItems()) {
        SQLExpr expr = each.getExpr();
        OrderByType orderByType = null == each.getType() ? OrderByType.ASC : OrderByType.valueOf(each.getType());
        if (expr instanceof SQLIntegerExpr) {
            getParseContext().addOrderByColumn(((SQLIntegerExpr) expr).getNumber().intValue(), orderByType);
        } else if (expr instanceof SQLIdentifierExpr) {
            getParseContext().addOrderByColumn(Optional.<String>absent(), ((SQLIdentifierExpr) expr).getName(), orderByType);
        } else if (expr instanceof SQLPropertyExpr) {
            SQLPropertyExpr sqlPropertyExpr = (SQLPropertyExpr) expr;
            getParseContext().addOrderByColumn(Optional.of(sqlPropertyExpr.getOwner().toString()), sqlPropertyExpr.getName(), orderByType);
        }
    }
    return super.visit(x);
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLIntegerExpr(com.alibaba.druid.sql.ast.expr.SQLIntegerExpr) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) OrderByType(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn.OrderByType)

Example 2 with OrderByType

use of com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn.OrderByType in project sharding-jdbc by dangdangdotcom.

the class MySQLSelectVisitor method visit.

/**
     * 将GROUP BY列放入parseResult.
     * 直接返回false,防止重复解析GROUP BY表达式.
     * 
     * @param x GROUP BY 表达式
     * @return false 停止遍历AST
     */
@Override
public boolean visit(final MySqlSelectGroupByExpr x) {
    OrderByType orderByType = null == x.getType() ? OrderByType.ASC : OrderByType.valueOf(x.getType());
    if (x.getExpr() instanceof SQLPropertyExpr) {
        SQLPropertyExpr expr = (SQLPropertyExpr) x.getExpr();
        getParseContext().addGroupByColumns(Optional.of(expr.getOwner().toString()), expr.getName(), orderByType);
    } else if (x.getExpr() instanceof SQLIdentifierExpr) {
        SQLIdentifierExpr expr = (SQLIdentifierExpr) x.getExpr();
        getParseContext().addGroupByColumns(Optional.<String>absent(), expr.getName(), orderByType);
    }
    return super.visit(x);
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) OrderByType(com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn.OrderByType)

Aggregations

SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)2 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)2 OrderByType (com.dangdang.ddframe.rdb.sharding.parser.result.merger.OrderByColumn.OrderByType)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)1 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)1