Search in sources :

Example 26 with TableStat

use of com.alibaba.druid.stat.TableStat in project Mycat-Server by MyCATApache.

the class MycatSchemaStatVisitor method visit.

@Override
public boolean visit(SQLAlterTableStatement x) {
    String tableName = x.getName().toString();
    TableStat stat = getTableStat(tableName, tableName);
    stat.incrementAlterCount();
    setCurrentTable(x, tableName);
    for (SQLAlterTableItem item : x.getItems()) {
        item.setParent(x);
        item.accept(this);
    }
    return false;
}
Also used : SQLAlterTableItem(com.alibaba.druid.sql.ast.statement.SQLAlterTableItem) TableStat(com.alibaba.druid.stat.TableStat)

Example 27 with TableStat

use of com.alibaba.druid.stat.TableStat in project Mycat-Server by MyCATApache.

the class MycatSchemaStatVisitor method visit.

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

Example 28 with TableStat

use of com.alibaba.druid.stat.TableStat in project Mycat-Server by MyCATApache.

the class MycatSchemaStatVisitor method visit.

// DUAL
public boolean visit(MySqlDeleteStatement x) {
    setAliasMap();
    setMode(x, Mode.Delete);
    accept(x.getFrom());
    accept(x.getUsing());
    x.getTableSource().accept(this);
    if (x.getTableSource() instanceof SQLExprTableSource) {
        SQLName tableName = (SQLName) ((SQLExprTableSource) x.getTableSource()).getExpr();
        String ident = tableName.toString();
        setCurrentTable(x, ident);
        TableStat stat = this.getTableStat(ident, ident);
        stat.incrementDeleteCount();
    }
    accept(x.getWhere());
    accept(x.getOrderBy());
    accept(x.getLimit());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource)

Example 29 with TableStat

use of com.alibaba.druid.stat.TableStat in project Mycat-Server by MyCATApache.

the class DruidUpdateParser method getUpdateTableCount.

/**
     * 获取更新的表数
     * @author lian
     * @date 2016年11月2日
     * @return
     */
private int getUpdateTableCount() {
    Map<Name, TableStat> tableMap = this.ctx.getVisitor().getTables();
    int updateTableCount = 0;
    for (Name _name : tableMap.keySet()) {
        TableStat ts = tableMap.get(_name);
        updateTableCount += ts.getUpdateCount();
    }
    return updateTableCount;
}
Also used : TableStat(com.alibaba.druid.stat.TableStat) Name(com.alibaba.druid.stat.TableStat.Name)

Example 30 with TableStat

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

the class OracleSchemaStatVisitor method visit.

public boolean visit(OracleUpdateStatement x) {
    setAliasMap();
    setMode(x, Mode.Update);
    SQLTableSource tableSource = x.getTableSource();
    SQLExpr tableExpr = null;
    if (tableSource instanceof SQLExprTableSource) {
        tableExpr = ((SQLExprTableSource) tableSource).getExpr();
    }
    if (tableExpr instanceof SQLName) {
        String ident = tableExpr.toString();
        setCurrentTable(ident);
        TableStat stat = getTableStat(ident);
        stat.incrementUpdateCount();
        Map<String, String> aliasMap = getAliasMap();
        aliasMap.put(ident, ident);
        aliasMap.put(tableSource.getAlias(), ident);
    } else {
        tableSource.accept(this);
    }
    accept(x.getItems());
    accept(x.getWhere());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) SQLTableSource(com.alibaba.druid.sql.ast.statement.SQLTableSource) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

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