本文整理汇总了Java中com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock类的典型用法代码示例。如果您正苦于以下问题:Java SQLSelectQueryBlock类的具体用法?Java SQLSelectQueryBlock怎么用?Java SQLSelectQueryBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SQLSelectQueryBlock类属于com.alibaba.druid.sql.ast.statement包,在下文中一共展示了SQLSelectQueryBlock类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: add
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public void add(String select) {
if (select == null || select.length() == 0) {
return;
}
SQLSelectParser selectParser = SQLParserUtils.createSQLStatementParser(select, dbType)
.createSQLSelectParser();
SQLSelectQueryBlock queryBlock = SQLParserUtils.createSelectQueryBlock(dbType);
selectParser.accept(Token.SELECT);
selectParser.parseSelectList(queryBlock);
selectParser.accept(Token.FROM);
selectParser.accept(Token.EOF);
sqlCache.add(select.substring(6));
queryBlockCache.add(queryBlock);
printSqlList.add(queryBlock.toString());
}
开发者ID:zuonima,项目名称:sql-utils,代码行数:20,代码来源:SQLSelectListCache.java
示例2: match
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public boolean match(Lexer lexer, SQLSelectQueryBlock queryBlock) {
if (lexer.token != Token.SELECT) {
return false;
}
int pos = lexer.pos;
String text = lexer.text;
for (int i = 0; i < sqlCache.size(); i++) {
String block = sqlCache.get(i);
if (text.startsWith(block, pos)) {
//SQLSelectQueryBlock queryBlockCached = queryBlockCache.get(i);
// queryBlockCached.cloneSelectListTo(queryBlock);
String printSql = printSqlList.get(i);
queryBlock.setCachedSelectList(printSql);
int len = pos + block.length();
lexer.reset(len, text.charAt(len), Token.FROM);
return true;
}
}
return false;
}
开发者ID:zuonima,项目名称:sql-utils,代码行数:24,代码来源:SQLSelectListCache.java
示例3: computeDataType
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public SQLDataType computeDataType() {
if (subQuery == null) {
return null;
}
SQLSelectQueryBlock queryBlock = subQuery.getFirstQueryBlock();
if (queryBlock == null) {
return null;
}
List<SQLSelectItem> selectList = queryBlock.getSelectList();
if (selectList.size() == 1) {
return selectList.get(0).computeDataType();
}
return null;
}
开发者ID:zuonima,项目名称:sql-utils,代码行数:18,代码来源:SQLAnyExpr.java
示例4: visit
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
@Override
public boolean visit(DB2SelectQueryBlock x) {
this.visit((SQLSelectQueryBlock) x);
if (x.isForReadOnly()) {
println();
print0(ucase ? "FOR READ ONLY" : "for read only");
}
if (x.getIsolation() != null) {
println();
print0(ucase ? "WITH " : "with ");
print0(x.getIsolation().name());
}
if (x.getOptimizeFor() != null) {
println();
print0(ucase ? "OPTIMIZE FOR " : "optimize for ");
x.getOptimizeFor().accept(this);
}
return false;
}
开发者ID:zuonima,项目名称:sql-utils,代码行数:24,代码来源:DB2OutputVisitor.java
示例5: isFromJoinOrUnionTable
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public static boolean isFromJoinOrUnionTable(SQLExpr expr) {
SQLObject temp = expr;
AtomicInteger counter = new AtomicInteger(10);
while (temp != null &&
!(expr instanceof SQLSelectQueryBlock) &&
!(expr instanceof SQLJoinTableSource) && !(expr instanceof SQLUnionQuery) && counter.get() > 0) {
counter.decrementAndGet();
temp = temp.getParent();
if (temp instanceof SQLSelectQueryBlock) {
SQLTableSource from = ((SQLSelectQueryBlock) temp).getFrom();
if (from instanceof SQLJoinTableSource || from instanceof SQLUnionQuery) {
return true;
}
}
if (temp instanceof SQLJoinTableSource || temp instanceof SQLUnionQuery) {
return true;
}
}
return false;
}
开发者ID:mazhou,项目名称:es-sql,代码行数:21,代码来源:Util.java
示例6: createSelectQueryBlock
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public static SQLSelectQueryBlock createSelectQueryBlock(String dbType) {
if (JdbcConstants.MYSQL.equals(dbType)) {
return new MySqlSelectQueryBlock();
}
if (JdbcConstants.ORACLE.equals(dbType)) {
return new OracleSelectQueryBlock();
}
if (JdbcConstants.DB2.equals(dbType)) {
return new DB2SelectQueryBlock();
}
if (JdbcConstants.POSTGRESQL.equals(dbType)) {
return new DB2SelectQueryBlock();
}
if (JdbcConstants.ODPS.equals(dbType)) {
return new DB2SelectQueryBlock();
}
if (JdbcConstants.SQL_SERVER.equals(dbType)) {
return new DB2SelectQueryBlock();
}
return new SQLSelectQueryBlock();
}
开发者ID:zuonima,项目名称:sql-utils,代码行数:28,代码来源:SQLParserUtils.java
示例7: unwrap
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public static SQLExpr unwrap(SQLExpr expr) {
if (expr == null) {
return null;
}
if (expr instanceof SQLQueryExpr) {
SQLSelect select = ((SQLQueryExpr) expr).getSubQuery();
if (select == null) {
return null;
}
if (select.getQuery() instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) select.getQuery();
if (queryBlock.getFrom() == null) {
if (queryBlock.getSelectList().size() == 1) {
return queryBlock.getSelectList().get(0).getExpr();
}
}
}
}
return expr;
}
开发者ID:zuonima,项目名称:sql-utils,代码行数:23,代码来源:SQLEvalVisitorUtils.java
示例8: visit
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public static boolean visit(SQLEvalVisitor visitor, SQLQueryExpr x) {
if (x.getSubQuery().getQuery() instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) x.getSubQuery().getQuery();
boolean nullFrom = false;
if (queryBlock.getFrom() == null) {
nullFrom = true;
} else if (queryBlock.getFrom() instanceof SQLExprTableSource) {
SQLExpr expr = ((SQLExprTableSource) queryBlock.getFrom()).getExpr();
if (expr instanceof SQLIdentifierExpr) {
if ("dual".equalsIgnoreCase(((SQLIdentifierExpr) expr).getName())) {
nullFrom = true;
}
}
}
if (nullFrom) {
List<Object> row = new ArrayList<Object>(queryBlock.getSelectList().size());
for (int i = 0; i < queryBlock.getSelectList().size(); ++i) {
SQLSelectItem item = queryBlock.getSelectList().get(i);
item.getExpr().accept(visitor);
Object cell = item.getExpr().getAttribute(EVAL_VALUE);
row.add(cell);
}
List<List<Object>> rows = new ArrayList<List<Object>>(1);
rows.add(row);
Object result = rows;
queryBlock.putAttribute(EVAL_VALUE, result);
x.getSubQuery().putAttribute(EVAL_VALUE, result);
x.putAttribute(EVAL_VALUE, result);
return false;
}
}
return false;
}
开发者ID:zuonima,项目名称:sql-utils,代码行数:41,代码来源:SQLEvalVisitorUtils.java
示例9: oracleValidationQueryCheck
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的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
示例10: db2ValidationQueryCheck
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
private void db2ValidationQueryCheck() {
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 db2 validationQuery. " + validationQuery + ", may should be : " + validationQuery
+ " FROM SYSDUMMY");
}
}
}
开发者ID:mazhou,项目名称:es-sql,代码行数:29,代码来源:ElasticSearchDruidDataSource.java
示例11: main
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; //导入依赖的package包/类
public static void main(String[] args) {
String sql = " select * from event where eventId = 0001 and eventKey = key and eventName between begin and end";
String insert = " insert into uservalues(id,ooo)";
//使用mysql解析
MySqlStatementParser sqlStatementParser = new MySqlStatementParser(sql) ;
//解析select查询
// System.out.println("parse select "+sqlStatementParser.parseStatement());
SQLSelectStatement sqlStatement = (SQLSelectStatement) sqlStatementParser.parseStatement();
SQLSelect sqlSelect = sqlStatement.getSelect() ;
//获取sql查询块
SQLSelectQueryBlock sqlSelectQuery = (SQLSelectQueryBlock)sqlSelect.getQuery() ;
StringBuffer out = new StringBuffer() ;
// //创建sql解析的标准化输出
// SQLASTOutputVisitor sqlastOutputVisitor = SQLUtils.createFormatOutputVisitor(out , SQLUtils.parseStatements(sql, JdbcUtils.MYSQL) , JdbcUtils.MYSQL) ;
SQLBinaryOpExpr expr = (SQLBinaryOpExpr)sqlSelectQuery.getWhere();
System.out.println("expr:"+expr.getClass().getName());
// sqlastOutputVisitor.visit(expr);
SQLBetweenExpr betweenExpr = (SQLBetweenExpr) expr.getRight();
System.out.println(betweenExpr.getBeginExpr().toString());
// SQLIdentifierExpr sqlIdentifierExpr = (SQLIdentifierExpr) exprRight.getLeft();
// sqlIdentifierExpr.accept(sqlastOutputVisitor);
// List<Object> params = sqlVariantRefExpr.getName();
// System.out.println(sqlIdentifierExpr.getName());
int index = 0;
// for (TableStat.Column column:sqlastOutputVisitor.getgetColumns()){
// System.out.println(column.getName()+":"+params.get(index));
// index++;
// }
//
// //解析select项
// out.delete(0, out.length()) ;
// for (SQLSelectItem sqlSelectItem : sqlSelectQuery.getSelectList()) {
// if(out.length()>1){
// out.append(",") ;
// }
// sqlSelectItem.accept(sqlastOutputVisitor);
// }
// System.out.println("SELECT "+out) ;
//
// //解析from
// out.delete(0, out.length()) ;
// sqlSelectQuery.getFrom().accept(sqlastOutputVisitor) ;
// System.out.println("FROM "+out) ;
//
// //解析where
// out.delete(0, out.length()) ;
// sqlSelectQuery.getWhere().accept(sqlastOutputVisitor) ;
// System.out.println("WHERE "+out);
}
开发者ID:rpgmakervx,项目名称:slardar,代码行数:51,代码来源:SqlParserTest.java
注:本文中的com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论