コード例 #1
0
ファイル: MySqlOutputVisitor.java プロジェクト: flyneil/druid
  public boolean visit(SQLCreateTableStatement x) {

    MySqlCreateTableStatement mysqlCreateTableStatement = null;
    if (x instanceof MySqlCreateTableStatement) {
      mysqlCreateTableStatement = (MySqlCreateTableStatement) x;
    }

    if (SQLCreateTableStatement.Type.GLOBAL_TEMPORARY.equals(x.getType())) {
      print("CREATE TEMPORARY TABLE ");
    } else {
      print("CREATE TABLE ");
    }

    if (mysqlCreateTableStatement != null && mysqlCreateTableStatement.isIfNotExiists()) {
      print("IF NOT EXISTS ");
    }

    x.getName().accept(this);
    print(" (");
    incrementIndent();
    println();
    for (int i = 0, size = x.getTableElementList().size(); i < size; ++i) {
      if (i != 0) {
        print(", ");
        println();
      }
      x.getTableElementList().get(i).accept(this);
    }
    decrementIndent();
    println();
    print(")");

    if (mysqlCreateTableStatement != null) {
      for (Map.Entry<String, String> option :
          mysqlCreateTableStatement.getTableOptions().entrySet()) {
        print(" ");
        print(option.getKey());
        print(" = ");
        print(option.getValue());
      }
    }

    if (mysqlCreateTableStatement != null && mysqlCreateTableStatement.getQuery() != null) {
      print(" ");
      incrementIndent();
      println();
      mysqlCreateTableStatement.getQuery().accept(this);
      decrementIndent();
    }

    return false;
  }
コード例 #2
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;
  }
コード例 #3
0
  public SQLCreateTableStatement parseCrateTable(boolean acceptCreate) {
    if (acceptCreate) {
      accept(Token.CREATE);
    }

    SQLCreateTableStatement createTable = newCreateStatement();

    if (identifierEquals("GLOBAL")) {
      lexer.nextToken();

      if (identifierEquals("TEMPORARY")) {
        lexer.nextToken();
        createTable.setType(SQLCreateTableStatement.Type.GLOBAL_TEMPORARY);
      } else {
        throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal());
      }
    } else if (lexer.token() == Token.IDENTIFIER && lexer.stringVal().equalsIgnoreCase("LOCAL")) {
      lexer.nextToken();
      if (lexer.token() == Token.IDENTIFIER && lexer.stringVal().equalsIgnoreCase("TEMPORAY")) {
        lexer.nextToken();
        createTable.setType(SQLCreateTableStatement.Type.LOCAL_TEMPORARY);
      } else {
        throw new ParserException("syntax error");
      }
    }

    accept(Token.TABLE);

    createTable.setName(this.exprParser.name());

    if (lexer.token() == Token.LPAREN) {
      lexer.nextToken();

      for (; ; ) {
        if (lexer.token() == Token.IDENTIFIER //
            || lexer.token() == Token.LITERAL_ALIAS) {
          SQLColumnDefinition column = this.exprParser.parseColumn();
          createTable.getTableElementList().add(column);
        } else if (lexer.token == Token.PRIMARY //
            || lexer.token == Token.UNIQUE //
            || lexer.token == Token.CHECK //
            || lexer.token == Token.CONSTRAINT) {
          SQLConstraint constraint = this.exprParser.parseConstaint();
          constraint.setParent(createTable);
          createTable.getTableElementList().add((SQLTableElement) constraint);
        } else if (lexer.token() == Token.TABLESPACE) {
          throw new ParserException("TODO " + lexer.token());
        } else {
          SQLColumnDefinition column = this.exprParser.parseColumn();
          createTable.getTableElementList().add(column);
        }

        if (lexer.token() == Token.COMMA) {
          lexer.nextToken();

          if (lexer.token() == Token.RPAREN) { // compatible for sql server
            break;
          }
          continue;
        }

        break;
      }

      // while
      // (this.tokenList.current().equals(OracleToken.ConstraintToken)) {
      // parseConstaint(table.getConstraints());
      //
      // if (this.tokenList.current().equals(OracleToken.CommaToken))
      // ;
      // lexer.nextToken();
      // }

      accept(Token.RPAREN);

      if (identifierEquals("INHERITS")) {
        lexer.nextToken();
        accept(Token.LPAREN);
        SQLName inherits = this.exprParser.name();
        createTable.setInherits(new SQLExprTableSource(inherits));
        accept(Token.RPAREN);
      }
    }

    return createTable;
  }