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


Java SQLSelectStatement类代码示例

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


SQLSelectStatement类属于com.alibaba.druid.sql.ast.statement包,在下文中一共展示了SQLSelectStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: statementParse

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的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();
		}
	}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:22,代码来源:DruidSelectParser.java

示例2: isConditionAlwaysTrue

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的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;
	}
	
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:18,代码来源:DruidSelectParser.java

示例3: statementParse

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的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);
			}
		}

	}


}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:38,代码来源:DruidSelectOracleParser.java

示例4: sqlserverParse

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
private void sqlserverParse(SchemaConfig schema, RouteResultset rrs)
{
    //使用sqlserver的解析,否则会有部分语法识别错误
    SQLServerStatementParser oracleParser = new SQLServerStatementParser(getCtx().getSql());
    SQLSelectStatement oracleStmt = (SQLSelectStatement) oracleParser.parseStatement();
    SQLSelectQuery oracleSqlSelectQuery = oracleStmt.getSelect().getQuery();
    if(oracleSqlSelectQuery instanceof SQLServerSelectQueryBlock)
    {
        parseSqlServerPageSql(oracleStmt, rrs, (SQLServerSelectQueryBlock) oracleSqlSelectQuery, schema);
        if(isNeedParseOrderAgg)
        {
            parseOrderAggGroupSqlServer(schema, oracleStmt,rrs, (SQLServerSelectQueryBlock) oracleSqlSelectQuery);
        }
    }

}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:17,代码来源:DruidSelectSqlServerParser.java

示例5: isSupportSelect

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

示例6: buildNodes

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
private static BaseHandlerBuilder buildNodes(RouteResultset rrs, ServerConnection c) {
    SQLSelectStatement ast = (SQLSelectStatement) rrs.getSqlStatement();
    MySQLPlanNodeVisitor visitor = new MySQLPlanNodeVisitor(c.getSchema(), c.getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager(), false);
    visitor.visit(ast);
    PlanNode node = visitor.getTableNode();
    node.setSql(rrs.getStatement());
    node.setUpFields();
    PlanUtil.checkTablesPrivilege(c, node, ast);
    node = MyOptimizer.optimize(node);

    if (!PlanUtil.containsSubQuery(node) && !visitor.isContainSchema()) {
        node.setAst(ast);
    }
    HandlerBuilder builder = new HandlerBuilder(node, c.getSession2());
    return builder.getBuilder(c.getSession2(), node, true);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:17,代码来源:ExplainHandler.java

示例7: parserNoSharding

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
private boolean parserNoSharding(ServerConnection sc, String contextSchema, SchemaInfo schemaInfo, RouteResultset rrs,
                                 MySqlInsertStatement insert) throws SQLException {

    if (RouterUtil.isNoSharding(schemaInfo.getSchemaConfig(), schemaInfo.getTable())) {
        if (insert.getQuery() != null) {
            SQLSelectStatement selectStmt = new SQLSelectStatement(insert.getQuery());
            StringPtr sqlSchema = new StringPtr(schemaInfo.getSchema());
            if (!SchemaUtil.isNoSharding(sc, insert.getQuery().getQuery(), selectStmt, contextSchema, sqlSchema)) {
                return false;
            }
        }
        rrs.setStatement(RouterUtil.removeSchema(rrs.getStatement(), schemaInfo.getSchema()));
        RouterUtil.routeToSingleNode(rrs, schemaInfo.getSchemaConfig().getDataNode());
        return true;
    }
    return false;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:18,代码来源:DruidInsertParser.java

示例8: getCountSql

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
@Override
public String getCountSql(String sql) {
	SQLStatementParser parser = new MySqlStatementParser(sql);
	List<SQLStatement> stmtList = parser.parseStatementList();

	// 将AST通过visitor输出
	StringBuilder out = new StringBuilder();
	MysqlCountOutputVisitor visitor = new MysqlCountOutputVisitor(out);

	for (SQLStatement stmt : stmtList) {
		if (stmt instanceof SQLSelectStatement) {
			stmt.accept(visitor);
			out.append(";");
		}
	}

	return out.toString();
}
 
开发者ID:dianping,项目名称:zebra,代码行数:19,代码来源:MySQLDialect.java

示例9: route

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
public void route(SystemConfig sysConfig, SchemaConfig schema,int sqlType, String realSQL, String charset, ServerConnection sc,	LayerCachePool cachePool) {
	int rs = ServerParse.parse(realSQL);
	this.sqltype = rs & 0xff;
	this.sysConfig=sysConfig; 
	this.schema=schema;
	this.charset=charset; 
	this.sc=sc;	
	this.cachePool=cachePool;		
	try {
	 //  RouteStrategy routes=RouteStrategyFactory.getRouteStrategy();	
	  // rrs =RouteStrategyFactory.getRouteStrategy().route(sysConfig, schema, sqlType2, realSQL,charset, sc, cachePool);		   
		MySqlStatementParser parser = new MySqlStatementParser(realSQL);			
		SQLStatement statement = parser.parseStatement();
		if(statement instanceof SQLSelectStatement) {
		   SQLSelectStatement st=(SQLSelectStatement)statement;
		   SQLSelectQuery sqlSelectQuery =st.getSelect().getQuery();
			if(sqlSelectQuery instanceof MySqlSelectQueryBlock) {
				MySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)st.getSelect().getQuery();
				joinParser=new JoinParser(mysqlSelectQuery,realSQL);
				joinParser.parser();
			}	
		}
	   /*	
	   if (routes instanceof DruidMysqlRouteStrategy) {
		   SQLSelectStatement st=((DruidMysqlRouteStrategy) routes).getSQLStatement();
		   SQLSelectQuery sqlSelectQuery =st.getSelect().getQuery();
			if(sqlSelectQuery instanceof MySqlSelectQueryBlock) {
				MySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)st.getSelect().getQuery();
				joinParser=new JoinParser(mysqlSelectQuery,realSQL);
				joinParser.parser();
			}
	   }
	   */
	} catch (Exception e) {
	
	}
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:38,代码来源:ShareJoin.java

示例10: parseSelect

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
@Override
public SQLSelectStatement parseSelect()
{

    MycatSelectParser selectParser = new MycatSelectParser(this.selectExprParser);
    return new SQLSelectStatement(selectParser.select(), JdbcConstants.MYSQL);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:8,代码来源:MycatStatementParser.java

示例11: visit

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
@Override
    public boolean visit(SQLSelectStatement x) {
        setAliasMap();
//        getAliasMap().put("DUAL", null);

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

示例12: statementParse

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的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();
		MySqlSelectQueryBlock.Limit limit=mysqlSelectQuery.getLimit();
		if(limit==null)
		{
               sqlserverParse(schema, rrs);


           }
		if(isNeedParseOrderAgg)
		{
			parseOrderAggGroupMysql(schema, stmt,rrs, mysqlSelectQuery);
			//更改canRunInReadDB属性
			if ((mysqlSelectQuery.isForUpdate() || mysqlSelectQuery.isLockInShareMode()) && rrs.isAutocommit() == false)
			{
				rrs.setCanRunInReadDB(false);
			}
		}

	}


}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:29,代码来源:DruidSelectSqlServerParser.java

示例13: create

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
public static DruidParser create(SchemaConfig schema, SQLStatement statement, SchemaStatVisitor visitor)
{
    DruidParser parser = null;
    if (statement instanceof SQLSelectStatement)
    {
        if(schema.isNeedSupportMultiDBType())
        {
            parser = getDruidParserForMultiDB(schema, statement, visitor);

        }

        if (parser == null)
        {
            parser = new DruidSelectParser();
        }
    } else if (statement instanceof MySqlInsertStatement)
    {
        parser = new DruidInsertParser();
    } else if (statement instanceof MySqlDeleteStatement)
    {
        parser = new DruidDeleteParser();
    } else if (statement instanceof MySqlCreateTableStatement)
    {
        parser = new DruidCreateTableParser();
    } else if (statement instanceof MySqlUpdateStatement)
    {
        parser = new DruidUpdateParser();
    } else if (statement instanceof SQLAlterTableStatement)
    {
        parser = new DruidAlterTableParser();
    } else if (statement instanceof MySqlLockTableStatement) {
    	parser = new DruidLockTableParser();
    } else
    {
        parser = new DefaultDruidParser();
    }

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

示例14: isSelect

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
/**
 * SELECT 语句
 */
   private boolean isSelect(SQLStatement statement) {
	if(statement instanceof SQLSelectStatement) {
		return true;
	}
	return false;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:10,代码来源:DruidMycatRouteStrategy.java

示例15: oracleValidationQueryCheck

import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
private void oracleValidationQueryCheck() {
    if (validationQuery == null) {
        return;
    }
    if (validationQuery.length() == 0) {
        return;
    }

    SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbType);
    List<SQLStatement> stmtList = sqlStmtParser.parseStatementList();

    if (stmtList.size() != 1) {
        return;
    }

    SQLStatement stmt = stmtList.get(0);
    if (!(stmt instanceof SQLSelectStatement)) {
        return;
    }

    SQLSelectQuery query = ((SQLSelectStatement) stmt).getSelect().getQuery();
    if (query instanceof SQLSelectQueryBlock) {
        if (((SQLSelectQueryBlock) query).getFrom() == null) {
            LOG.error("invalid oracle validationQuery. " + validationQuery + ", may should be : " + validationQuery
                    + " FROM DUAL");
        }
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:29,代码来源:ElasticSearchDruidDataSource.java


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