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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations