Search in sources :

Example 16 with TableStat

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;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 17 with TableStat

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;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Example 18 with TableStat

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;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 19 with TableStat

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;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Example 20 with TableStat

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;
    }
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) Map(java.util.Map) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Aggregations

TableStat (com.alibaba.druid.stat.TableStat)45 SQLName (com.alibaba.druid.sql.ast.SQLName)21 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)10 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)9 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)9 SQLUtils (com.alibaba.druid.sql.SQLUtils)6 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)4 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)3 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)3 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)3 Mode (com.alibaba.druid.stat.TableStat.Mode)2 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)1 SQLAlterTableItem (com.alibaba.druid.sql.ast.statement.SQLAlterTableItem)1 SQLDropIndexStatement (com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement)1 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)1 Name (com.alibaba.druid.stat.TableStat.Name)1 Map (java.util.Map)1