forked from alibaba/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
943 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/alibaba/druid/sql/dialect/db2/ast/stmt/DB2SelectQueryBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 1999-2011 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.druid.sql.dialect.db2.ast.stmt; | ||
|
||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; | ||
|
||
public class DB2SelectQueryBlock extends SQLSelectQueryBlock { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/alibaba/druid/sql/dialect/db2/parser/DB2ExprParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.alibaba.druid.sql.dialect.db2.parser; | ||
|
||
import com.alibaba.druid.sql.parser.Lexer; | ||
import com.alibaba.druid.sql.parser.SQLExprParser; | ||
|
||
public class DB2ExprParser extends SQLExprParser { | ||
|
||
public final static String[] AGGREGATE_FUNCTIONS = { "AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM", "ROW_NUMBER" }; | ||
|
||
public DB2ExprParser(String sql){ | ||
this(new DB2Lexer(sql)); | ||
this.lexer.nextToken(); | ||
} | ||
|
||
public DB2ExprParser(Lexer lexer){ | ||
super(lexer); | ||
this.aggregateFunctions = AGGREGATE_FUNCTIONS; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/alibaba/druid/sql/dialect/db2/parser/DB2Lexer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.alibaba.druid.sql.dialect.db2.parser; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.alibaba.druid.sql.parser.Keywords; | ||
import com.alibaba.druid.sql.parser.Lexer; | ||
import com.alibaba.druid.sql.parser.Token; | ||
|
||
|
||
public class DB2Lexer extends Lexer { | ||
|
||
public final static Keywords DEFAULT_DB2_KEYWORDS; | ||
|
||
static { | ||
Map<String, Token> map = new HashMap<String, Token>(); | ||
|
||
map.putAll(Keywords.DEFAULT_KEYWORDS.getKeywords()); | ||
|
||
DEFAULT_DB2_KEYWORDS = new Keywords(map); | ||
} | ||
|
||
public DB2Lexer(String input){ | ||
super(input); | ||
super.keywods = DEFAULT_DB2_KEYWORDS; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/alibaba/druid/sql/dialect/db2/parser/DB2SelectParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 1999-2011 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.druid.sql.dialect.db2.parser; | ||
|
||
import com.alibaba.druid.sql.ast.SQLSetQuantifier; | ||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery; | ||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; | ||
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock; | ||
import com.alibaba.druid.sql.parser.SQLExprParser; | ||
import com.alibaba.druid.sql.parser.SQLSelectParser; | ||
import com.alibaba.druid.sql.parser.Token; | ||
|
||
public class DB2SelectParser extends SQLSelectParser { | ||
|
||
public DB2SelectParser(SQLExprParser exprParser){ | ||
super(exprParser); | ||
} | ||
|
||
public DB2SelectParser(String sql){ | ||
this(new DB2ExprParser(sql)); | ||
} | ||
|
||
protected SQLExprParser createExprParser() { | ||
return new DB2ExprParser(lexer); | ||
} | ||
|
||
@Override | ||
public SQLSelectQuery query() { | ||
if (lexer.token() == Token.LPAREN) { | ||
lexer.nextToken(); | ||
|
||
SQLSelectQuery select = query(); | ||
accept(Token.RPAREN); | ||
|
||
return queryRest(select); | ||
} | ||
|
||
accept(Token.SELECT); | ||
|
||
if (lexer.token() == Token.COMMENT) { | ||
lexer.nextToken(); | ||
} | ||
|
||
DB2SelectQueryBlock queryBlock = new DB2SelectQueryBlock(); | ||
|
||
if (lexer.token() == Token.DISTINCT) { | ||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT); | ||
lexer.nextToken(); | ||
} else if (lexer.token() == Token.UNIQUE) { | ||
queryBlock.setDistionOption(SQLSetQuantifier.UNIQUE); | ||
lexer.nextToken(); | ||
} else if (lexer.token() == Token.ALL) { | ||
queryBlock.setDistionOption(SQLSetQuantifier.ALL); | ||
lexer.nextToken(); | ||
} | ||
|
||
parseSelectList(queryBlock); | ||
|
||
parseFrom(queryBlock); | ||
|
||
parseWhere(queryBlock); | ||
|
||
parseGroupBy(queryBlock); | ||
|
||
return queryRest(queryBlock); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/alibaba/druid/sql/dialect/db2/parser/DB2StatementParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.alibaba.druid.sql.dialect.db2.parser; | ||
|
||
import com.alibaba.druid.sql.parser.Lexer; | ||
import com.alibaba.druid.sql.parser.SQLStatementParser; | ||
|
||
|
||
public class DB2StatementParser extends SQLStatementParser { | ||
public DB2StatementParser(String sql) { | ||
super (new DB2ExprParser(sql)); | ||
} | ||
|
||
public DB2StatementParser(Lexer lexer){ | ||
super(new DB2ExprParser(lexer)); | ||
} | ||
|
||
public DB2SelectParser createSQLSelectParser() { | ||
return new DB2SelectParser(this.exprParser); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/alibaba/druid/sql/dialect/db2/visitor/DB2ASTVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.alibaba.druid.sql.dialect.db2.visitor; | ||
|
||
import com.alibaba.druid.sql.visitor.SQLASTVisitor; | ||
|
||
|
||
public interface DB2ASTVisitor extends SQLASTVisitor { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/alibaba/druid/sql/dialect/db2/visitor/DB2ASTVisitorAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alibaba.druid.sql.dialect.db2.visitor; | ||
|
||
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter; | ||
|
||
public class DB2ASTVisitorAdapter extends SQLASTVisitorAdapter implements DB2ASTVisitor { | ||
|
||
} |
Oops, something went wrong.