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


Java SQLStatementParser.parseStatement方法代码示例

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


在下文中一共展示了SQLStatementParser.parseStatement方法的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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: parseStmt

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
private SQLStatement parseStmt(String sql) {
	SQLStatementParser statParser = SQLParserUtils.createSQLStatementParser(sql, "mysql");
	SQLStatement stmt = statParser.parseStatement();
	return stmt;		
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:6,代码来源:TableStatAnalyzer.java

示例11: start

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

    if (this.checkPartition(strSql)) {
        serverConnection.writeErrMessage(ErrorCode.ER_UNSUPPORTED_PS, " unsupported load data with Partition");
        clear();
        return;
    }

    SQLStatementParser parser = new MySqlStatementParser(strSql);
    statement = (MySqlLoadDataInFileStatement) parser.parseStatement();
    fileName = parseFileName(strSql);
    if (fileName == null) {
        serverConnection.writeErrMessage(ErrorCode.ER_FILE_NOT_FOUND, " file name is null !");
        clear();
        return;
    }

    schema = DbleServer.getInstance().getConfig().getSchemas().get(serverConnection.getSchema());
    tableId2DataNodeCache = (LayerCachePool) DbleServer.getInstance().getCacheService().getCachePool("TableID2DataNodeCache");
    tableName = statement.getTableName().getSimpleName();
    if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
        tableName = tableName.toLowerCase();
    }

    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;
        //request file from client
        ByteBuffer buffer = serverConnection.allocate();
        RequestFilePacket filePacket = new RequestFilePacket();
        filePacket.setFileName(fileName.getBytes());
        filePacket.setPacketId(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);
            }
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:71,代码来源:ServerLoadDataInfileHandler.java

示例12: parseStmt

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
private SQLStatement parseStmt(String sql) {
    SQLStatementParser statParser = SQLParserUtils.createSQLStatementParser(sql, "mysql");
    SQLStatement stmt = statParser.parseStatement();
    return stmt;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:6,代码来源:TableStatAnalyzer.java

示例13: constructByQuery

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
public RouteResultset constructByQuery(String sql) throws SQLException {
    SQLStatementParser parser = new MySqlStatementParser(sql);
    SQLSelectStatement select = (SQLSelectStatement) parser.parseStatement();
    return constructByStatement(sql, select);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:6,代码来源:MergeBuilder.java

示例14: parseProcedure

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
private Procedure parseProcedure(String sql, Map hintMap) {
    boolean fields = hintMap.containsKey("list_fields");
    boolean isResultList = "list".equals(hintMap.get("result_type")) || fields;
    Procedure procedure = new Procedure();
    procedure.setOriginSql(sql);
    procedure.setResultList(isResultList);
    List<String> sqlList = Splitter.on(";").trimResults().splitToList(sql);
    Set<String> outSet = new HashSet<>();
    for (int i = sqlList.size() - 1; i >= 0; i--) {
        String query = sqlList.get(i);
        if (Strings.isNullOrEmpty(query)) {
            continue;
        }
        SQLStatementParser parser = new MySqlStatementParser(query);
        SQLStatement statement = parser.parseStatement();
        if (statement instanceof SQLSelectStatement) {
            parseProcedureForSelect(procedure, outSet, query, (SQLSelectStatement) statement);
        } else if (statement instanceof SQLCallStatement) {
            parseProcedureForCall(procedure, outSet, query, (SQLCallStatement) statement);
        } else if (statement instanceof SQLSetStatement) {
            parseProcedureForSet(procedure, query, (SQLSetStatement) statement);
        }

    }
    if (fields) {
        String listFieldsStr = (String) hintMap.get("list_fields");
        List<String> listFields = Splitter.on(",").trimResults().splitToList(listFieldsStr);
        for (String field : listFields) {
            if (!procedure.getParameterMap().containsKey(field)) {
                ProcedureParameter parameter = new ProcedureParameter();
                parameter.setParameterType(ProcedureParameter.OUT);
                parameter.setName(field);
                parameter.setJdbcType(-10);
                parameter.setIndex(procedure.getParameterMap().size() + 1);
                procedure.getParameterMap().put(field, parameter);
            }
        }
        procedure.getListFields().addAll(listFields);
    }
    return procedure;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:42,代码来源:HintSQLHandler.java

示例15: getSelectStatement

import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
private SQLSelectStatement getSelectStatement(String sql) {
    SQLStatementParser parser = new MySqlStatementParser(sql);
    return (SQLSelectStatement) parser.parseStatement();
}
 
开发者ID:actiontech,项目名称:dble,代码行数:5,代码来源:TestMySQLItemVisitor.java


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