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


Java SQLStatementParser类代码示例

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


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

示例1: updateMetaData

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
public void updateMetaData(String schema, String sql, boolean isSuccess, boolean needNotifyOther) {
    SQLStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement statement = parser.parseStatement();
    if (statement instanceof MySqlCreateTableStatement) {
        createTable(schema, sql, (MySqlCreateTableStatement) statement, isSuccess, needNotifyOther);
    } else if (statement instanceof SQLDropTableStatement) {
        dropTable(schema, sql, (SQLDropTableStatement) statement, isSuccess, needNotifyOther);
    } else if (statement instanceof SQLAlterTableStatement) {
        alterTable(schema, sql, (SQLAlterTableStatement) statement, isSuccess, needNotifyOther);
    } else if (statement instanceof SQLTruncateStatement) {
        truncateTable(schema, sql, (SQLTruncateStatement) statement, isSuccess, needNotifyOther);
    } else if (statement instanceof SQLCreateIndexStatement) {
        createIndex(schema, sql, (SQLCreateIndexStatement) statement, isSuccess, needNotifyOther);
    } else if (statement instanceof SQLDropIndexStatement) {
        dropIndex(schema, sql, (SQLDropIndexStatement) statement, isSuccess, needNotifyOther);
    } else {
        // TODO: further
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:20,代码来源:ProxyMetaManager.java

示例2: isSupportSelect

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

示例3: isInsertSeq

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
private static boolean isInsertSeq(ServerConnection c, String stmt, SchemaConfig schema) throws SQLException {
    SQLStatementParser parser = new MySqlStatementParser(stmt);
    MySqlInsertStatement statement = (MySqlInsertStatement) parser.parseStatement();
    String schemaName = schema == null ? null : schema.getName();
    SQLExprTableSource tableSource = statement.getTableSource();
    SchemaUtil.SchemaInfo schemaInfo = SchemaUtil.getSchemaInfo(c.getUser(), schemaName, tableSource);
    String tableName = schemaInfo.getTable();
    schema = schemaInfo.getSchemaConfig();
    TableConfig tableConfig = schema.getTables().get(tableName);
    if (tableConfig == null) {
        return false;
    } else if (tableConfig.isAutoIncrement()) {
        return true;
    }
    return false;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:17,代码来源:ExplainHandler.java

示例4: parserSQL

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
@Override
public SQLStatement parserSQL(String originSql) throws SQLSyntaxErrorException {
    SQLStatementParser parser = new MySqlStatementParser(originSql);

    /**
     * thrown SQL SyntaxError if parser error
     */
    try {
        List<SQLStatement> list = parser.parseStatementList();
        if (list.size() > 1) {
            throw new SQLSyntaxErrorException("MultiQueries is not supported,use single query instead ");
        }
        return list.get(0);
    } catch (Exception t) {
        LOGGER.info("routeNormalSqlWithAST", t);
        if (t.getMessage() != null) {
            throw new SQLSyntaxErrorException(t.getMessage());
        } else {
            throw new SQLSyntaxErrorException(t);
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:23,代码来源:DefaultRouteStrategy.java

示例5: getCountSql

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

示例6: isMycatSeq

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
private static boolean isMycatSeq(String stmt, SchemaConfig schema)
  {
      if(pattern.matcher(stmt).find()) {
	return true;
}
      SQLStatementParser parser =new MySqlStatementParser(stmt);
      MySqlInsertStatement statement = (MySqlInsertStatement) parser.parseStatement();
      String tableName=   statement.getTableName().getSimpleName();
      TableConfig tableConfig= schema.getTables().get(tableName.toUpperCase());
      if(tableConfig==null) {
	return false;
}
      if(tableConfig.isAutoIncrement())
      {
          boolean isHasIdInSql=false;
          String primaryKey = tableConfig.getPrimaryKey();
          List<SQLExpr> columns = statement.getColumns();
          for (SQLExpr column : columns)
          {
              String columnName = column.toString();
              if(primaryKey.equalsIgnoreCase(columnName))
              {
                  isHasIdInSql = true;
                  break;
              }
          }
          if(!isHasIdInSql) {
		return true;
	}
      }


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

示例7: changeInsertAddSlot

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
public static String changeInsertAddSlot(String sql,int slotValue)
{
    SQLStatementParser parser = new MycatStatementParser(sql);
    MySqlInsertStatement insert = (MySqlInsertStatement) parser.parseStatement();
    insert.getColumns().add(new SQLIdentifierExpr("_slot") );
    insert.getValues().getValues().add(new SQLIntegerExpr(slotValue))  ;
    return insert.toString();
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:9,代码来源:ParseUtil.java

示例8: oracleValidationQueryCheck

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

示例9: db2ValidationQueryCheck

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

示例10: parseSQL

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
private static SQLStatement parseSQL(String stmt) throws SQLSyntaxErrorException {
    SQLStatementParser parser = new MySqlStatementParser(stmt);
    try {
        return parser.parseStatement();
    } catch (Exception t) {
        if (t.getMessage() != null) {
            throw new SQLSyntaxErrorException(t.getMessage());
        } else {
            throw new SQLSyntaxErrorException(t);
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:13,代码来源:SetHandler.java

示例11: parseProcedure

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
private Procedure parseProcedure(String sql) {
    Procedure procedure = new Procedure();
    procedure.setOriginSql(sql);
    procedure.setResultList(false);
    SQLStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement statement = parser.parseStatement();
    if (statement instanceof SQLCallStatement) {
        parseProcedureForCall(procedure, sql, (SQLCallStatement) statement);
    }
    return procedure;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:12,代码来源:AbstractRouteStrategy.java

示例12: getPlanNode

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
private PlanNode getPlanNode(String sql) {
    SQLStatementParser parser = new MySqlStatementParser(sql);
    SQLSelectStatement ast = (SQLSelectStatement) parser.parseStatement();
    MySQLPlanNodeVisitor visitor = new MySQLPlanNodeVisitor("TESTDB", 33, null, true);
    visitor.visit(ast);
    return visitor.getTableNode();
}
 
开发者ID:actiontech,项目名称:dble,代码行数:8,代码来源:TestMySQLPlanNodeVisitor.java

示例13: parseSql

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
private static SQLStatement parseSql(String sql) {
    String convertSql = trimPattern.matcher(sql).replaceAll("xtrim");
    SQLStatementParser parser = new OracleStatementParser(convertSql);
    List<SQLStatement> stmtList;
    try {
        stmtList = parser.parseStatementList();
    } catch (ParserException exception) {
        exception.printStackTrace();
        throw new RuntimeException(sql + " is invalid, detail " + exception.getMessage());
    }

    return stmtList.get(0);
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:14,代码来源:OracleSensitiveFieldsParser.java

示例14: getSQLStatementParser

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
private static SQLStatementParser getSQLStatementParser(DatabaseType databaseType,final String sql) {
    switch (databaseType) {
        case MySQL: 
            return new MySqlStatementParser(sql);
        case PostgreSQL:
        	return new PGSQLStatementParser(sql);
        case Oracle:
        	return new OracleStatementParser(sql);
        default: 
            throw new UnsupportedOperationException(String.format("Cannot support database type [%s]", databaseType));
    }
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:13,代码来源:SQLParserFactory.java

示例15: start

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入依赖的package包/类
@Override
public void start(String sql)
{
    clear();
    this.sql = sql;


    SQLStatementParser parser = new MycatStatementParser(sql);
    statement = (MySqlLoadDataInFileStatement) parser.parseStatement();
    fileName = parseFileName(sql);

    if (fileName == null)
    {
        serverConnection.writeErrMessage(ErrorCode.ER_FILE_NOT_FOUND, " file name is null !");
        clear();
        return;
    }
    schema = MycatServer.getInstance().getConfig()
            .getSchemas().get(serverConnection.getSchema());
    tableId2DataNodeCache = (LayerCachePool) MycatServer.getInstance().getCacheService().getCachePool("TableID2DataNodeCache");
    tableName = statement.getTableName().getSimpleName().toUpperCase();
    tableConfig = schema.getTables().get(tableName);
    tempPath = SystemConfig.getHomePath() + File.separator + "temp" + File.separator + serverConnection.getId() + File.separator;
    tempFile = tempPath + "clientTemp.txt";
    tempByteBuffer = new ByteArrayOutputStream();

    List<SQLExpr> columns = statement.getColumns();
    if(tableConfig!=null)
    {
        String pColumn = getPartitionColumn();
        if (pColumn != null && columns != null && columns.size() > 0)
        {

            for (int i = 0, columnsSize = columns.size(); i < columnsSize; i++)
            {
                String column = StringUtil.removeBackquote(columns.get(i).toString());
                if (pColumn.equalsIgnoreCase(column))
                {
                    partitionColumnIndex = i;
                    break;

                }

            }

        }
    }

    parseLoadDataPram();
    if (statement.isLocal())
    {
        isStartLoadData = true;
        //向客户端请求发送文件
        ByteBuffer buffer = serverConnection.allocate();
        RequestFilePacket filePacket = new RequestFilePacket();
        filePacket.fileName = fileName.getBytes();
        filePacket.packetId = 1;
        filePacket.write(buffer, serverConnection, true);
    } else
    {
        if (!new File(fileName).exists())
        {
            serverConnection.writeErrMessage(ErrorCode.ER_FILE_NOT_FOUND, fileName + " is not found!");
            clear();
        } else
        {
            parseFileByLine(fileName, loadData.getCharset(), loadData.getLineTerminatedBy());
            RouteResultset rrs = buildResultSet(routeResultMap);
            if (rrs != null)
            {
                flushDataToFile();
                isStartLoadData = false;
                serverConnection.getSession2().execute(rrs, ServerParse.LOAD_DATA_INFILE_SQL);
            }

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


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