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


Java MySqlSelectQueryBlock.getSelectList方法代码示例

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


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

示例1: isSupportSelect

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private static boolean isSupportSelect(String stmt) {
    SQLStatementParser parser = new MySqlStatementParser(stmt);
    SQLStatement statement = parser.parseStatement();
    if (!(statement instanceof SQLSelectStatement)) {
        return false;
    }

    SQLSelectQuery sqlSelectQuery = ((SQLSelectStatement) statement).getSelect().getQuery();
    if (!(sqlSelectQuery instanceof MySqlSelectQueryBlock)) {
        return false;
    }
    MySqlSelectQueryBlock selectQueryBlock = (MySqlSelectQueryBlock) sqlSelectQuery;
    SQLTableSource mysqlFrom = selectQueryBlock.getFrom();
    if (mysqlFrom != null) {
        return false;
    }
    for (SQLSelectItem item : selectQueryBlock.getSelectList()) {
        SQLExpr selectItem = item.getExpr();
        if (!isVariantRef(selectItem)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:25,代码来源:SelectHandler.java

示例2: isNoSharding

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
public static boolean isNoSharding(ServerConnection source, SQLSelectQuery sqlSelectQuery, SQLStatement selectStmt, String contextSchema, StringPtr sqlSchema)
        throws SQLException {
    if (sqlSelectQuery instanceof MySqlSelectQueryBlock) {
        MySqlSelectQueryBlock mySqlSelectQueryBlock = (MySqlSelectQueryBlock) sqlSelectQuery;
        if (!isNoSharding(source, mySqlSelectQueryBlock.getFrom(), selectStmt, contextSchema, sqlSchema)) {
            return false;
        }
        if (mySqlSelectQueryBlock.getWhere() != null && !SchemaUtil.isNoSharding(source, mySqlSelectQueryBlock.getWhere(), contextSchema, sqlSchema)) {
            return false;
        }
        for (SQLSelectItem selectItem : mySqlSelectQueryBlock.getSelectList()) {
            if (!SchemaUtil.isNoSharding(source, selectItem.getExpr(), contextSchema, sqlSchema)) {
                return false;
            }
        }
        return true;
    } else if (sqlSelectQuery instanceof MySqlUnionQuery) {
        return isNoSharding(source, (MySqlUnionQuery) sqlSelectQuery, selectStmt, contextSchema, sqlSchema);
    } else {
        return false;
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:23,代码来源:SchemaUtil.java

示例3: findSelect

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void findSelect(MySqlSelectQueryBlock query, Select select, String tableAlias) throws SqlParseException {
    List<SQLSelectItem> selectList = query.getSelectList();
    for (SQLSelectItem sqlSelectItem : selectList) {
        Field field = FieldMaker.makeField(sqlSelectItem.getExpr(), sqlSelectItem.getAlias(), tableAlias);
        select.addField(field);
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:8,代码来源:SqlParser.java

示例4: parseProcedureForSelect

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void parseProcedureForSelect(Procedure procedure, Set<String> outSet, String query, SQLSelectStatement statement) {
    MySqlSelectQueryBlock selectQuery = (MySqlSelectQueryBlock) statement.getSelect().getQuery();
    if (selectQuery != null) {
        List<SQLSelectItem> selectItems = selectQuery.getSelectList();
        for (SQLSelectItem selectItem : selectItems) {
            String select = selectItem.toString();
            outSet.add(select);
            procedure.getSelectColumns().add(select);
        }
    }
    procedure.setSelectSql(query);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:13,代码来源:HintSQLHandler.java

示例5: testSelectItem

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Test
public void testSelectItem() {
    MySqlSelectQueryBlock query = getQuery("select sum(col1) from table1 where a >1 ");
    List<SQLSelectItem> items = query.getSelectList();

    MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset,null);
    items.get(0).accept(v);
    Item item = v.getItem();
    Assert.assertEquals(true, "SUM(col1)".equals(item.getItemName()));
}
 
开发者ID:actiontech,项目名称:dble,代码行数:11,代码来源:TestMySQLItemVisitor.java

示例6: parseOrderby

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
/**
 * 解析Orderby
 * @param result
 * @param plan
 * @param mysqlSelectQuery
 */
protected void parseOrderby(ParseResult result, ExecutePlan plan, MySqlSelectQueryBlock mysqlSelectQuery){
    if (mysqlSelectQuery.getOrderBy() == null){
        return;
    }
    List<SQLSelectOrderByItem> orderByItems = mysqlSelectQuery.getOrderBy().getItems();
    if (orderByItems == null || orderByItems.size() == 0){
        return;
    }
    List<SQLSelectItem> selectList      = mysqlSelectQuery.getSelectList();
    List<OrderbyColumn> orderbyColumns  = new ArrayList<OrderbyColumn>(orderByItems.size());
    for(SQLSelectOrderByItem item : orderByItems){
        String name = StringUtil.removeDot(item.getExpr().toString());
        if (result.getAliaColumns() != null){
            String alias = result.getAliaColumns().get(name);
            if (alias != null){
                // select user_id as uid ....order by user_id
                // 要把oderby的user_id转换为uid,以便结果集合并
                orderbyColumns.add(new OrderbyColumn(alias, OrderbyColumn.buildOrderbyType(item.getType())));
                continue;
            }
        }
        if (!result.isHasAllColumnExpr()){
            // select列表中没有orderby的字段 添加,用于后面做合并
            SQLIdentifierExpr exp = new SQLIdentifierExpr(name);

            // item
            SQLSelectItem addItem = new SQLSelectItem();
            addItem.setExpr(exp);
            exp.setParent(item);
            selectList.add(addItem);
        }
        orderbyColumns.add(new OrderbyColumn(name, OrderbyColumn.buildOrderbyType(item.getType())));
    }
    plan.setOrderbyColumns(orderbyColumns);
}
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:42,代码来源:MySqlSelectParser.java

示例7: visit

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Override
public boolean visit(MySqlSelectQueryBlock x) {
	Map<String, SQLSelectItem> selectItemMap = result.getMergeContext().getSelectItemMap();
	Map<String, String> columnNameAliasMapping = result.getMergeContext().getColumnNameAliasMapping();

	for (SQLSelectItem column : x.getSelectList()) {
		String name = null;
		if (column.getExpr() instanceof SQLAggregateExpr) {
			SQLAggregateExpr expr = (SQLAggregateExpr) column.getExpr();
			SQLExpr argument = expr.getArguments().get(0);
			if (argument instanceof SQLAllColumnExpr) {
				name = expr.getMethodName() + "(*)";
			} else if(argument instanceof SQLIntegerExpr){
				name = expr.getMethodName() + "(1)";
			}else {
				name = expr.getMethodName() + "(" + ((SQLName) argument).getSimpleName() + ")";
				columnNameAliasMapping.put(((SQLName) argument).getSimpleName(), column.getAlias());
			}

			result.getMergeContext().setAggregate(true);
		} else if (column.getExpr() instanceof SQLIdentifierExpr || column.getExpr() instanceof SQLPropertyExpr) {
			name = ((SQLName) column.getExpr()).getSimpleName();

			if (column.getAlias() != null) {
				SQLName identifier = (SQLName) column.getExpr();
				columnNameAliasMapping.put(identifier.getSimpleName(), column.getAlias());
			}
		} else {
			// ignore SQLAllColumnExpr,SQLMethodInvokeExpr and etc.
		}

		selectItemMap.put(column.getAlias() == null ? name : column.getAlias(), column);
	}

	if (x.getDistionOption() == 2) {
		result.getMergeContext().setDistinct(true);
	}

	return true;
}
 
开发者ID:dianping,项目名称:zebra,代码行数:41,代码来源:MySQLSelectASTVisitor.java

示例8: findSelect

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void findSelect(MySqlSelectQueryBlock query, Select select,String tableAlias) throws SqlParseException {
    List<SQLSelectItem> selectList = query.getSelectList();
    for (SQLSelectItem sqlSelectItem : selectList) {
        Field field = FieldMaker.makeField(sqlSelectItem.getExpr(), sqlSelectItem.getAlias(),tableAlias);
        select.addField(field);
    }
}
 
开发者ID:selvakumarEsra,项目名称:es4sql,代码行数:8,代码来源:SqlParser.java

示例9: visit

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
public boolean visit(MySqlSelectQueryBlock sqlSelectQuery) {
    SQLTableSource from = sqlSelectQuery.getFrom();
    if (from != null) {
        visit(from);
        if (this.tableNode instanceof NoNameNode) {
            this.tableNode.setSql(SQLUtils.toMySqlString(sqlSelectQuery));
        }
    } else {
        this.tableNode = new NoNameNode(currentDb, SQLUtils.toMySqlString(sqlSelectQuery));
    }

    if (tableNode != null && (sqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCT || sqlSelectQuery.getDistionOption() == SQLSetQuantifier.DISTINCTROW)) {
        this.tableNode.setDistinct(true);
    }

    List<SQLSelectItem> items = sqlSelectQuery.getSelectList();
    if (items != null) {
        List<Item> selectItems = handleSelectItems(items);
        if (selectItems != null) {
            this.tableNode.select(selectItems);
        }
    }

    SQLExpr whereExpr = sqlSelectQuery.getWhere();
    if (whereExpr != null) {
        handleWhereCondition(whereExpr);
    }

    SQLOrderBy orderBy = sqlSelectQuery.getOrderBy();
    if (orderBy != null) {
        handleOrderBy(orderBy);
    }

    SQLSelectGroupByClause groupBy = sqlSelectQuery.getGroupBy();
    if (groupBy != null) {
        handleGroupBy(groupBy);
    }

    SQLLimit limit = sqlSelectQuery.getLimit();
    if (limit != null) {
        handleLimit(limit);
    }
    return true;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:45,代码来源:MySQLPlanNodeVisitor.java

示例10: parseGroupBy

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
/**
 * 解析groupby
 * @param result
 * @param plan
 * @param mysqlSelectQuery
 */
protected void parseGroupBy(ParseResult result, ExecutePlan plan, MySqlSelectQueryBlock mysqlSelectQuery){
    if(mysqlSelectQuery.getGroupBy() == null) {
        return;
    }
    List<SQLExpr> groupByItems = mysqlSelectQuery.getGroupBy().getItems();
    if (groupByItems == null || groupByItems.size() == 0){
        return;
    }
    List<SQLSelectItem> selectList      = mysqlSelectQuery.getSelectList();
    List<String> groupbyColumns  = new ArrayList<String>(groupByItems.size());
    for(SQLExpr item : groupByItems){
        String name = null;
        if (item instanceof MySqlSelectGroupByExpr){
            name = StringUtil.removeDot(((MySqlSelectGroupByExpr) item).getExpr().toString());
        }else if (item instanceof SQLIdentifierExpr){
            name = item.toString();
        }else if (item instanceof SQLName){
            name = ((SQLName) item).getSimpleName();
        }else {
            throw new BayMaxException("group by 不支持的表达式:" + item.toString());
        }
        if (result.getAliaColumns() != null){
            // 有别名,说明在select list中使用了别名
            String alias = result.getAliaColumns().get(name);
            if (alias != null){
                // select user_id as uid ....order by user_id
                // 要把oderby的user_id转换为uid,以便结果集合并,这个替换是等价的
                // 因为合并的时候需要根据orderby的字段,取值,比较
                groupbyColumns.add(alias);
                continue;
            }
        }
        if (!result.isHasAllColumnExpr()){
            // select列表中没有orderby的字段 添加,用于后面做合并
            SQLIdentifierExpr exp = new SQLIdentifierExpr(name);
            // item
            SQLSelectItem addItem = new SQLSelectItem();
            addItem.setExpr(exp);
            exp.setParent(item);
            selectList.add(addItem);
        }
        groupbyColumns.add(name);
    }
    plan.setGroupbyColumns(groupbyColumns);
}
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:52,代码来源:MySqlSelectParser.java


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