コード例 #1
0
  public void endVisit(SQLSelectQueryBlock x) {
    String originalTable = (String) x.getAttribute("_old_local_");
    x.putAttribute("table", getCurrentTable());
    setCurrentTable(originalTable);

    setModeOrigin(x);
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
  @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;
  }
コード例 #4
0
  @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;
  }
コード例 #5
0
  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;
  }
コード例 #6
0
  public boolean visit(SQLSelect x) {
    setCurrentTable(x);

    if (x.getOrderBy() != null) {
      x.getOrderBy().setParent(x);
    }

    accept(x.getQuery());

    String originalTable = getCurrentTable();

    setCurrentTable((String) x.getQuery().getAttribute("table"));
    x.putAttribute("_old_local_", originalTable);

    accept(x.getOrderBy());

    setCurrentTable(originalTable);

    return false;
  }
コード例 #7
0
  @Override
  public boolean visit(SQLAlterTableStatement x) {
    String tableName = x.getName().toString();
    TableStat stat = getTableStat(tableName);
    stat.incrementAlterCount();

    setCurrentTable(x, tableName);

    for (SQLAlterTableItem item : x.getItems()) {
      item.setParent(x);
      item.accept(this);
    }

    return false;
  }
コード例 #8
0
  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);

    return false;
  }
コード例 #9
0
  @Override
  public boolean visit(SQLForeignKeyImpl x) {

    for (SQLName column : x.getReferencedColumns()) {
      column.accept(this);
    }

    String table = x.getReferencedTableName().getSimpleName();
    setCurrentTable(table);

    TableStat stat = getTableStat(table);
    stat.incrementReferencedCount();
    for (SQLName column : x.getReferencedColumns()) {
      String columnName = column.getSimpleName();
      addColumn(table, columnName);
    }

    return false;
  }
コード例 #10
0
  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;
  }
コード例 #11
0
  @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;
  }
コード例 #12
0
  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;
  }