mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
ddd mapping support
This commit is contained in:
@@ -50,108 +50,110 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
return queryRest(select);
|
||||
}
|
||||
|
||||
accept(Token.SELECT);
|
||||
|
||||
MySqlSelectQueryBlock queryBlock = new MySqlSelectQueryBlock();
|
||||
|
||||
if (lexer.token() == (Token.DISTINCT)) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("DISTINCTROW")) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCTROW);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == (Token.ALL)) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.ALL);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("HIGH_PRIORITY")) {
|
||||
queryBlock.setHignPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("STRAIGHT_JOIN")) {
|
||||
queryBlock.setStraightJoin(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_SMALL_RESULT")) {
|
||||
queryBlock.setSmallResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_BIG_RESULT")) {
|
||||
queryBlock.setBigResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_BUFFER_RESULT")) {
|
||||
queryBlock.setBufferResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_CACHE")) {
|
||||
queryBlock.setCache(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_NO_CACHE")) {
|
||||
queryBlock.setCache(false);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_CALC_FOUND_ROWS")) {
|
||||
queryBlock.setCalcFoundRows(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
parseSelectList(queryBlock);
|
||||
|
||||
if (lexer.token() == (Token.INTO)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("OUTFILE");
|
||||
SQLExpr outFile = expr();
|
||||
queryBlock.setOutFile(outFile);
|
||||
|
||||
if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
|
||||
if (lexer.token() == (Token.DISTINCT)) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("DISTINCTROW")) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCTROW);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == (Token.ALL)) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.ALL);
|
||||
lexer.nextToken();
|
||||
|
||||
if (identifierEquals("TERMINATED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
}
|
||||
queryBlock.setOutFileColumnsTerminatedBy((SQLLiteralExpr) expr());
|
||||
|
||||
if (identifierEquals("OPTIONALLY")) {
|
||||
lexer.nextToken();
|
||||
queryBlock.setOutFileColumnsEnclosedOptionally(true);
|
||||
}
|
||||
|
||||
if (identifierEquals("ENCLOSED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileColumnsEnclosedBy((SQLLiteralExpr) expr());
|
||||
}
|
||||
|
||||
if (identifierEquals("ESCAPED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileColumnsEscaped((SQLLiteralExpr) expr());
|
||||
}
|
||||
}
|
||||
|
||||
if (identifierEquals("LINES")) {
|
||||
if (identifierEquals("HIGH_PRIORITY")) {
|
||||
queryBlock.setHignPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("STARTING")) {
|
||||
if (identifierEquals("STRAIGHT_JOIN")) {
|
||||
queryBlock.setStraightJoin(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_SMALL_RESULT")) {
|
||||
queryBlock.setSmallResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_BIG_RESULT")) {
|
||||
queryBlock.setBigResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_BUFFER_RESULT")) {
|
||||
queryBlock.setBufferResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_CACHE")) {
|
||||
queryBlock.setCache(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_NO_CACHE")) {
|
||||
queryBlock.setCache(false);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("SQL_CALC_FOUND_ROWS")) {
|
||||
queryBlock.setCalcFoundRows(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
parseSelectList(queryBlock);
|
||||
|
||||
if (lexer.token() == (Token.INTO)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("OUTFILE");
|
||||
SQLExpr outFile = expr();
|
||||
queryBlock.setOutFile(outFile);
|
||||
|
||||
if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileLinesStartingBy((SQLLiteralExpr) expr());
|
||||
} else {
|
||||
identifierEquals("TERMINATED");
|
||||
|
||||
if (identifierEquals("TERMINATED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
}
|
||||
queryBlock.setOutFileColumnsTerminatedBy((SQLLiteralExpr) expr());
|
||||
|
||||
if (identifierEquals("OPTIONALLY")) {
|
||||
lexer.nextToken();
|
||||
queryBlock.setOutFileColumnsEnclosedOptionally(true);
|
||||
}
|
||||
|
||||
if (identifierEquals("ENCLOSED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileColumnsEnclosedBy((SQLLiteralExpr) expr());
|
||||
}
|
||||
|
||||
if (identifierEquals("ESCAPED")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileColumnsEscaped((SQLLiteralExpr) expr());
|
||||
}
|
||||
}
|
||||
|
||||
if (identifierEquals("LINES")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileLinesTerminatedBy((SQLLiteralExpr) expr());
|
||||
|
||||
if (identifierEquals("STARTING")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileLinesStartingBy((SQLLiteralExpr) expr());
|
||||
} else {
|
||||
identifierEquals("TERMINATED");
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
queryBlock.setOutFileLinesTerminatedBy((SQLLiteralExpr) expr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
-34
@@ -87,45 +87,47 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
public MySqlDeleteStatement parseDeleteStatement() throws ParserException {
|
||||
accept(Token.DELETE);
|
||||
|
||||
MySqlDeleteStatement deleteStatement = new MySqlDeleteStatement();
|
||||
|
||||
if (identifierEquals("LOW_PRIORITY")) {
|
||||
deleteStatement.setLowPriority(true);
|
||||
if (lexer.token() == Token.DELETE) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("QUICK")) {
|
||||
deleteStatement.setQuick(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("IGNORE")) {
|
||||
deleteStatement.setIgnore(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
exprParser.names(deleteStatement.getTableNames());
|
||||
|
||||
if (lexer.token() == Token.FROM) {
|
||||
if (identifierEquals("LOW_PRIORITY")) {
|
||||
deleteStatement.setLowPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("QUICK")) {
|
||||
deleteStatement.setQuick(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("IGNORE")) {
|
||||
deleteStatement.setIgnore(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
exprParser.names(deleteStatement.getTableNames());
|
||||
|
||||
if (lexer.token() == Token.FROM) {
|
||||
lexer.nextToken();
|
||||
SQLTableSource tableSource = createSQLSelectParser().parseTableSource();
|
||||
deleteStatement.setFrom(tableSource);
|
||||
}
|
||||
} else {
|
||||
if (lexer.token() == Token.FROM) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
exprParser.names(deleteStatement.getTableNames());
|
||||
}
|
||||
|
||||
if (identifierEquals("USING")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLTableSource tableSource = createSQLSelectParser().parseTableSource();
|
||||
deleteStatement.setFrom(tableSource);
|
||||
deleteStatement.setUsing(tableSource);
|
||||
}
|
||||
} else {
|
||||
if (lexer.token() == Token.FROM) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
exprParser.names(deleteStatement.getTableNames());
|
||||
}
|
||||
|
||||
if (identifierEquals("USING")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLTableSource tableSource = createSQLSelectParser().parseTableSource();
|
||||
deleteStatement.setUsing(tableSource);
|
||||
}
|
||||
|
||||
if (lexer.token() == (Token.WHERE)) {
|
||||
@@ -987,7 +989,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
protected SQLDropTableStatement parseDropTable(boolean acceptDrop) {
|
||||
if (acceptDrop) {
|
||||
accept(Token.DROP);
|
||||
@@ -995,7 +997,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
accept(Token.TABLE);
|
||||
|
||||
MySqlDropTableStatement stmt = new MySqlDropTableStatement();
|
||||
|
||||
|
||||
if (lexer.token() == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EXISTS);
|
||||
|
||||
Reference in New Issue
Block a user