}
public OracleMergeStatement parseMerge() {
accept(Token.MERGE);
OracleMergeStatement stmt = new OracleMergeStatement();
parseHints(stmt.getHints());
accept(Token.INTO);
stmt.setInto(exprParser.name());
stmt.setAlias(as());
accept(Token.USING);
SQLTableSource using = this.createSQLSelectParser().parseTableSource();
stmt.setUsing(using);
accept(Token.ON);
stmt.setOn(exprParser.expr());
boolean insertFlag = false;
if (lexer.token() == Token.WHEN) {
lexer.nextToken();
if (lexer.token() == Token.MATCHED) {
OracleMergeStatement.MergeUpdateClause updateClause = new OracleMergeStatement.MergeUpdateClause();
lexer.nextToken();
accept(Token.THEN);
accept(Token.UPDATE);
accept(Token.SET);
for (;;) {
SQLUpdateSetItem item = new SQLUpdateSetItem();
item.setColumn(this.exprParser.name());
accept(Token.EQ);
item.setValue(this.exprParser.expr());
updateClause.getItems().add(item);
if (lexer.token() == (Token.COMMA)) {
lexer.nextToken();
continue;
}
break;
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
updateClause.setWhere(exprParser.expr());
}
if (lexer.token() == Token.DELETE) {
lexer.nextToken();
accept(Token.WHERE);
updateClause.setWhere(exprParser.expr());
}
stmt.setUpdateClause(updateClause);
} else if (lexer.token() == Token.NOT) {
lexer.nextToken();
insertFlag = true;
}
}
if (!insertFlag) {
if (lexer.token() == Token.WHEN) {
lexer.nextToken();
}
if (lexer.token() == Token.NOT) {
lexer.nextToken();
insertFlag = true;
}
}
if (insertFlag) {
OracleMergeStatement.MergeInsertClause insertClause = new OracleMergeStatement.MergeInsertClause();
accept(Token.MATCHED);
accept(Token.THEN);
accept(Token.INSERT);
if (lexer.token() == Token.LPAREN) {
accept(Token.LPAREN);
exprParser.exprList(insertClause.getColumns());
accept(Token.RPAREN);
}
accept(Token.VALUES);
accept(Token.LPAREN);
exprParser.exprList(insertClause.getValues());
accept(Token.RPAREN);
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
insertClause.setWhere(exprParser.expr());
}
stmt.setInsertClause(insertClause);
}
OracleErrorLoggingClause errorClause = parseErrorLoggingClause();
stmt.setErrorLoggingClause(errorClause);
return stmt;
}