本文整理汇总了Java中com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getOrderBy方法的典型用法代码示例。如果您正苦于以下问题:Java MySqlSelectQueryBlock.getOrderBy方法的具体用法?Java MySqlSelectQueryBlock.getOrderBy怎么用?Java MySqlSelectQueryBlock.getOrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock
的用法示例。
在下文中一共展示了MySqlSelectQueryBlock.getOrderBy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseOrderAggGroupMysql
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
protected void parseOrderAggGroupMysql(SchemaConfig schema, SQLStatement stmt, RouteResultset rrs, MySqlSelectQueryBlock mysqlSelectQuery)
{
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
// rrs.setGroupByCols((String[])visitor.getGroupByColumns().toArray());
if(!isNeedParseOrderAgg)
{
return;
}
Map<String, String> aliaColumns = parseAggGroupCommon(schema, stmt, rrs, mysqlSelectQuery);
//setOrderByCols
if(mysqlSelectQuery.getOrderBy() != null) {
List<SQLSelectOrderByItem> orderByItems = mysqlSelectQuery.getOrderBy().getItems();
rrs.setOrderByCols(buildOrderByCols(orderByItems,aliaColumns));
}
isNeedParseOrderAgg=false;
}
示例2: visit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Override
public boolean visit(MySqlSelectQueryBlock x) {
SQLOrderBy orderBy = x.getOrderBy();
SQLLimit limit = x.getLimit();
if (limit != null && (orderBy == null || orderBy.getItems().size() == 0)) {
boolean subQueryHasOrderBy = false;
SQLTableSource from = x.getFrom();
if (from instanceof SQLSubqueryTableSource) {
SQLSubqueryTableSource subqueryTabSrc = (SQLSubqueryTableSource) from;
SQLSelect select = subqueryTabSrc.getSelect();
if (select.getQuery() instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock subquery = (SQLSelectQueryBlock) select.getQuery();
if (subquery.getOrderBy() != null && subquery.getOrderBy().getItems().size() > 0) {
subQueryHasOrderBy = true;
}
}
}
if (!subQueryHasOrderBy) {
unorderedLimitCount++;
}
}
return true;
}
示例3: findOrderBy
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void findOrderBy(MySqlSelectQueryBlock query, Select select) throws SqlParseException {
SQLOrderBy orderBy = query.getOrderBy();
if (orderBy == null) {
return;
}
List<SQLSelectOrderByItem> items = orderBy.getItems();
List<String> lists = new ArrayList<>();
for (SQLSelectOrderByItem sqlSelectOrderByItem : items) {
SQLExpr expr = sqlSelectOrderByItem.getExpr();
lists.add(FieldMaker.makeField(expr, null,null).toString());
if (sqlSelectOrderByItem.getType() == null) {
sqlSelectOrderByItem.setType(SQLOrderingSpecification.ASC);
}
String type = sqlSelectOrderByItem.getType().toString();
for (String name : lists) {
name = name.replace("`", "");
select.addOrderBy(name, type);
}
lists.clear();
}
}
示例4: findOrderBy
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void findOrderBy(MySqlSelectQueryBlock query, Select select) throws SqlParseException {
SQLOrderBy orderBy = query.getOrderBy();
if (orderBy == null) {
return;
}
List<SQLSelectOrderByItem> items = orderBy.getItems();
addOrderByToSelect(select, items, null);
}
示例5: parseOrderAggGroupMysql
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
private void parseOrderAggGroupMysql(SchemaConfig schema, SQLStatement stmt, RouteResultset rrs,
MySqlSelectQueryBlock mysqlSelectQuery, TableConfig tc) throws SQLException {
//simple merge of ORDER BY has bugs,so optimizer here
if (mysqlSelectQuery.getOrderBy() != null) {
tryAddLimit(schema, tc, mysqlSelectQuery);
rrs.setSqlStatement(stmt);
rrs.setNeedOptimizer(true);
return;
}
parseAggGroupCommon(schema, stmt, rrs, mysqlSelectQuery, tc);
}
示例6: testOrderby
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
@Test
public void testOrderby() {
MySqlSelectQueryBlock query = getQuery("select col1,col2 from table1 order by col1 asc, col2 desc ");
SQLOrderBy orderBy = query.getOrderBy();
int i = 0;
for (SQLSelectOrderByItem p : orderBy.getItems()) {
i++;
String orderCol = "col" + i;
SQLExpr expr = p.getExpr();
MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
expr.accept(v);
Item item = v.getItem();
Assert.assertEquals(true, orderCol.equals(item.getItemName()));
}
}
示例7: 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);
}
示例8: visit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入方法依赖的package包/类
public boolean visit(MySqlSelectQueryBlock x) {
if (x.getOrderBy() != null) {
x.getOrderBy().setParent(x);
}
print0(ucase ? "SELECT COUNT(*) " : "select count(*) ");
if (x.getFrom() != null) {
println();
print0(ucase ? "FROM " : "from ");
x.getFrom().accept(this);
}
if (x.getWhere() != null) {
println();
print0(ucase ? "WHERE " : "where ");
x.getWhere().setParent(x);
x.getWhere().accept(this);
}
if (x.getGroupBy() != null) {
println();
x.getGroupBy().accept(this);
}
if (x.getOrderBy() != null) {
println();
x.getOrderBy().accept(this);
}
return false;
}
示例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;
}