improved sql parser SchemaStatVisitor.

This commit is contained in:
wenshao
2016-09-27 11:11:32 +08:00
parent f1eb24a1de
commit 4833b71e83
11 changed files with 153 additions and 2 deletions
@@ -663,5 +663,11 @@ public class SQLUtils {
List<SQLStatement> stmtList = parseStatements(sql, dbType);
return SQLUtils.toSQLString(stmtList, dbType, null, null, tableMapping);
}
public static boolean containsIndexDDL(String sql, String dbType) {
List<SQLStatement> stmtList = parseStatements(sql, dbType);
return false;
}
}
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2101 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.ast;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
@@ -122,7 +122,9 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
}
tableName = handleName(tableName);
TableStat stat = tableStats.get(tableName);
TableStat.Name tableNameObj = new TableStat.Name(tableName);
TableStat stat = tableStats.get(tableNameObj);
if (stat == null) {
stat = new TableStat();
tableStats.put(new TableStat.Name(tableName), stat);
@@ -1452,6 +1454,10 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
for (SQLSelectOrderByItem item : x.getItems()) {
item.accept(this);
}
String table = ((SQLAlterTableStatement) x.getParent()).getName().toString();
TableStat tableStat = this.getTableStat(table);
tableStat.incrementCreateIndexCount();
return false;
}
@@ -1694,4 +1700,48 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
public boolean visit(SQLCreateSequenceStatement x) {
return false;
}
@Override
public boolean visit(SQLAlterTableAddConstraint x) {
SQLConstraint constraint = x.getConstraint();
if (constraint instanceof SQLUniqueConstraint) {
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
String tableName = stmt.getName().toString();
TableStat tableStat = this.getTableStat(tableName);
tableStat.incrementCreateIndexCount();
}
return true;
}
@Override
public boolean visit(SQLAlterTableDropIndex x) {
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
String tableName = stmt.getName().toString();
TableStat tableStat = this.getTableStat(tableName);
tableStat.incrementDropIndexCount();
return false;
}
@Override
public boolean visit(SQLAlterTableDropPrimaryKey x) {
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
String tableName = stmt.getName().toString();
TableStat tableStat = this.getTableStat(tableName);
tableStat.incrementDropIndexCount();
return false;
}
@Override
public boolean visit(SQLAlterTableDropKey x) {
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
String tableName = stmt.getName().toString();
TableStat tableStat = this.getTableStat(tableName);
tableStat.incrementDropIndexCount();
return false;
}
//
}