本文整理汇总了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();
}
}
示例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;
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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) {
}
}
示例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);
}
示例11: visit
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; //导入依赖的package包/类
@Override
public boolean visit(SQLSelectStatement x) {
setAliasMap();
// getAliasMap().put("DUAL", null);
return true;
}
示例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);
}
}
}
}
示例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;
}
示例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;
}
示例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");
}
}
}