当前位置:网站首页>学习Apache ShardingSphere解析器源码(一)
学习Apache ShardingSphere解析器源码(一)
2022-08-10 23:44:00 【InfoQ】
1. 写作由来
2. 以Oracle的DropTable功能为例分析
dropTable
: DROP TABLE tableName (CASCADE CONSTRAINTS)? (PURGE)?
;
tableName
: (owner DOT_)? name
;
owner
: identifier
;
name
: identifier
;
identifier
: IDENTIFIER_ | unreservedWord
;
-- 删除用户tom下的jerry表
drop table tom.jerry;
public interface ASTNode {}
public class IdentifierValue implements ASTNode {
private final String name;
public IdentifierValue(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public class TableName implements ASTNode {
private IdentifierValue owner;
private final IdentifierValue name;
public TableName(IdentifierValue name) {
this.name = name;
}
public void setOwner(IdentifierValue owner) {
this.owner = owner;
}
public Optional<IdentifierValue> getOwner() {
return Optional.ofNullable(owner);
}
public IdentifierValue getName() {
return name;
}
}
public class DropTableStatement implements ASTNode {
private final TableName tableName;
public DropTableStatement(TableName tableName) {
this.tableName = tableName;
}
public TableName getTableName() {
return tableName;
}
@Override
public String toString() {
return "DropTableStatement{" +
"tableName=" + tableName +
'}';
}
}
public class OracleDDLStatementVisitor extends OracleStatementBaseVisitor<ASTNode> {
@Override
public ASTNode visitDropTable(OracleStatementParser.DropTableContext ctx) {
return new DropTableStatement((TableName) visit(ctx.tableName()));
}
@Override
public ASTNode visitTableName(OracleStatementParser.TableNameContext ctx) {
TableName result = new TableName((IdentifierValue) visit(ctx.name()));
if (Objects.nonNull(ctx.owner())) {
result.setOwner((IdentifierValue) visit(ctx.owner()));
}
return result;
}
@Override
public ASTNode visitIdentifier(OracleStatementParser.IdentifierContext ctx) {
return new IdentifierValue(ctx.IDENTIFIER_().getText());
}
}
边栏推荐
猜你喜欢
Parse method's parameter list (including parameter names)
C language, operators of shift operators (> >, < <) explanation
11. 自定义转换器
[C Language Chapter] Detailed explanation of bitwise operators (“<<”, “>>”, “&”, “|”, “^”, “~”)
Server Tips
[C language articles] Expression evaluation (implicit type conversion, arithmetic conversion)
CW614N铜棒CuZn39Pb3对应牌号
Easy-to-use translation plug-in - one-click automatic translation plug-in software
22年全国程序员1月薪资出炉,才知道年薪 40 万以上的有这么多?
C3604环保黄铜带
随机推荐
深度学习 Transformer架构解析
App的回归测试,有什么高效的测试方法?
如何判断一个数为多少进制?
ROS实验笔记之——安装QPEP以及Intel-MKL
[C language articles] Expression evaluation (implicit type conversion, arithmetic conversion)
7. yaml
iNFTnews | In the Web3 era, users will have data autonomy
SQL注入基础---order by \ limit \ 宽字节注入
jsp中使用JDBC连接mysql的方法与实例
Geogebra 教程之 03 没有铅笔的数学
Talking about jsfuck coding
CW617N锡青铜 CuZn40Pb2对应牌号
《剑指offer》题解——week2(持续更新)
5. Lombok
3. 容器功能
【C语言】二分查找(折半查找)
Web-based meal ordering system in epidemic quarantine area
[C language] Implementation of guessing number game
I caught a 10-year-old Ali test developer, and after talking about it, I made a lot of money...
9. Rest 风格请求处理