Search in sources :

Example 36 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class MySqlSchemaStatVisitor method visit.

@Override
public boolean visit(MySqlInsertStatement x) {
    setMode(x, Mode.Insert);
    setAliasMap();
    SQLName tableName = x.getTableName();
    String ident = null;
    if (tableName instanceof SQLIdentifierExpr) {
        ident = ((SQLIdentifierExpr) tableName).getName();
    } else if (tableName instanceof SQLPropertyExpr) {
        SQLPropertyExpr propertyExpr = (SQLPropertyExpr) tableName;
        if (propertyExpr.getOwner() instanceof SQLIdentifierExpr) {
            ident = propertyExpr.toString();
        }
    }
    if (ident != null) {
        setCurrentTable(x, ident);
        TableStat stat = getTableStat(ident);
        stat.incrementInsertCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, x.getAlias(), ident);
        putAliasMap(aliasMap, ident, ident);
    }
    accept(x.getColumns());
    accept(x.getValuesList());
    accept(x.getQuery());
    accept(x.getDuplicateKeyUpdate());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) TableStat(com.alibaba.druid.stat.TableStat) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)

Example 37 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class SchemaStatVisitor method visit.

public boolean visit(SQLDeleteStatement x) {
    setAliasMap();
    setMode(x, Mode.Delete);
    String tableName = x.getTableName().toString();
    setCurrentTable(tableName);
    if (x.getAlias() != null) {
        putAliasMap(this.aliasMap, x.getAlias(), tableName);
    }
    if (x.getTableSource() instanceof SQLSubqueryTableSource) {
        SQLSelectQuery selectQuery = ((SQLSubqueryTableSource) x.getTableSource()).getSelect().getQuery();
        if (selectQuery instanceof SQLSelectQueryBlock) {
            SQLSelectQueryBlock subQueryBlock = ((SQLSelectQueryBlock) selectQuery);
            subQueryBlock.getWhere().accept(this);
        }
    }
    TableStat stat = getTableStat(tableName);
    stat.incrementDeleteCount();
    accept(x.getWhere());
    return false;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Example 38 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class SchemaStatVisitor method visit.

public boolean visit(SQLCreateTableStatement x) {
    for (SQLTableElement e : x.getTableElementList()) {
        e.setParent(x);
    }
    String tableName = x.getName().toString();
    TableStat stat = getTableStat(tableName);
    stat.incrementCreateCount();
    setCurrentTable(x, tableName);
    accept(x.getTableElementList());
    restoreCurrentTable(x);
    if (x.getInherits() != null) {
        x.getInherits().accept(this);
    }
    if (x.getSelect() != null) {
        x.getSelect().accept(this);
    }
    return false;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Example 39 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class SchemaStatVisitor method visit.

public boolean visit(SQLUpdateStatement x) {
    setAliasMap();
    setMode(x, Mode.Update);
    SQLName identName = x.getTableName();
    if (identName != null) {
        String ident = identName.toString();
        setCurrentTable(ident);
        TableStat stat = getTableStat(ident);
        stat.incrementUpdateCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, ident, ident);
    } else {
        x.getTableSource().accept(this);
    }
    accept(x.getFrom());
    accept(x.getItems());
    accept(x.getWhere());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 40 with TableStat

use of com.alibaba.druid.stat.TableStat in project druid by alibaba.

the class SchemaStatVisitor method getTableStat.

public TableStat getTableStat(String tableName, String alias) {
    if (variants.containsKey(tableName)) {
        return null;
    }
    tableName = handleName(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);
        putAliasMap(aliasMap, alias, tableName);
    }
    return stat;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) SQLName(com.alibaba.druid.sql.ast.SQLName)

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