use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class SchemaStatVisitor method visit.
@Override
public boolean visit(SQLForeignKeyImpl x) {
for (SQLName column : x.getReferencingColumns()) {
column.accept(this);
}
String table = x.getReferencedTableName().getSimpleName();
setCurrentTable(table);
TableStat stat = getTableStat(table);
stat.incrementReferencedCount();
for (SQLName column : x.getReferencedColumns()) {
String columnName = column.getSimpleName();
addColumn(table, columnName);
}
return false;
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class SchemaStatVisitor method visit.
@Override
public boolean visit(SQLAlterTableStatement x) {
String tableName = x.getName().toString();
TableStat stat = getTableStat(tableName);
stat.incrementAlterCount();
setCurrentTable(x, tableName);
for (SQLAlterTableItem item : x.getItems()) {
item.setParent(x);
item.accept(this);
}
return false;
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class SchemaStatVisitor method visit.
@Override
public boolean visit(SQLCreateIndexStatement x) {
setMode(x, Mode.CreateIndex);
SQLName name = (SQLName) ((SQLExprTableSource) x.getTable()).getExpr();
String table = name.toString();
setCurrentTable(table);
TableStat stat = getTableStat(table);
stat.incrementDropIndexCount();
Map<String, String> aliasMap = getAliasMap();
putAliasMap(aliasMap, table, table);
for (SQLSelectOrderByItem item : x.getItems()) {
SQLExpr expr = item.getExpr();
if (expr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
String columnName = identExpr.getName();
addColumn(table, columnName);
}
}
return false;
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class SchemaStatVisitor method visit.
@Override
public boolean visit(SQLAlterTableAddIndex x) {
for (SQLSelectOrderByItem item : x.getItems()) {
item.accept(this);
}
String table = ((SQLAlterTableStatement) x.getParent()).getName().toString();
TableStat tableStat = this.getTableStat(table);
tableStat.incrementCreateIndexCount();
return false;
}
use of com.alibaba.druid.stat.TableStat in project druid by alibaba.
the class ExportTables method evaluate.
public String evaluate(String sql, String dbType) {
try {
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType);
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
for (SQLStatement stmt : statementList) {
stmt.accept(visitor);
}
StringBuffer buf = new StringBuffer();
for (Map.Entry<TableStat.Name, TableStat> entry : visitor.getTables().entrySet()) {
TableStat.Name name = entry.getKey();
if (buf.length() != 0) {
buf.append(',');
}
buf.append(name.toString());
}
return buf.toString();
} catch (Throwable ex) {
System.err.println("error sql : " + sql);
ex.printStackTrace();
return null;
}
}
Aggregations