Пример #1
0
  @Override
  public MySqlPrimaryKey parsePrimaryKey() {
    accept(Token.PRIMARY);
    accept(Token.KEY);

    MySqlPrimaryKey primaryKey = new MySqlPrimaryKey();

    if (identifierEquals("USING")) {
      lexer.nextToken();
      primaryKey.setIndexType(lexer.stringVal());
      lexer.nextToken();
    }

    accept(Token.LPAREN);
    for (; ; ) {
      primaryKey.getColumns().add(this.expr());
      if (!(lexer.token() == (Token.COMMA))) {
        break;
      } else {
        lexer.nextToken();
      }
    }
    accept(Token.RPAREN);

    return primaryKey;
  }
Пример #2
0
  @Override
  public boolean visit(MySqlPrimaryKey x) {
    if (x.getName() != null) {
      print("CONSTRAINT ");
      x.accept(this);
      print(' ');
    }

    print("PRIAMRY KEY");

    if (x.getIndexType() != null) {
      print(" USING ");
      print(x.getIndexType());
    }

    print(" (");

    for (int i = 0, size = x.getColumns().size(); i < size; ++i) {
      if (i != 0) {
        print(", ");
      }
      x.getColumns().get(i).accept(this);
    }
    print(")");

    return false;
  }