use of com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint in project druid by alibaba.
the class OracleStatementParser method parseAlterTable.
private SQLStatement parseAlterTable() {
lexer.nextToken();
SQLAlterTableStatement stmt = new SQLAlterTableStatement(getDbType());
stmt.setName(this.exprParser.name());
for (; ; ) {
if (identifierEquals("ADD")) {
lexer.nextToken();
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
SQLAlterTableAddColumn item = parseAlterTableAddColumn();
stmt.addItem(item);
accept(Token.RPAREN);
} else if (lexer.token() == Token.CONSTRAINT) {
OracleConstraint constraint = ((OracleExprParser) this.exprParser).parseConstaint();
SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint();
constraint.setParent(item);
item.setParent(stmt);
item.setConstraint(constraint);
stmt.addItem(item);
} else if (lexer.token() == Token.IDENTIFIER) {
SQLAlterTableAddColumn item = parseAlterTableAddColumn();
stmt.addItem(item);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
continue;
} else if (identifierEquals("MOVE")) {
lexer.nextToken();
if (lexer.token() == Token.TABLESPACE) {
lexer.nextToken();
OracleAlterTableMoveTablespace item = new OracleAlterTableMoveTablespace();
item.setName(this.exprParser.name());
stmt.addItem(item);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
} else if (identifierEquals("RENAME")) {
stmt.addItem(parseAlterTableRename());
} else if (identifierEquals("MODIFY")) {
lexer.nextToken();
OracleAlterTableModify item = new OracleAlterTableModify();
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
for (; ; ) {
SQLColumnDefinition columnDef = this.exprParser.parseColumn();
item.addColumn(columnDef);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
} else {
SQLColumnDefinition columnDef = this.exprParser.parseColumn();
item.addColumn(columnDef);
}
stmt.addItem(item);
continue;
} else if (identifierEquals("SPLIT")) {
parseAlterTableSplit(stmt);
continue;
} else if (lexer.token() == Token.TRUNCATE) {
lexer.nextToken();
if (identifierEquals("PARTITION")) {
lexer.nextToken();
OracleAlterTableTruncatePartition item = new OracleAlterTableTruncatePartition();
item.setName(this.exprParser.name());
stmt.addItem(item);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
continue;
} else if (lexer.token() == Token.DROP) {
parseAlterDrop(stmt);
continue;
} else if (lexer.token() == Token.DISABLE) {
lexer.nextToken();
if (lexer.token() == Token.CONSTRAINT) {
lexer.nextToken();
SQLAlterTableEnableConstraint item = new SQLAlterTableEnableConstraint();
item.setConstraintName(this.exprParser.name());
stmt.addItem(item);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
} else if (lexer.token() == Token.ENABLE) {
lexer.nextToken();
if (lexer.token() == Token.CONSTRAINT) {
lexer.nextToken();
SQLAlterTableDisableConstraint item = new SQLAlterTableDisableConstraint();
item.setConstraintName(this.exprParser.name());
stmt.addItem(item);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
}
break;
}
if (lexer.token() == Token.UPDATE) {
lexer.nextToken();
if (identifierEquals("GLOBAL")) {
lexer.nextToken();
acceptIdentifier("INDEXES");
stmt.setUpdateGlobalIndexes(true);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
}
return stmt;
}
use of com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint in project druid by alibaba.
the class OracleExprParser method parseConstaint.
public OracleConstraint parseConstaint() {
OracleConstraint constraint = (OracleConstraint) super.parseConstaint();
for (; ; ) {
if (lexer.token() == Token.EXCEPTIONS) {
lexer.nextToken();
accept(Token.INTO);
SQLName exceptionsInto = this.name();
constraint.setExceptionsInto(exceptionsInto);
continue;
}
if (lexer.token() == Token.DISABLE) {
lexer.nextToken();
constraint.setEnable(false);
continue;
}
if (lexer.token() == Token.ENABLE) {
lexer.nextToken();
constraint.setEnable(true);
continue;
}
if (lexer.token() == Token.INITIALLY) {
lexer.nextToken();
if (lexer.token() == Token.IMMEDIATE) {
lexer.nextToken();
constraint.setInitially(Initially.IMMEDIATE);
} else {
accept(Token.DEFERRED);
constraint.setInitially(Initially.DEFERRED);
}
continue;
}
if (lexer.token() == Token.NOT) {
lexer.nextToken();
if (identifierEquals("DEFERRABLE")) {
lexer.nextToken();
constraint.setDeferrable(false);
continue;
}
throw new ParserException("TODO " + lexer.token());
}
if (identifierEquals("DEFERRABLE")) {
lexer.nextToken();
constraint.setDeferrable(true);
continue;
}
break;
}
return constraint;
}
Aggregations