当前位置:网站首页>学习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());
}
}
边栏推荐
- Geogebra 教程之 03 没有铅笔的数学
- mysql数据库高级操作
- 10. Notes on receiving parameters
- How to quickly grasp industry opportunities and introduce new ones more efficiently is an important proposition
- 12. Handling JSON
- Is there a way out in the testing industry if it is purely business testing?
- The Missing Semester of Your CS Education
- Multilingual Translation - Multilingual Translation Software Free
- 基于Web的疫情隔离区订餐系统
- mysql索引,事务与存储引擎
猜你喜欢
随机推荐
9. Rest 风格请求处理
开源一夏|OpenHarmony如何选择图片在Image组件上显示(eTS)
烘干衣服问题
Special class and type conversion
There is no recycle bin for deleted files on the computer desktop, what should I do if the deleted files on the desktop cannot be found in the recycle bin?
Rust从入门到精通05-语句和表达式
Cache knowledge summary
Timers, synchronous and asynchronous APIs, file system modules, file streams
盘点美军的无人机家底
jsp中使用JDBC连接mysql的方法与实例
2. 依赖管理和自动配置
【C语言】C语言程序设计:动态通讯录(顺序表实现)
如何快速把握行业机会,更高效地推陈出新,是一个重要的命题
SQL注入基础---order by \ limit \ 宽字节注入
iNFTnews | In the Web3 era, users will have data autonomy
I caught a 10-year-old Ali test developer, and after talking about it, I made a lot of money...
15. 拦截器-HandlerInterceptor
mysql数据库高级操作
14. Thymeleaf
Geogebra 教程之 03 没有铅笔的数学









