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


Java MySqlStatementParser.parseStatement方法代码示例

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


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

示例1: test

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
public void test(String sql, String logicName, String targetName){

        MySqlStatementParser parser = new MySqlStatementParser(sql);
        SQLStatement statement = parser.parseStatement();

        ReplaceTableNameVisitor replaceVisitor = new ReplaceTableNameVisitor(logicName, targetName);
        StringBuilder out = new StringBuilder();
        MySqlOutputVisitor outPutVisitor = new MySqlOutputVisitor(out);
        // 替换表名
        statement.accept(replaceVisitor);
        // 输出sql
        statement.accept(outPutVisitor);

        System.out.println();
        System.out.println(sql);
        System.out.println(out.toString());
        // 输出sql后要还原statement以便下次替换表名
        replaceVisitor.reset();
    }
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:20,代码来源:ReplaceTableNameVisitorTest.java

示例2: changeCreateTable

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
private  static String changeCreateTable(SchemaConfig schema,String tableName,String sql) {
	if (schema.getTables().containsKey(tableName)) {
		MySqlStatementParser parser = new MySqlStatementParser(sql);
		SQLStatement insertStatement = parser.parseStatement();
		if (insertStatement instanceof MySqlCreateTableStatement) {
			TableConfig tableConfig = schema.getTables().get(tableName);
			AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();
			if (algorithm instanceof SlotFunction) {
				SQLColumnDefinition column = new SQLColumnDefinition();
				column.setDataType(new SQLCharacterDataType("int"));
				column.setName(new SQLIdentifierExpr("_slot"));
				column.setComment(new SQLCharExpr("自动迁移算法slot,禁止修改"));
				((SQLCreateTableStatement) insertStatement).getTableElementList().add(column);
				return insertStatement.toString();

			}
		}

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

示例3: test

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
private List<List<TableStat.Condition>> test(String sql){
    MySqlStatementParser parser = new MySqlStatementParser(sql);

    SQLStatement statemen = parser.parseStatement();

    List<Object> parameters = new ArrayList<Object>();

    parameters.add(10);

    OrVisitor visitor = new OrVisitor();
    OrVisitor.OrEntity orEntity = new OrVisitor.OrEntity(visitor, statemen);
    List<List<TableStat.Condition>> conditions = orEntity.getOrConditions();
    System.out.println();
    System.out.println(sql);
    System.out.println(conditions);
    System.out.println();
    return conditions;
}
 
开发者ID:tongbanjie,项目名称:baymax,代码行数:19,代码来源:OrVisitorTest.java

示例4: route

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的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

示例5: parseConditionValues

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
/**
 * 解析 SQL 获取指定表及条件列的值
 * 
 * @param sql
 * @param tableName
 * @param colnumName
 * @return
 */
public List<Object> parseConditionValues(String sql, String tableName, String colnumName)  {
	
	List<Object> values = null;
	
	if ( sql != null && tableName != null && columnName != null ) {
	
		values = new ArrayList<Object>();
		
		MySqlStatementParser parser = new MySqlStatementParser(sql);
		SQLStatement stmt = parser.parseStatement();
		
		MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
		stmt.accept(visitor);
		
		String currentTable = visitor.getCurrentTable();
		if ( tableName.equalsIgnoreCase( currentTable ) ) {
			
			List<Condition> conditions = visitor.getConditions();
			for(Condition condition: conditions) {
				
				String ccN = condition.getColumn().getName();
				ccN = fixName(ccN);
				
				if ( colnumName.equalsIgnoreCase( ccN ) ) {					
					List<Object> ccVL = condition.getValues();
					values.addAll( ccVL );
				}
			}
		}				
	}
	return values;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:41,代码来源:QueryConditionAnalyzer.java

示例6: isInsertHasSlot

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
private boolean isInsertHasSlot(String sql)
{
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    MySqlInsertStatement insertStatement= (MySqlInsertStatement)parser.parseStatement();
 List<SQLExpr> cc= insertStatement.getColumns();
    for (SQLExpr sqlExpr : cc) {
        SQLIdentifierExpr c= (SQLIdentifierExpr) sqlExpr;
        if("_slot".equalsIgnoreCase(c.getName())   &&cc.size()==insertStatement.getValues().getValues().size())    return true;
    }
    return false;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:12,代码来源:DruidMysqlCreateTableTest.java

示例7: testModifySQLLimit

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
public void testModifySQLLimit() throws Exception {
    final SchemaConfig schema = schemaMap.get("TESTDB");

    String sql = null;
    RouteResultset rrs = null;
    //SQL span multi datanode 
    sql = "select * from orders limit 2,3";
    rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertEquals(true, rrs.isCacheAble());
    Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 2);
    NodeNameAsserter nameAsserter = new NodeNameAsserter("dn2",
            "dn1");
    nameAsserter.assertRouteNodeNames(nodeMap.keySet());
    Assert.assertEquals(3, rrs.getLimitSize());


    MySqlStatementParser parser = new MySqlStatementParser("SELECT * FROM orders LIMIT 0,5");
    SQLStatement statement = parser.parseStatement();

    Assert.assertEquals(statement.toString(), rrs.getNodes()[0].getStatement());

    //SQL  not span multi datanode
    sql = "select * from customer where id=10000 limit 2,3";
    rrs = routeStrategy.route(new SystemConfig(), schema, ServerParse.SELECT, sql, null, null, cachePool);
    Assert.assertEquals(true, rrs.isCacheAble());
    nodeMap = getNodeMap(rrs, 1);
    nameAsserter = new NodeNameAsserter("dn1");
    nameAsserter.assertRouteNodeNames(nodeMap.keySet());
    Assert.assertEquals(3, rrs.getLimitSize());
    Assert.assertEquals("select * from customer where id=10000 limit 2,3", rrs.getNodes()[0].getStatement());


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

示例8: mysqSqlFilter

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
public static String mysqSqlFilter(String sql, List<String> conditionNames){
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement sqlStatement = parser.parseStatement();
    StringBuilder buffer = new StringBuilder();
    MysqlConditionVisitor mysqlConditionVisitor = new MysqlConditionVisitor(conditionNames,buffer);
    sqlStatement.accept(mysqlConditionVisitor);
    return buffer.toString();
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:9,代码来源:ZSQLUtils.java

示例9: parseConditionValues

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
/**
 * parseConditionValues
 *
 * @param sql
 * @param table
 * @param column
 * @return
 */
public List<Object> parseConditionValues(String sql, String table, String column) {

    List<Object> values = null;

    if (sql != null && table != null && QueryConditionAnalyzer.this.columnName != null) {

        values = new ArrayList<>();

        MySqlStatementParser parser = new MySqlStatementParser(sql);
        SQLStatement stmt = parser.parseStatement();

        MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
        stmt.accept(visitor);

        String currentTable = visitor.getCurrentTable();
        if (table.equalsIgnoreCase(currentTable)) {

            List<Condition> conditions = visitor.getConditions();
            for (Condition condition : conditions) {

                String ccN = condition.getColumn().getName();
                ccN = fixName(ccN);

                if (column.equalsIgnoreCase(ccN)) {
                    List<Object> ccVL = condition.getValues();
                    values.addAll(ccVL);
                }
            }
        }
    }
    return values;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:41,代码来源:QueryConditionAnalyzer.java

示例10: isInsertHasSlot

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
private boolean isInsertHasSlot(String sql) {
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    MySqlInsertStatement insertStatement = (MySqlInsertStatement) parser.parseStatement();
    List<SQLExpr> cc = insertStatement.getColumns();
    for (SQLExpr sqlExpr : cc) {
        SQLIdentifierExpr c = (SQLIdentifierExpr) sqlExpr;
        if ("_slot".equalsIgnoreCase(c.getName()) && cc.size() == insertStatement.getValues().getValues().size())
            return true;
    }
    return false;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:12,代码来源:DruidMysqlCreateTableTest.java

示例11: testModifySQLLimit

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
public void testModifySQLLimit() throws Exception {
    final SchemaConfig schema = schemaMap.get("TESTDB");

    String sql = null;
    RouteResultset rrs = null;
    //SQL span multi datanode 
    sql = "select * from orders limit 2,3";
    rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
    Assert.assertEquals(true, rrs.isCacheAble());
    Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 2);
    NodeNameAsserter nameAsserter = new NodeNameAsserter("dn2",
            "dn1");
    nameAsserter.assertRouteNodeNames(nodeMap.keySet());
    Assert.assertEquals(3, rrs.getLimitSize());


    MySqlStatementParser parser = new MySqlStatementParser("SELECT * FROM orders LIMIT 0,5");
    SQLStatement statement = parser.parseStatement();

    Assert.assertEquals(statement.toString(), rrs.getNodes()[0].getStatement());

    //SQL  not span multi datanode
    sql = "select * from customer where id=10000 limit 2,3";
    rrs = routeStrategy.route(schema, ServerParse.SELECT, sql, null, cachePool);
    Assert.assertEquals(true, rrs.isCacheAble());
    nodeMap = getNodeMap(rrs, 1);
    nameAsserter = new NodeNameAsserter("dn1");
    nameAsserter.assertRouteNodeNames(nodeMap.keySet());
    Assert.assertEquals(3, rrs.getLimitSize());
    Assert.assertEquals("select * from customer where id=10000 limit 2,3", rrs.getNodes()[0].getStatement());


}
 
开发者ID:actiontech,项目名称:dble,代码行数:34,代码来源:DruidMysqlRouteStrategyTest.java

示例12: convert

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
public static String convert(String sql, String sourceSchema, String sourceTable, String targetSchema,
                             String targetTable) {
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement stmt = parser.parseStatement();

    StringBuilder out = new StringBuilder();
    OtterMyqlOutputVisitor visitor = new OtterMyqlOutputVisitor(out,
        sourceSchema,
        sourceTable,
        targetSchema,
        targetTable);
    stmt.accept(visitor);
    return out.toString();
}
 
开发者ID:alibaba,项目名称:otter,代码行数:15,代码来源:DdlUtils.java

示例13: route

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
@Override
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 {
		MySqlStatementParser parser = new MySqlStatementParser(realSQL);	 
		SQLStatement statement = parser.parseStatement();
		MySqlInsertStatement insert = (MySqlInsertStatement)statement;
		if(insert.getValuesList()!=null){
			String tableName = StringUtil.getTableName(realSQL).toUpperCase();
			TableConfig tableConfig = schema.getTables().get(tableName);
			String primaryKey = tableConfig.getPrimaryKey();//获得表的主键字段
			
			SQLIdentifierExpr sqlIdentifierExpr = new SQLIdentifierExpr();
			sqlIdentifierExpr.setName(primaryKey);
			insert.getColumns().add(sqlIdentifierExpr);
			
			if(sequenceHandler == null){
				int seqHandlerType = MycatServer.getInstance().getConfig().getSystem().getSequnceHandlerType();
				switch(seqHandlerType){
					case SystemConfig.SEQUENCEHANDLER_MYSQLDB:
						sequenceHandler = IncrSequenceMySQLHandler.getInstance();
						break;
					case SystemConfig.SEQUENCEHANDLER_LOCALFILE:
						sequenceHandler = IncrSequencePropHandler.getInstance();
						break;
					case SystemConfig.SEQUENCEHANDLER_LOCAL_TIME:
						sequenceHandler = IncrSequenceTimeHandler.getInstance();
						break;
					case SystemConfig.SEQUENCEHANDLER_ZK_DISTRIBUTED:
						sequenceHandler = DistributedSequenceHandler.getInstance(MycatServer.getInstance().getConfig().getSystem());
						break;
					case SystemConfig.SEQUENCEHANDLER_ZK_GLOBAL_INCREMENT:
						sequenceHandler = IncrSequenceZKHandler.getInstance();
						break;
					default:
						throw new java.lang.IllegalArgumentException("Invalid sequnce handler type "+seqHandlerType);
				}
			}
			
			for(ValuesClause vc : insert.getValuesList()){
				SQLIntegerExpr sqlIntegerExpr = new SQLIntegerExpr();
				long value = sequenceHandler.nextId(tableName.toUpperCase());
				sqlIntegerExpr.setNumber(value);//插入生成的sequence值
				vc.addValue(sqlIntegerExpr);
			}
			
			String insertSql = insert.toString();
			this.executeSql = insertSql;
		}
		
	} catch (Exception e) {
		LOGGER.error("BatchInsertSequence.route(......)",e);
	}
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:64,代码来源:BatchInsertSequence.java

示例14: parseSql

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
public String parseSql(String sql) {
	MySqlStatementParser parser = new MySqlStatementParser(sql);
	SQLStatement statement = parser.parseStatement();
	return GlobalTableUtil.addColumnIfCreate(sql, statement);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:6,代码来源:GlobalTableUtilTest.java

示例15: parseSql

import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; //导入方法依赖的package包/类
public boolean parseSql(String sql) {
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    SQLStatement statement = parser.parseStatement();
    return hasColumn(statement);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:6,代码来源:DruidMysqlCreateTableTest.java


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