@Override public boolean visit(SQLInsertStatement x) { setMode(x, Mode.Insert); setAliasMap(); String originalTable = getCurrentTable(); if (x.getTableName() instanceof SQLName) { String ident = ((SQLName) x.getTableName()).toString(); setCurrentTable(ident); x.putAttribute("_old_local_", originalTable); TableStat stat = getTableStat(ident); stat.incrementInsertCount(); Map<String, String> aliasMap = getAliasMap(); if (aliasMap != null) { if (x.getAlias() != null) { aliasMap.put(x.getAlias(), ident); } aliasMap.put(ident, ident); } } accept(x.getColumns()); accept(x.getQuery()); return false; }
@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(); if (aliasMap != null) { aliasMap.put(ident, ident); } } return false; }
@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(); if (aliasMap != null) { aliasMap.put(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; }
public boolean visit(SQLSelectQueryBlock x) { if (x.getFrom() == null) { return false; } setMode(x, Mode.Select); if (x.getFrom() instanceof SQLSubqueryTableSource) { x.getFrom().accept(this); return false; } if (x.getInto() != null && x.getInto().getExpr() instanceof SQLName) { SQLName into = (SQLName) x.getInto().getExpr(); String ident = into.toString(); TableStat stat = getTableStat(ident); if (stat != null) { stat.incrementInsertCount(); } } String originalTable = getCurrentTable(); if (x.getFrom() instanceof SQLExprTableSource) { SQLExprTableSource tableSource = (SQLExprTableSource) x.getFrom(); if (tableSource.getExpr() instanceof SQLName) { String ident = tableSource.getExpr().toString(); setCurrentTable(x, ident); x.putAttribute(ATTR_TABLE, ident); if (x.getParent() instanceof SQLSelect) { x.getParent().putAttribute(ATTR_TABLE, ident); } x.putAttribute("_old_local_", originalTable); } } if (x.getFrom() != null) { x.getFrom().accept(this); // 提前执行,获得aliasMap String table = (String) x.getFrom().getAttribute(ATTR_TABLE); if (table != null) { x.putAttribute(ATTR_TABLE, table); } } // String ident = x.getTable().toString(); // // TableStat stat = getTableStat(ident); // stat.incrementInsertCount(); // return false; if (x.getWhere() != null) { x.getWhere().setParent(x); } return true; }
public boolean visit(SQLDeleteStatement x) { setAliasMap(); setMode(x, Mode.Delete); String tableName = x.getTableName().toString(); setCurrentTable(tableName); if (x.getAlias() != null) { this.aliasMap.put(x.getAlias(), tableName); } TableStat stat = getTableStat(tableName); stat.incrementDeleteCount(); accept(x.getWhere()); return false; }
@Override public boolean visit(SQLDropIndexStatement x) { setMode(x, Mode.DropIndex); SQLExprTableSource table = x.getTableName(); if (table != null) { SQLName name = (SQLName) table.getExpr(); String ident = name.toString(); setCurrentTable(ident); TableStat stat = getTableStat(ident); stat.incrementDropIndexCount(); Map<String, String> aliasMap = getAliasMap(); if (aliasMap != null) { aliasMap.put(ident, ident); } } return false; }
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(); aliasMap.put(ident, ident); } else { x.getTableSource().accept(this); } accept(x.getItems()); accept(x.getWhere()); return false; }
@Override public boolean visit(SQLDropViewStatement x) { setMode(x, Mode.Drop); return true; }