shardingjdbc源码解析

入口分析:

  1. org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement#execute
    这里是分库分表的切入口
    在这里插入图片描述

  2. org.apache.shardingsphere.core.BaseShardingEngine#shard

在这里插入图片描述
3. org.apache.shardingsphere.core.PreparedQueryShardingEngine#route
4. org.apache.shardingsphere.core.route.PreparedStatementRoutingEngine#route
这里开始对逻辑sql进行解析
在这里插入图片描述

4.1. org.apache.shardingsphere.core.route.router.sharding.ParsingSQLRouter#parse
在这里插入图片描述

4.2 org.apache.shardingsphere.core.parse.SQLParsingEngine#parse

  • 首先判断缓存中是否存在解析结果
  • 解析逻辑sql到SQLStatement
    在这里插入图片描述
  1. org.apache.shardingsphere.core.route.router.sharding.ParsingSQLRouter#route
    在这里插入图片描述
    6.1 org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine#route()
    6.2 org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine#getDataNodes
    6.3 org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine#routeByShardingConditions
    6.4 org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine#routeByShardingConditionsWithCondition
    6.5 org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine#routeTables
    这里会根据是否含有分片键来判断是直接查询所有表还是根据分片键查询对应的实际表。
    在这里插入图片描述
    6.6 org.apache.shardingsphere.core.strategy.route.standard.StandardShardingStrategy#doSharding

这里最终会进入到你定义的分表规则,去获取到最终真实要查询的表名称
6.7 com.cxytiandi.sharding.algorithm.MyPreciseShardingAlgorithm#doSharding
在这里插入图片描述
7. org.apache.shardingsphere.core.BaseShardingEngine#rewriteAndConvert
重写sql语句
在这里插入图片描述
7.1 org.apache.shardingsphere.core.rewrite.SQLRewriteEngine#rewrite
在这里将表名进行改写:
insert int user(id,name) values(1, ‘xly’);
改写为
insert into user_1(id,name) values(1, ‘xly’);

在这里插入图片描述
到这里就结束了源码的解析。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值