本文整理汇总了Java中com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock类的典型用法代码示例。如果您正苦于以下问题:Java MySqlSelectQueryBlock类的具体用法?Java MySqlSelectQueryBlock怎么用?Java MySqlSelectQueryBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySqlSelectQueryBlock类属于com.alibaba.druid.sql.dialect.mysql.ast.statement包,在下文中一共展示了MySqlSelectQueryBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: statementParse
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
@Override
public void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) {
SQLSelectStatement selectStmt = (SQLSelectStatement)stmt;
SQLSelectQuery sqlSelectQuery = selectStmt.getSelect().getQuery();
if(sqlSelectQuery instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)selectStmt.getSelect().getQuery();
parseOrderAggGroupMysql(schema, stmt,rrs, mysqlSelectQuery);
//更改canRunInReadDB属性
if ((mysqlSelectQuery.isForUpdate() || mysqlSelectQuery.isLockInShareMode()) && rrs.isAutocommit() == false)
{
rrs.setCanRunInReadDB(false);
}
} else if (sqlSelectQuery instanceof MySqlUnionQuery) {
// MySqlUnionQuery unionQuery = (MySqlUnionQuery)sqlSelectQuery;
// MySqlSelectQueryBlock left = (MySqlSelectQueryBlock)unionQuery.getLeft();
// MySqlSelectQueryBlock right = (MySqlSelectQueryBlock)unionQuery.getLeft();
// System.out.println();
}
}
示例2: 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;
}
示例3: isNeedCache
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
private boolean isNeedCache(SchemaConfig schema, RouteResultset rrs,
MySqlSelectQueryBlock mysqlSelectQuery, Map<String, Map<String, Set<ColumnRoutePair>>> allConditions) {
if(ctx.getTables() == null || ctx.getTables().size() == 0 ) {
return false;
}
TableConfig tc = schema.getTables().get(ctx.getTables().get(0));
if(tc==null ||(ctx.getTables().size() == 1 && tc.isGlobalTable())
) {//|| (ctx.getTables().size() == 1) && tc.getRule() == null && tc.getDataNodes().size() == 1
return false;
} else {
//单表主键查询
if(ctx.getTables().size() == 1) {
String tableName = ctx.getTables().get(0);
String primaryKey = schema.getTables().get(tableName).getPrimaryKey();
// schema.getTables().get(ctx.getTables().get(0)).getParentKey() != null;
if(ctx.getRouteCalculateUnit().getTablesAndConditions().get(tableName) != null
&& ctx.getRouteCalculateUnit().getTablesAndConditions().get(tableName).get(primaryKey) != null
&& tc.getDataNodes().size() > 1) {//有主键条件
return false;
}
}
return true;
}
}
示例4: isConditionAlwaysTrue
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
private boolean isConditionAlwaysTrue(SQLStatement statement) {
SQLSelectStatement selectStmt = (SQLSelectStatement)statement;
SQLSelectQuery sqlSelectQuery = selectStmt.getSelect().getQuery();
if(sqlSelectQuery instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)selectStmt.getSelect().getQuery();
SQLExpr expr = mysqlSelectQuery.getWhere();
Object o = WallVisitorUtils.getValue(expr);
if(Boolean.TRUE.equals(o)) {
return true;
}
return false;
} else {//union
return false;
}
}
示例5: statementParse
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
@Override
public void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) {
SQLSelectStatement selectStmt = (SQLSelectStatement)stmt;
SQLSelectQuery sqlSelectQuery = selectStmt.getSelect().getQuery();
//从mysql解析过来
if(sqlSelectQuery instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)selectStmt.getSelect().getQuery();
Limit limit=mysqlSelectQuery.getLimit();
if(limit==null)
{
//使用oracle的解析,否则会有部分oracle语法识别错误
OracleStatementParser oracleParser = new OracleStatementParser(getCtx().getSql());
SQLSelectStatement oracleStmt = (SQLSelectStatement) oracleParser.parseStatement();
selectStmt= oracleStmt;
SQLSelectQuery oracleSqlSelectQuery = oracleStmt.getSelect().getQuery();
if(oracleSqlSelectQuery instanceof OracleSelectQueryBlock)
{
parseNativePageSql(oracleStmt, rrs, (OracleSelectQueryBlock) oracleSqlSelectQuery, schema);
}
}
if(isNeedParseOrderAgg)
{
parseOrderAggGroupMysql(schema, selectStmt,rrs, mysqlSelectQuery);
//更改canRunInReadDB属性
if ((mysqlSelectQuery.isForUpdate() || mysqlSelectQuery.isLockInShareMode()) && rrs.isAutocommit() == false)
{
rrs.setCanRunInReadDB(false);
}
}
}
}
示例6: 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;
}
示例7: createSelectQueryBlock
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
protected SQLSelectQuery createSelectQueryBlock() {
if (JdbcConstants.MYSQL.equals(dbType)) {
return new MySqlSelectQueryBlock();
}
if (JdbcConstants.POSTGRESQL.equals(dbType)) {
return new PGSelectQueryBlock();
}
if (JdbcConstants.SQL_SERVER.equals(dbType)) {
return new SQLServerSelectQueryBlock();
}
if (JdbcConstants.ORACLE.equals(dbType)) {
return new OracleSelectQueryBlock();
}
return new SQLSelectQueryBlock();
}
示例8: parseLimit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
public MySqlSelectQueryBlock.Limit parseLimit() {
if (lexer.token() == Token.LIMIT) {
lexer.nextToken();
MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit();
SQLExpr temp = this.expr();
if (lexer.token() == (Token.COMMA)) {
limit.setOffset(temp);
lexer.nextToken();
limit.setRowCount(this.expr());
} else if (identifierEquals("OFFSET")) {
limit.setRowCount(temp);
lexer.nextToken();
limit.setOffset(this.expr());
} else {
limit.setRowCount(temp);
}
return limit;
}
return null;
}
示例9: parseJoinSelect
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
public JoinSelect parseJoinSelect(SQLQueryExpr sqlExpr) throws SqlParseException {
MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) sqlExpr.getSubQuery().getQuery();
List<From> joinedFrom = findJoinedFrom(query.getFrom());
if (joinedFrom.size() != 2)
throw new RuntimeException("currently supports only 2 tables join");
JoinSelect joinSelect = createBasicJoinSelectAccordingToTableSource((SQLJoinTableSource) query.getFrom());
List<Hint> hints = parseHints(query.getHints());
joinSelect.setHints(hints);
String firstTableAlias = joinedFrom.get(0).getAlias();
String secondTableAlias = joinedFrom.get(1).getAlias();
Map<String, Where> aliasToWhere = splitAndFindWhere(query.getWhere(), firstTableAlias, secondTableAlias);
Map<String, List<SQLSelectOrderByItem>> aliasToOrderBy = splitAndFindOrder(query.getOrderBy(), firstTableAlias, secondTableAlias);
List<Condition> connectedConditions = getConditionsFlatten(joinSelect.getConnectedWhere());
joinSelect.setConnectedConditions(connectedConditions);
fillTableSelectedJoin(joinSelect.getFirstTable(), query, joinedFrom.get(0), aliasToWhere.get(firstTableAlias), aliasToOrderBy.get(firstTableAlias), connectedConditions);
fillTableSelectedJoin(joinSelect.getSecondTable(), query, joinedFrom.get(1), aliasToWhere.get(secondTableAlias), aliasToOrderBy.get(secondTableAlias), connectedConditions);
updateJoinLimit(query.getLimit(), joinSelect);
//todo: throw error feature not supported: no group bys on joins ?
return joinSelect;
}
示例10: 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;
}
示例11: 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;
}
}
示例12: testGroupbyOrder
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
@Test
public void testGroupbyOrder() {
MySqlSelectQueryBlock query = getQuery("select col1,col2 from table1 group by col1 desc,col2 asc ");
SQLSelectGroupByClause groupBy = query.getGroupBy();
int i = 0;
for (SQLExpr p : groupBy.getItems()) {
i++;
String groupCol = "col" + i;
MySqlOrderingExpr groupitem = (MySqlOrderingExpr) p;
SQLExpr q = groupitem.getExpr();
MySQLItemVisitor v = new MySQLItemVisitor(this.currentDb, utf8Charset, null);
q.accept(v);
Item item = v.getItem();
Assert.assertEquals(true, groupCol.equals(item.getItemName()));
}
}
示例13: endVisit
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
@Override
public void endVisit(final MySqlSelectQueryBlock x) {
//把缺失的orderby列补上,union太复杂暂时不支持
if(isMasterSelect()){
if(!CollectionUtils.isEmpty(missOrderbyColumns)){
String orderby_columns="";
for(String columnName: missOrderbyColumns){
orderby_columns+= ", "+ columnName;
}
parseResult.getSqlBuilder().buildSQL("select_missing_columns", orderby_columns);
}
//增加一个limit东西限制查询大小
if(parseResult.getLimit()== null){
//print(" limit 9");
}
}
if(isEnableCollectMetadata()){
finishCollectMetadata= true;
}
selectLayer--;
}
示例14: getMethodValuesWithSubQueries
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; //导入依赖的package包/类
private Object[] getMethodValuesWithSubQueries(SQLMethodInvokeExpr method) throws SqlParseException {
List<Object> values = new ArrayList<>();
boolean foundSubQuery = false;
for(SQLExpr innerExpr : method.getParameters()){
if(innerExpr instanceof SQLQueryExpr){
foundSubQuery = true;
Select select = parseSelect((MySqlSelectQueryBlock) ((SQLQueryExpr) innerExpr).getSubQuery().getQuery());
values.add(new SubQueryExpression(select));
}
else {
values.add(innerExpr);
}
}
Object[] conditionValues ;
if(foundSubQuery)
conditionValues = values.toArray();
else
conditionValues = method.getParameters().toArray();
return conditionValues;
}
示例15: 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();
}
}