Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
14c9e3bd
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
14c9e3bd
编写于
9月 09, 2017
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move inline parser to core
上级
d0ec4aa1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
280 addition
and
18 deletion
+280
-18
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/main/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/InlineParser.java
...ame/rdb/sharding/config/common/internal/InlineParser.java
+11
-11
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/AllTests.java
...dangdang/ddframe/rdb/sharding/config/common/AllTests.java
+2
-2
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/InlineExpressionParserTest.java
...ng/config/common/internal/InlineExpressionParserTest.java
+3
-2
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/rule/TableRule.java
...com/dangdang/ddframe/rdb/sharding/api/rule/TableRule.java
+25
-0
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/util/InlineExpressionParser.java
...ang/ddframe/rdb/sharding/util/InlineExpressionParser.java
+170
-0
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/util/AllUtilTests.java
.../com/dangdang/ddframe/rdb/sharding/util/AllUtilTests.java
+2
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/util/InlineExpressionParserTest.java
...ddframe/rdb/sharding/util/InlineExpressionParserTest.java
+65
-0
sharding-jdbc-example/sharding-jdbc-example-jdbc/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/Main.java
.../com/dangdang/ddframe/rdb/sharding/example/jdbc/Main.java
+2
-2
未找到文件。
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/main/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/InlineParser.java
浏览文件 @
14c9e3bd
...
@@ -135,17 +135,6 @@ public final class InlineParser {
...
@@ -135,17 +135,6 @@ public final class InlineParser {
return
result
;
return
result
;
}
}
private
String
assemblySegment
(
final
List
<
String
>
cartesianValue
,
final
GString
segment
)
{
StringBuilder
result
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
segment
.
getStrings
().
length
;
i
++)
{
result
.
append
(
segment
.
getStrings
()[
i
]);
if
(
i
<
cartesianValue
.
size
())
{
result
.
append
(
cartesianValue
.
get
(
i
));
}
}
return
result
.
toString
();
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
private
Set
<
List
<
String
>>
getCartesianValues
(
final
GString
segment
)
{
private
Set
<
List
<
String
>>
getCartesianValues
(
final
GString
segment
)
{
List
<
Set
<
String
>>
result
=
new
ArrayList
<>(
segment
.
getValues
().
length
);
List
<
Set
<
String
>>
result
=
new
ArrayList
<>(
segment
.
getValues
().
length
);
...
@@ -167,4 +156,15 @@ public final class InlineParser {
...
@@ -167,4 +156,15 @@ public final class InlineParser {
}
}
return
Sets
.
cartesianProduct
(
result
);
return
Sets
.
cartesianProduct
(
result
);
}
}
private
String
assemblySegment
(
final
List
<
String
>
cartesianValue
,
final
GString
segment
)
{
StringBuilder
result
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
segment
.
getStrings
().
length
;
i
++)
{
result
.
append
(
segment
.
getStrings
()[
i
]);
if
(
i
<
cartesianValue
.
size
())
{
result
.
append
(
cartesianValue
.
get
(
i
));
}
}
return
result
.
toString
();
}
}
}
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/AllTests.java
浏览文件 @
14c9e3bd
...
@@ -19,7 +19,7 @@ package com.dangdang.ddframe.rdb.sharding.config.common;
...
@@ -19,7 +19,7 @@ package com.dangdang.ddframe.rdb.sharding.config.common;
import
com.dangdang.ddframe.rdb.sharding.config.common.api.ShardingRuleBuilderTest
;
import
com.dangdang.ddframe.rdb.sharding.config.common.api.ShardingRuleBuilderTest
;
import
com.dangdang.ddframe.rdb.sharding.config.common.internal.ClosureShardingAlgorithmTest
;
import
com.dangdang.ddframe.rdb.sharding.config.common.internal.ClosureShardingAlgorithmTest
;
import
com.dangdang.ddframe.rdb.sharding.config.common.internal.InlineParserTest
;
import
com.dangdang.ddframe.rdb.sharding.config.common.internal.Inline
Expression
ParserTest
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite
;
...
@@ -27,7 +27,7 @@ import org.junit.runners.Suite;
...
@@ -27,7 +27,7 @@ import org.junit.runners.Suite;
@Suite
.
SuiteClasses
({
@Suite
.
SuiteClasses
({
ShardingRuleBuilderTest
.
class
,
ShardingRuleBuilderTest
.
class
,
ClosureShardingAlgorithmTest
.
class
,
ClosureShardingAlgorithmTest
.
class
,
InlineParserTest
.
class
Inline
Expression
ParserTest
.
class
})
})
public
class
AllTests
{
public
class
AllTests
{
}
}
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/InlineParserTest.java
→
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/Inline
Expression
ParserTest.java
浏览文件 @
14c9e3bd
...
@@ -26,7 +26,7 @@ import static org.hamcrest.Matchers.hasItems;
...
@@ -26,7 +26,7 @@ import static org.hamcrest.Matchers.hasItems;
import
static
org
.
hamcrest
.
core
.
Is
.
is
;
import
static
org
.
hamcrest
.
core
.
Is
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
final
class
InlineParserTest
{
public
final
class
Inline
Expression
ParserTest
{
@Test
@Test
public
void
assertSplit
()
{
public
void
assertSplit
()
{
...
@@ -37,7 +37,8 @@ public final class InlineParserTest {
...
@@ -37,7 +37,8 @@ public final class InlineParserTest {
@Test
@Test
public
void
assertEvaluate
()
{
public
void
assertEvaluate
()
{
assertThat
(
new
InlineParser
(
" 1 , 2 "
).
evaluate
(),
hasItems
(
"1"
,
"2"
));
assertThat
(
new
InlineParser
(
" 1 , 2 "
).
evaluate
(),
hasItems
(
"1"
,
"2"
));
assertThat
(
new
InlineParser
(
" 1 , t_order_${1..2} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_1"
,
"t_order_2"
));
assertThat
(
new
InlineParser
(
" 1 , t_order_${[0, 1, 2]} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_0"
,
"t_order_1"
,
"t_order_2"
));
assertThat
(
new
InlineParser
(
" 1 , t_order_${0..2} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_0"
,
"t_order_1"
,
"t_order_2"
));
assertThat
(
new
InlineParser
(
" 1 , t_order_${null} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_"
));
assertThat
(
new
InlineParser
(
" 1 , t_order_${null} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_"
));
assertThat
(
new
InlineParser
(
" 1 , t_order_${'xx'} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_xx"
));
assertThat
(
new
InlineParser
(
" 1 , t_order_${'xx'} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_xx"
));
assertThat
(
new
InlineParser
(
" t_${['new','old']}_order_${1..2} "
).
evaluate
(),
hasItems
(
"t_new_order_1"
,
"t_new_order_2"
,
"t_old_order_1"
,
"t_old_order_2"
));
assertThat
(
new
InlineParser
(
" t_${['new','old']}_order_${1..2} "
).
evaluate
(),
hasItems
(
"t_new_order_1"
,
"t_new_order_2"
,
"t_old_order_1"
,
"t_old_order_2"
));
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/rule/TableRule.java
浏览文件 @
14c9e3bd
...
@@ -19,6 +19,7 @@ package com.dangdang.ddframe.rdb.sharding.api.rule;
...
@@ -19,6 +19,7 @@ package com.dangdang.ddframe.rdb.sharding.api.rule;
import
com.dangdang.ddframe.rdb.sharding.keygen.KeyGenerator
;
import
com.dangdang.ddframe.rdb.sharding.keygen.KeyGenerator
;
import
com.dangdang.ddframe.rdb.sharding.routing.strategy.ShardingStrategy
;
import
com.dangdang.ddframe.rdb.sharding.routing.strategy.ShardingStrategy
;
import
com.dangdang.ddframe.rdb.sharding.util.InlineExpressionParser
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Preconditions
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
...
@@ -235,6 +236,18 @@ public final class TableRule {
...
@@ -235,6 +236,18 @@ public final class TableRule {
return
this
;
return
this
;
}
}
/**
* Build actual tables.
*
* @param inlineExpression actual tables inline expression
* @return this builder
*/
public
TableRuleBuilder
actualTablesInlineExpression
(
final
String
inlineExpression
)
{
this
.
actualTables
.
clear
();
this
.
actualTables
.
addAll
(
new
InlineExpressionParser
(
inlineExpression
).
evaluate
());
return
this
;
}
/**
/**
* Build data source rule.
* Build data source rule.
*
*
...
@@ -258,6 +271,18 @@ public final class TableRule {
...
@@ -258,6 +271,18 @@ public final class TableRule {
return
this
;
return
this
;
}
}
/**
* Build data sources's names.
*
* @param inlineExpression data sources's names inline expression
* @return this builder
*/
public
TableRuleBuilder
dataSourceNames
(
final
String
inlineExpression
)
{
this
.
dataSourceNames
.
clear
();
this
.
dataSourceNames
.
addAll
(
new
InlineExpressionParser
(
inlineExpression
).
evaluate
());
return
this
;
}
/**
/**
* Build database sharding strategy.
* Build database sharding strategy.
*
*
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/util/InlineExpressionParser.java
0 → 100644
浏览文件 @
14c9e3bd
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package
com.dangdang.ddframe.rdb.sharding.util
;
import
com.google.common.base.Function
;
import
com.google.common.base.Splitter
;
import
com.google.common.collect.Collections2
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
groovy.lang.GString
;
import
groovy.lang.GroovyShell
;
import
lombok.RequiredArgsConstructor
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
/**
* Inline expression parser.
*
* @author gaohongtao
* @author zhangliang
*/
@RequiredArgsConstructor
public
final
class
InlineExpressionParser
{
private
static
final
char
SPLITTER
=
','
;
private
final
String
inlineExpression
;
/**
* Split inline expression.
*
* @return split inline expression segments
*/
public
List
<
String
>
split
()
{
return
Splitter
.
on
(
SPLITTER
).
trimResults
().
splitToList
(
inlineExpression
);
}
/**
* Split and evaluate inline expression.
*
* @return result list
*/
public
List
<
String
>
evaluate
()
{
final
GroovyShell
shell
=
new
GroovyShell
();
return
flattenSegments
(
Lists
.
transform
(
splitWithInlineExpression
(),
new
Function
<
String
,
Object
>()
{
@Override
public
Object
apply
(
final
String
input
)
{
StringBuilder
expression
=
new
StringBuilder
(
input
);
if
(!
input
.
startsWith
(
"\""
))
{
expression
.
insert
(
0
,
"\""
);
}
if
(!
input
.
endsWith
(
"\""
))
{
expression
.
append
(
"\""
);
}
return
shell
.
evaluate
(
expression
.
toString
());
}
}));
}
List
<
String
>
splitWithInlineExpression
()
{
List
<
String
>
result
=
new
ArrayList
<>();
StringBuilder
segment
=
new
StringBuilder
();
int
bracketsDepth
=
0
;
for
(
int
i
=
0
;
i
<
inlineExpression
.
length
();
i
++)
{
char
each
=
inlineExpression
.
charAt
(
i
);
switch
(
each
)
{
case
SPLITTER:
if
(
bracketsDepth
>
0
)
{
segment
.
append
(
each
);
}
else
{
result
.
add
(
segment
.
toString
().
trim
());
segment
.
setLength
(
0
);
}
break
;
case
'$'
:
if
(
'{'
==
inlineExpression
.
charAt
(
i
+
1
))
{
bracketsDepth
++;
}
segment
.
append
(
each
);
break
;
case
'}'
:
if
(
bracketsDepth
>
0
)
{
bracketsDepth
--;
}
segment
.
append
(
each
);
break
;
default
:
segment
.
append
(
each
);
break
;
}
}
if
(
segment
.
length
()
>
0
)
{
result
.
add
(
segment
.
toString
().
trim
());
}
return
result
;
}
private
List
<
String
>
flattenSegments
(
final
List
<
Object
>
segments
)
{
List
<
String
>
result
=
new
ArrayList
<>();
for
(
Object
each
:
segments
)
{
if
(
each
instanceof
GString
)
{
result
.
addAll
(
assemblyCartesianSegments
((
GString
)
each
));
}
else
{
result
.
add
(
each
.
toString
());
}
}
return
result
;
}
private
List
<
String
>
assemblyCartesianSegments
(
final
GString
segment
)
{
Set
<
List
<
String
>>
cartesianValues
=
getCartesianValues
(
segment
);
List
<
String
>
result
=
new
ArrayList
<>(
cartesianValues
.
size
());
for
(
List
<
String
>
each
:
cartesianValues
)
{
result
.
add
(
assemblySegment
(
each
,
segment
));
}
return
result
;
}
@SuppressWarnings
(
"unchecked"
)
private
Set
<
List
<
String
>>
getCartesianValues
(
final
GString
segment
)
{
List
<
Set
<
String
>>
result
=
new
ArrayList
<>(
segment
.
getValues
().
length
);
for
(
Object
each
:
segment
.
getValues
())
{
if
(
null
==
each
)
{
continue
;
}
if
(
each
instanceof
Collection
)
{
result
.
add
(
Sets
.
newHashSet
(
Collections2
.
transform
((
Collection
<
Object
>)
each
,
new
Function
<
Object
,
String
>()
{
@Override
public
String
apply
(
final
Object
input
)
{
return
input
.
toString
();
}
})));
}
else
{
result
.
add
(
Sets
.
newHashSet
(
each
.
toString
()));
}
}
return
Sets
.
cartesianProduct
(
result
);
}
private
String
assemblySegment
(
final
List
<
String
>
cartesianValue
,
final
GString
segment
)
{
StringBuilder
result
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
segment
.
getStrings
().
length
;
i
++)
{
result
.
append
(
segment
.
getStrings
()[
i
]);
if
(
i
<
cartesianValue
.
size
())
{
result
.
append
(
cartesianValue
.
get
(
i
));
}
}
return
result
.
toString
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/util/AllUtilTests.java
浏览文件 @
14c9e3bd
...
@@ -23,7 +23,8 @@ import org.junit.runners.Suite;
...
@@ -23,7 +23,8 @@ import org.junit.runners.Suite;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@Suite
.
SuiteClasses
({
@Suite
.
SuiteClasses
({
NumberUtilTest
.
class
,
NumberUtilTest
.
class
,
StringUtilTest
.
class
,
StringUtilTest
.
class
,
InlineExpressionParserTest
.
class
,
SQLUtilTest
.
class
,
SQLUtilTest
.
class
,
EventBusInstanceTest
.
class
EventBusInstanceTest
.
class
})
})
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/util/InlineExpressionParserTest.java
0 → 100644
浏览文件 @
14c9e3bd
package
com.dangdang.ddframe.rdb.sharding.util
;
import
org.junit.Test
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
static
org
.
hamcrest
.
core
.
Is
.
is
;
import
static
org
.
hamcrest
.
core
.
IsCollectionContaining
.
hasItems
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
final
class
InlineExpressionParserTest
{
@Test
public
void
assertSplit
()
{
assertThat
(
new
InlineExpressionParser
(
" 1 "
).
split
(),
is
(
Collections
.
singletonList
(
"1"
)));
assertThat
(
new
InlineExpressionParser
(
" 1 , 2 "
).
split
(),
is
(
Arrays
.
asList
(
"1"
,
"2"
)));
}
@Test
public
void
assertEvaluate
()
{
assertThat
(
new
InlineExpressionParser
(
" 1 , 2 "
).
evaluate
(),
hasItems
(
"1"
,
"2"
));
assertThat
(
new
InlineExpressionParser
(
" 1 , t_order_${[0, 1, 2]} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_0"
,
"t_order_1"
,
"t_order_2"
));
assertThat
(
new
InlineExpressionParser
(
" 1 , t_order_${0..2} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_0"
,
"t_order_1"
,
"t_order_2"
));
assertThat
(
new
InlineExpressionParser
(
" 1 , t_order_${null} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_"
));
assertThat
(
new
InlineExpressionParser
(
" 1 , t_order_${'xx'} "
).
evaluate
(),
hasItems
(
"1"
,
"t_order_xx"
));
assertThat
(
new
InlineExpressionParser
(
" t_${['new','old']}_order_${1..2} "
).
evaluate
(),
hasItems
(
"t_new_order_1"
,
"t_new_order_2"
,
"t_old_order_1"
,
"t_old_order_2"
));
assertThat
(
new
InlineExpressionParser
(
" t_${[\"new${1+2}\",'old']}_order_${1..2} "
).
evaluate
(),
hasItems
(
"t_new3_order_1"
,
"t_new3_order_2"
,
"t_old_order_1"
,
"t_old_order_2"
));
}
@Test
public
void
assertSplitWithInlineExpressionForOneRegularValue
()
{
assertThat
(
new
InlineExpressionParser
(
"order"
).
splitWithInlineExpression
(),
is
(
Collections
.
singletonList
(
"order"
)));
}
@Test
public
void
assertSplitWithInlineExpressionForOneInlineValue
()
{
assertThat
(
new
InlineExpressionParser
(
"order_${0..7}"
).
splitWithInlineExpression
(),
is
(
Collections
.
singletonList
(
"order_${0..7}"
)));
}
@Test
public
void
assertSplitWithInlineExpressionForRegularValuesWithSpace
()
{
assertThat
(
new
InlineExpressionParser
(
" order , order_item "
).
splitWithInlineExpression
(),
is
(
Arrays
.
asList
(
"order"
,
"order_item"
)));
}
@Test
public
void
assertSplitWithInlineExpressionForMixedValuesWithSpace
()
{
assertThat
(
new
InlineExpressionParser
(
" order , order_item_${0..7} "
).
splitWithInlineExpression
(),
is
(
Arrays
.
asList
(
"order"
,
"order_item_${0..7}"
)));
}
@Test
public
void
assertSplitWithInlineExpressionForMixedValuesAndWithCommaAtInlineExpression
()
{
assertThat
(
new
InlineExpressionParser
(
" order , order_item_${0, 2, 4} "
).
splitWithInlineExpression
(),
is
(
Arrays
.
asList
(
"order"
,
"order_item_${0, 2, 4}"
)));
}
@Test
public
void
assertSplitWithInlineExpressionForMixedValuesAndNestedInlineExpression
()
{
assertThat
(
new
InlineExpressionParser
(
" order , order_item_${0, ${1..7}} "
).
splitWithInlineExpression
(),
is
(
Arrays
.
asList
(
"order"
,
"order_item_${0, ${1..7}}"
)));
}
@Test
public
void
assertSplitWithInlineExpressionForValuesNotInlineExpression
()
{
assertThat
(
new
InlineExpressionParser
(
" order , order_item_$ {0, 1} "
).
splitWithInlineExpression
(),
is
(
Arrays
.
asList
(
"order"
,
"order_item_$ {0"
,
"1}"
)));
}
}
sharding-jdbc-example/sharding-jdbc-example-jdbc/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/Main.java
浏览文件 @
14c9e3bd
...
@@ -118,8 +118,8 @@ public final class Main {
...
@@ -118,8 +118,8 @@ public final class Main {
private
static
ShardingDataSource
getShardingDataSource
()
throws
SQLException
{
private
static
ShardingDataSource
getShardingDataSource
()
throws
SQLException
{
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
());
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
());
TableRule
orderTableRule
=
TableRule
.
builder
(
"t_order"
).
actualTables
(
"t_order_0"
,
"t_order_1
"
).
dataSourceRule
(
dataSourceRule
).
build
();
TableRule
orderTableRule
=
TableRule
.
builder
(
"t_order"
).
actualTables
InlineExpression
(
"t_order_${[0, 1]}
"
).
dataSourceRule
(
dataSourceRule
).
build
();
TableRule
orderItemTableRule
=
TableRule
.
builder
(
"t_order_item"
).
actualTables
(
"t_order_item_0"
,
"t_order_item_1
"
).
dataSourceRule
(
dataSourceRule
).
build
();
TableRule
orderItemTableRule
=
TableRule
.
builder
(
"t_order_item"
).
actualTables
InlineExpression
(
"t_order_item_${[0, 1]}
"
).
dataSourceRule
(
dataSourceRule
).
build
();
ShardingRule
shardingRule
=
ShardingRule
.
builder
(
dataSourceRule
).
tableRules
(
orderTableRule
,
orderItemTableRule
)
ShardingRule
shardingRule
=
ShardingRule
.
builder
(
dataSourceRule
).
tableRules
(
orderTableRule
,
orderItemTableRule
)
.
bindingTableRules
(
new
BindingTableRule
(
orderTableRule
,
orderItemTableRule
))
.
bindingTableRules
(
new
BindingTableRule
(
orderTableRule
,
orderItemTableRule
))
.
defaultDatabaseShardingStrategy
(
new
InlineShardingStrategy
(
"user_id"
,
"ds_jdbc_${user_id % 2}"
))
.
defaultDatabaseShardingStrategy
(
new
InlineShardingStrategy
(
"user_id"
,
"ds_jdbc_${user_id % 2}"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录