Search in sources :

Example 6 with TableStat

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

the class SQLServerSchemaStatVisitor method visit.

@Override
public boolean visit(SQLServerUpdateStatement x) {
    setAliasMap();
    String ident = x.getTableName().toString();
    setCurrentTable(ident);
    TableStat stat = getTableStat(ident);
    stat.incrementUpdateCount();
    Map<String, String> aliasMap = getAliasMap();
    aliasMap.put(ident, ident);
    accept(x.getItems());
    accept(x.getFrom());
    accept(x.getWhere());
    return false;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat)

Example 7 with TableStat

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

the class SchemaStatVisitor method visit.

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

Example 8 with TableStat

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

the class SchemaStatVisitor method visit.

@Override
public boolean visit(SQLDropTableStatement x) {
    setMode(x, Mode.Insert);
    setAliasMap();
    String originalTable = getCurrentTable();
    for (SQLExprTableSource tableSource : x.getTableSources()) {
        SQLName name = (SQLName) tableSource.getExpr();
        String ident = name.toString();
        setCurrentTable(ident);
        x.putAttribute("_old_local_", originalTable);
        TableStat stat = getTableStat(ident);
        stat.incrementDropCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, ident, ident);
    }
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 9 with TableStat

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

the class SchemaStatVisitor method visit.

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

Example 10 with TableStat

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

the class PGSchemaStatVisitor method visit.

@Override
public boolean visit(PGDeleteStatement x) {
    if (x.getWith() != null) {
        x.getWith().accept(this);
    }
    setAliasMap();
    for (SQLName name : x.getUsing()) {
        String ident = name.toString();
        TableStat stat = getTableStat(ident);
        stat.incrementSelectCount();
        Map<String, String> aliasMap = getAliasMap();
        if (aliasMap != null) {
            aliasMap.put(ident, ident);
        }
    }
    x.putAttribute("_original_use_mode", getMode());
    setMode(x, Mode.Delete);
    String ident = ((SQLIdentifierExpr) x.getTableName()).getName();
    setCurrentTable(ident);
    TableStat stat = getTableStat(ident, x.getAlias());
    stat.incrementDeleteCount();
    accept(x.getWhere());
    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)

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