Skip to content

Commit

Permalink
update docs for remove inline-expression .longValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 8, 2017
1 parent 1ee6d1a commit a8f7d1d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ try (
<property name="password" value=""/>
</bean>

<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id % 4}"/>
<rdb:data-source id="shardingDataSource">
<rdb:sharding-rule data-sources="dbtbl_0,dbtbl_1">
<rdb:table-rules>
Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ try (
<property name="password" value=""/>
</bean>

<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id % 4}"/>
<rdb:data-source id="shardingDataSource">
<rdb:sharding-rule data-sources="dbtbl_0,dbtbl_1">
<rdb:table-rules>
Expand Down
4 changes: 2 additions & 2 deletions sharding-jdbc-doc/content/00-overview/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ try (
<property name="password" value=""/>
</bean>

<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id % 4}"/>
<rdb:data-source id="shardingDataSource">
<rdb:sharding-rule data-sources="dbtbl_0,dbtbl_1">
<rdb:table-rules>
Expand Down
4 changes: 2 additions & 2 deletions sharding-jdbc-doc/content/01-start/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ try (
<property name="password" value=""/>
</bean>

<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id.longValue() % 4}"/>
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id % 4}"/>
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id % 4}"/>
<rdb:data-source id="shardingDataSource">
<rdb:sharding-rule data-sources="dbtbl_0,dbtbl_1">
<rdb:table-rules>
Expand Down
24 changes: 3 additions & 21 deletions sharding-jdbc-doc/content/02-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tables:
actualTables: t_order_${0..1}
tableStrategy: &table001
shardingColumns: order_id
algorithmExpression: t_order_${order_id.longValue() % 2}
algorithmExpression: t_order_${order_id % 2}

#绑定表中其余的表的策略与t_order的策略相同
t_order_item:
Expand Down Expand Up @@ -305,25 +305,7 @@ dbtbl_${['online', 'offline']}_${1..3}
表达式本质上是一段字符串,字符串中使用${}来嵌入groovy代码。

```groovy
data_source_${id.longValue() % 2 + 1}
data_source_${id % 2 + 1}
```

上面的表达式中data_source_是字符串前缀,id.longValue() % 2 + 1是groovy代码。

### 分区键值获取
groovy代码中可以使用分区键的名字直接获取表达式的值对象。

该对象是com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm.ShardingValueWrapper类型的对象。

该类中提供了一些方法,方便数据类型的转换。包装的原始类型一般为Number,java.util.Date,String 三种类型。使用类中的方法可以将这三种类型转换为需要的其他类型。

方法列表如下:

| *方法名* | *参数* | *返回类型* |
| ------------------------ | -------------- | -------------- |
| longValue() | | long |
| doubleValue() | | double |
| dateValue(String format) | 时间格式化表达式 | java.util.Date |
| dateValue() | | java.util.Date |
| toString(String format) | 时间格式化表达式 | String |
| toString() | | String |
上面的表达式中data_source_是字符串前缀,id % 2 + 1是groovy代码。
4 changes: 2 additions & 2 deletions sharding-jdbc-doc/content/02-guide/master-slave.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ dataSourceMap.put("ms_1", masterSlaveDs1);
<rdb:master-slave-data-source id="dbtbl_1" master-data-source-ref="dbtbl_1_master" slave-data-sources-ref="dbtbl_1_slave_0, dbtbl_1_slave_1" strategy-type="ROUND_ROBIN" />

<!-- 通过rdb:strategy和rdb:data-source继续构建分片数据源 -->
<rdb:strategy id="databaseStrategy" sharding-columns="user_id" algorithm-expression="dbtbl_${user_id.longValue() % 2}"/>
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 4}"/>
<rdb:strategy id="databaseStrategy" sharding-columns="user_id" algorithm-expression="dbtbl_${user_id % 2}"/>
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id % 4}"/>

<rdb:data-source id="shardingDataSource">
<rdb:sharding-rule data-sources="dbtbl_0, dbtbl_1">
Expand Down

0 comments on commit a8f7d1d

Please sign in to comment.