-
Notifications
You must be signed in to change notification settings - Fork 43
Quick start C1
sunyi edited this page Jun 6, 2016
·
5 revisions
一个插入时(insert)分表的例子
假设现在有一个大表 order 表,将 order 表分成4张表, order_00,01,02,03。
order_00, order_02 两张表在 数据源 ds_0 中
order_01, order_03 两张表在 数据源 ds_1 中
根据 ID 按 4 取余,分别到 4 个表中,order_{xx} , xx = id % 4
baymax的配置文件
<!-- order 是个逻辑表名 -->
<baymax:table tableName="order" namePatten="order_{00}">
<baymax:columns>
<baymax:column name="id"/> <!-- 根据 id 分表 -->
</baymax:columns>
<!-- 具体分表的逻辑方法 -->
<baymax:function class="com.tongbanjie.baymax.quickstart.c1.VirtualModFunction4_4"/>
<baymax:nodeMapping class="com.tongbanjie.baymax.router.strategy.SimpleTableNodeMapping">
<!-- p0 代表是一个数据源,与 multipleDataSource 定义的 identity 对应 -->
<!-- 这个配置代表的是 p0 这个数据源里有 order_00 与 order_02 两个表 -->
<baymax:node>p0:00,02</baymax:node>
<!-- 这个配置代表的是 p1 这个数据源里有 order_01 与 order_03 两个表 -->
<baymax:node>p1:01,03</baymax:node>
</baymax:nodeMapping>
</baymax:table>
对应的Java代码在: QuickStartC1