Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
01e0ba08
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,发现更多精彩内容 >>
提交
01e0ba08
编写于
9月 07, 2017
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor ShardingStrategy: auto merge in, split range strategy 10th version
上级
7e20c8e1
变更
51
显示空白变更内容
内联
并排
Showing
51 changed file
with
282 addition
and
152 deletion
+282
-152
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/main/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/algorithm/ClosureShardingAlgorithm.java
...g/common/internal/algorithm/ClosureShardingAlgorithm.java
+6
-4
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/algorithm/AbstractClosureShardingAlgorithmTest.java
...ernal/algorithm/AbstractClosureShardingAlgorithmTest.java
+6
-4
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/fixture/MultiAlgorithm.java
...arding/config/common/internal/fixture/MultiAlgorithm.java
+2
-2
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/fixture/SingleAlgorithm.java
...rding/config/common/internal/fixture/SingleAlgorithm.java
+2
-1
sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
...g/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
+2
-1
sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/algorithm/SingleKeyModuloTableShardingAlgorithm.java
...ring/algorithm/SingleKeyModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-config-parent/sharding-jdbc-config-yaml/src/test/java/com/dangdang/ddframe/rdb/sharding/config/yaml/algorithm/MultiAlgorithm.java
...me/rdb/sharding/config/yaml/algorithm/MultiAlgorithm.java
+2
-2
sharding-jdbc-config-parent/sharding-jdbc-config-yaml/src/test/java/com/dangdang/ddframe/rdb/sharding/config/yaml/algorithm/SingleAlgorithm.java
...e/rdb/sharding/config/yaml/algorithm/SingleAlgorithm.java
+2
-1
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/BaseShardingValue.java
.../dangdang/ddframe/rdb/sharding/api/BaseShardingValue.java
+47
-0
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/HintManager.java
...va/com/dangdang/ddframe/rdb/sharding/api/HintManager.java
+6
-6
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/RangeShardingValue.java
...dangdang/ddframe/rdb/sharding/api/RangeShardingValue.java
+45
-0
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/ShardingValue.java
.../com/dangdang/ddframe/rdb/sharding/api/ShardingValue.java
+4
-15
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/database/NoneDatabaseShardingAlgorithm.java
.../api/strategy/database/NoneDatabaseShardingAlgorithm.java
+4
-2
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/table/NoneTableShardingAlgorithm.java
...arding/api/strategy/table/NoneTableShardingAlgorithm.java
+4
-2
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/hint/HintManagerHolder.java
...dangdang/ddframe/rdb/sharding/hint/HintManagerHolder.java
+5
-5
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/context/condition/Condition.java
.../sharding/parsing/parser/context/condition/Condition.java
+5
-3
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/MultipleKeysShardingAlgorithm.java
...rding/routing/strategy/MultipleKeysShardingAlgorithm.java
+2
-2
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/NoneKeyShardingAlgorithm.java
...b/sharding/routing/strategy/NoneKeyShardingAlgorithm.java
+2
-2
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/ShardingStrategy.java
...frame/rdb/sharding/routing/strategy/ShardingStrategy.java
+7
-5
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/SingleKeyShardingAlgorithm.java
...sharding/routing/strategy/SingleKeyShardingAlgorithm.java
+2
-1
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/type/hint/DatabaseHintRoutingEngine.java
...sharding/routing/type/hint/DatabaseHintRoutingEngine.java
+3
-3
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/type/simple/SimpleRoutingEngine.java
...rdb/sharding/routing/type/simple/SimpleRoutingEngine.java
+18
-17
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/MultipleKeysModuloDatabaseShardingAlgorithm.java
.../fixture/MultipleKeysModuloDatabaseShardingAlgorithm.java
+6
-4
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/NoneKeyModuloDatabaseShardingAlgorithm.java
...grate/fixture/NoneKeyModuloDatabaseShardingAlgorithm.java
+3
-2
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/SingleKeyDynamicModuloTableShardingAlgorithm.java
...fixture/SingleKeyDynamicModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/SingleKeyModuloDatabaseShardingAlgorithm.java
...ate/fixture/SingleKeyModuloDatabaseShardingAlgorithm.java
+5
-4
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/SingleKeyModuloTableShardingAlgorithm.java
...egrate/fixture/SingleKeyModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/HintManagerTest.java
...om/dangdang/ddframe/rdb/sharding/api/HintManagerTest.java
+9
-9
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/ShardingValueTest.java
.../dangdang/ddframe/rdb/sharding/api/ShardingValueTest.java
+5
-5
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/strategy/common/ShardingStrategyTest.java
...db/sharding/api/strategy/common/ShardingStrategyTest.java
+8
-6
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/strategy/fixture/TestMultipleKeysShardingAlgorithm.java
...i/strategy/fixture/TestMultipleKeysShardingAlgorithm.java
+2
-2
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/strategy/fixture/TestSingleKeyShardingAlgorithm.java
.../api/strategy/fixture/TestSingleKeyShardingAlgorithm.java
+2
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/context/condition/ConditionTest.java
...rding/parsing/parser/context/condition/ConditionTest.java
+7
-5
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/sql/DeleteStatementParserTest.java
...harding/parsing/parser/sql/DeleteStatementParserTest.java
+9
-7
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/sql/InsertStatementParserTest.java
...harding/parsing/parser/sql/InsertStatementParserTest.java
+4
-3
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/sql/UpdateStatementParserTest.java
...harding/parsing/parser/sql/UpdateStatementParserTest.java
+9
-7
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/routing/fixture/OrderAttrShardingAlgorithm.java
.../sharding/routing/fixture/OrderAttrShardingAlgorithm.java
+2
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/routing/fixture/OrderDatabaseShardingAlgorithm.java
...rding/routing/fixture/OrderDatabaseShardingAlgorithm.java
+3
-2
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/routing/fixture/OrderShardingAlgorithm.java
.../rdb/sharding/routing/fixture/OrderShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-config-spring-masterslave/src/main/java/com/dangdang/ddframe/rdb/sharding/example/config/spring/masterslave/algorithm/SingleKeyModuloTableShardingAlgorithm.java
...lave/algorithm/SingleKeyModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-config-spring/src/main/java/com/dangdang/ddframe/rdb/sharding/example/config/spring/algorithm/SingleKeyModuloTableShardingAlgorithm.java
...ring/algorithm/SingleKeyModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jdbc-masterslave/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/masterslave/algorithm/ModuloDatabaseShardingAlgorithm.java
...asterslave/algorithm/ModuloDatabaseShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jdbc-masterslave/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/masterslave/algorithm/ModuloTableShardingAlgorithm.java
...c/masterslave/algorithm/ModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jdbc-transaction/src/main/java/com/dangdang/ddframe/rdb/sharding/example/transaction/algorithm/ModuloDatabaseShardingAlgorithm.java
...ransaction/algorithm/ModuloDatabaseShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jdbc-transaction/src/main/java/com/dangdang/ddframe/rdb/sharding/example/transaction/algorithm/ModuloTableShardingAlgorithm.java
...e/transaction/algorithm/ModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jdbc/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/ModuloDatabaseShardingAlgorithm.java
...ample/jdbc/algorithm/ModuloDatabaseShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jdbc/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/ModuloTableShardingAlgorithm.java
.../example/jdbc/algorithm/ModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jpa/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jpa/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
...a/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-jpa/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jpa/algorithm/SingleKeyModuloTableShardingAlgorithm.java
.../jpa/algorithm/SingleKeyModuloTableShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-mybatis/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
...c/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
+2
-1
sharding-jdbc-example/sharding-jdbc-example-mybatis/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/SingleKeyModuloTableShardingAlgorithm.java
...jdbc/algorithm/SingleKeyModuloTableShardingAlgorithm.java
+2
-1
未找到文件。
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/main/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/algorithm/ClosureShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.routing.strategy.MultipleKeysShardingAlgorithm
;
import
com.google.common.base.Joiner
;
...
...
@@ -51,18 +52,19 @@ public class ClosureShardingAlgorithm implements MultipleKeysShardingAlgorithm {
closureTemplate
=
(
Closure
)
new
GroovyShell
(
binding
).
evaluate
(
Joiner
.
on
(
""
).
join
(
"{it -> \""
,
expression
.
trim
(),
"\"}"
));
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
List
<
Set
<
Comparable
>>
valuesDim
=
new
ArrayList
<>();
List
<
String
>
columnNames
=
new
ArrayList
<>(
shardingValues
.
size
());
for
(
ShardingValue
<?>
each
:
shardingValues
)
{
for
(
Base
ShardingValue
<?>
each
:
shardingValues
)
{
columnNames
.
add
(
each
.
getColumnName
());
switch
(
each
.
getType
())
{
case
SINGLE:
valuesDim
.
add
(
Sets
.
newHashSet
((
Comparable
)
each
.
getValue
()));
valuesDim
.
add
(
Sets
.
newHashSet
((
Comparable
)
((
ShardingValue
)
each
)
.
getValue
()));
break
;
case
LIST:
valuesDim
.
add
(
Sets
.<
Comparable
>
newHashSet
(
each
.
getValues
()));
valuesDim
.
add
(
Sets
.<
Comparable
>
newHashSet
(
((
ShardingValue
)
each
)
.
getValues
()));
break
;
case
RANGE:
throw
new
UnsupportedOperationException
(
"Inline expression does not support BETWEEN, please use Java API Config"
);
...
...
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/algorithm/AbstractClosureShardingAlgorithmTest.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.config.common.internal.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.google.common.collect.BoundType
;
import
com.google.common.collect.Range
;
...
...
@@ -46,7 +48,7 @@ public abstract class AbstractClosureShardingAlgorithmTest {
@Test
public
void
assertEqual
()
{
Collection
<
String
>
result
=
createClosureShardingAlgorithm
().
doSharding
(
Collections
.
singletonList
(
"target_1"
),
Collections
.<
ShardingValue
>
singletonList
(
new
ShardingValue
<>(
"target"
,
"id"
,
1L
)));
Collections
.
singletonList
(
"target_1"
),
Collections
.<
Base
ShardingValue
>
singletonList
(
new
ShardingValue
<>(
"target"
,
"id"
,
1L
)));
assertThat
(
result
.
size
(),
is
(
1
));
assertThat
(
result
,
hasItem
(
"target_1"
));
}
...
...
@@ -54,7 +56,7 @@ public abstract class AbstractClosureShardingAlgorithmTest {
@Test
public
void
assertIn
()
{
Collection
<
String
>
result
=
createClosureShardingAlgorithm
().
doSharding
(
Arrays
.
asList
(
"target_0"
,
"target_1"
),
Collections
.<
ShardingValue
>
singletonList
(
new
ShardingValue
<>(
"target"
,
"id"
,
Arrays
.
asList
(
1
,
2
))));
Collections
.<
Base
ShardingValue
>
singletonList
(
new
ShardingValue
<>(
"target"
,
"id"
,
Arrays
.
asList
(
1
,
2
))));
assertThat
(
result
.
size
(),
is
(
2
));
assertThat
(
result
,
hasItem
(
"target_0"
));
assertThat
(
result
,
hasItem
(
"target_1"
));
...
...
@@ -63,11 +65,11 @@ public abstract class AbstractClosureShardingAlgorithmTest {
@Test
(
expected
=
UnsupportedOperationException
.
class
)
public
void
assertBetween
()
{
createClosureShardingAlgorithm
().
doSharding
(
Arrays
.
asList
(
"target_0"
,
"target_1"
),
Collections
.<
ShardingValue
>
singletonList
(
new
ShardingValue
<>(
"target"
,
"id"
,
Range
.
range
(
1
,
BoundType
.
CLOSED
,
2
,
BoundType
.
OPEN
))));
Collections
.<
BaseShardingValue
>
singletonList
(
new
Range
ShardingValue
<>(
"target"
,
"id"
,
Range
.
range
(
1
,
BoundType
.
CLOSED
,
2
,
BoundType
.
OPEN
))));
}
@Test
(
expected
=
MissingMethodException
.
class
)
public
void
assertEvaluateInlineExpressionFailure
()
{
createErrorClosureShardingAlgorithm
().
doSharding
(
Collections
.
singletonList
(
"target_1"
),
Collections
.<
ShardingValue
>
singletonList
(
new
ShardingValue
<>(
"target"
,
"id"
,
1L
)));
createErrorClosureShardingAlgorithm
().
doSharding
(
Collections
.
singletonList
(
"target_1"
),
Collections
.<
Base
ShardingValue
>
singletonList
(
new
ShardingValue
<>(
"target"
,
"id"
,
1L
)));
}
}
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/fixture/MultiAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,7 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.config.common.internal.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.
Base
ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.MultipleKeysTableShardingAlgorithm
;
import
java.util.Collection
;
...
...
@@ -25,7 +25,7 @@ import java.util.Collection;
public
class
MultiAlgorithm
implements
MultipleKeysTableShardingAlgorithm
{
@Override
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
return
null
;
}
}
sharding-jdbc-config-parent/sharding-jdbc-config-common/src/test/java/com/dangdang/ddframe/rdb/sharding/config/common/internal/fixture/SingleAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.config.common.internal.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
...
...
@@ -30,7 +31,7 @@ public class SingleAlgorithm implements SingleKeyDatabaseShardingAlgorithm {
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
availableTargetNames
,
final
ShardingValue
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
availableTargetNames
,
final
Range
ShardingValue
shardingValue
)
{
return
null
;
}
}
sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.spring.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public class SingleKeyModuloDatabaseShardingAlgorithm implements SingleKeyDataba
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/algorithm/SingleKeyModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.spring.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public class SingleKeyModuloTableShardingAlgorithm implements SingleKeyTableShar
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-config-parent/sharding-jdbc-config-yaml/src/test/java/com/dangdang/ddframe/rdb/sharding/config/yaml/algorithm/MultiAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,7 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.config.yaml.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.
Base
ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.MultipleKeysTableShardingAlgorithm
;
import
java.util.Collection
;
...
...
@@ -25,7 +25,7 @@ import java.util.Collection;
public
class
MultiAlgorithm
implements
MultipleKeysTableShardingAlgorithm
{
@Override
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
return
null
;
}
}
sharding-jdbc-config-parent/sharding-jdbc-config-yaml/src/test/java/com/dangdang/ddframe/rdb/sharding/config/yaml/algorithm/SingleAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.config.yaml.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
...
...
@@ -30,7 +31,7 @@ public class SingleAlgorithm implements SingleKeyDatabaseShardingAlgorithm {
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
availableTargetNames
,
final
ShardingValue
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
availableTargetNames
,
final
Range
ShardingValue
shardingValue
)
{
return
null
;
}
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/BaseShardingValue.java
0 → 100644
浏览文件 @
01e0ba08
/*
* 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.api
;
/**
* Sharding value interface.
*
* @author zhangliang
*/
public
interface
BaseShardingValue
<
T
extends
Comparable
<?>>
{
/**
* Get logic table name.
*
* @return logic table name
*/
String
getLogicTableName
();
/**
* Get column name.
*
* @return column name
*/
String
getColumnName
();
/**
* Get sharding value type.
*
* @return sharding value type
*/
ShardingValue
.
ShardingValueType
getType
();
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/HintManager.java
浏览文件 @
01e0ba08
...
...
@@ -40,9 +40,9 @@ import java.util.Map;
@NoArgsConstructor
(
access
=
AccessLevel
.
PRIVATE
)
public
final
class
HintManager
implements
AutoCloseable
{
private
final
Map
<
ShardingKey
,
ShardingValue
<?>
>
databaseShardingValues
=
new
HashMap
<>();
private
final
Map
<
ShardingKey
,
BaseShardingValue
>
databaseShardingValues
=
new
HashMap
<>();
private
final
Map
<
ShardingKey
,
ShardingValue
<?>
>
tableShardingValues
=
new
HashMap
<>();
private
final
Map
<
ShardingKey
,
BaseShardingValue
>
tableShardingValues
=
new
HashMap
<>();
@Getter
private
boolean
shardingHint
;
...
...
@@ -129,7 +129,7 @@ public final class HintManager implements AutoCloseable {
}
@SuppressWarnings
(
"unchecked"
)
private
ShardingValue
getShardingValue
(
final
String
logicTable
,
final
String
shardingColumn
,
final
ShardingOperator
operator
,
final
Comparable
<?>[]
values
)
{
private
Base
ShardingValue
getShardingValue
(
final
String
logicTable
,
final
String
shardingColumn
,
final
ShardingOperator
operator
,
final
Comparable
<?>[]
values
)
{
Preconditions
.
checkArgument
(
null
!=
values
&&
values
.
length
>
0
);
switch
(
operator
)
{
case
EQUAL:
...
...
@@ -137,7 +137,7 @@ public final class HintManager implements AutoCloseable {
case
IN:
return
new
ShardingValue
(
logicTable
,
shardingColumn
,
Arrays
.
asList
(
values
));
case
BETWEEN:
return
new
ShardingValue
(
logicTable
,
shardingColumn
,
Range
.
range
(
values
[
0
],
BoundType
.
CLOSED
,
values
[
1
],
BoundType
.
CLOSED
));
return
new
Range
ShardingValue
(
logicTable
,
shardingColumn
,
Range
.
range
(
values
[
0
],
BoundType
.
CLOSED
,
values
[
1
],
BoundType
.
CLOSED
));
default
:
throw
new
UnsupportedOperationException
(
operator
.
getExpression
());
}
...
...
@@ -149,7 +149,7 @@ public final class HintManager implements AutoCloseable {
* @param shardingKey sharding key
* @return sharding value for database
*/
public
ShardingValue
<?>
getDatabaseShardingValue
(
final
ShardingKey
shardingKey
)
{
public
BaseShardingValue
getDatabaseShardingValue
(
final
ShardingKey
shardingKey
)
{
return
databaseShardingValues
.
get
(
shardingKey
);
}
...
...
@@ -159,7 +159,7 @@ public final class HintManager implements AutoCloseable {
* @param shardingKey sharding key
* @return sharding value for table
*/
public
ShardingValue
<?>
getTableShardingValue
(
final
ShardingKey
shardingKey
)
{
public
BaseShardingValue
getTableShardingValue
(
final
ShardingKey
shardingKey
)
{
return
tableShardingValues
.
get
(
shardingKey
);
}
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/RangeShardingValue.java
0 → 100644
浏览文件 @
01e0ba08
/*
* 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.api
;
import
com.google.common.collect.Range
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.ToString
;
/**
* Sharding value for range.
*
* @author zhangliang
*/
@RequiredArgsConstructor
@Getter
@ToString
public
final
class
RangeShardingValue
<
T
extends
Comparable
<?>>
implements
BaseShardingValue
{
private
final
String
logicTableName
;
private
final
String
columnName
;
private
final
Range
<
T
>
valueRange
;
@Override
public
ShardingValue
.
ShardingValueType
getType
()
{
return
ShardingValue
.
ShardingValueType
.
RANGE
;
}
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/ShardingValue.java
浏览文件 @
01e0ba08
...
...
@@ -17,7 +17,6 @@
package
com.dangdang.ddframe.rdb.sharding.api
;
import
com.google.common.collect.Range
;
import
lombok.AccessLevel
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
...
...
@@ -39,7 +38,7 @@ import java.util.Collections;
@AllArgsConstructor
(
access
=
AccessLevel
.
PRIVATE
)
@Getter
@ToString
public
final
class
ShardingValue
<
T
extends
Comparable
<?>>
{
public
final
class
ShardingValue
<
T
extends
Comparable
<?>>
implements
BaseShardingValue
{
private
final
String
logicTableName
;
...
...
@@ -49,25 +48,15 @@ public final class ShardingValue<T extends Comparable<?>> {
private
final
Collection
<
T
>
values
;
private
final
Range
<
T
>
valueRange
;
public
ShardingValue
(
final
String
logicTableName
,
final
String
columnName
,
final
T
value
)
{
this
(
logicTableName
,
columnName
,
value
,
Collections
.<
T
>
emptyList
()
,
null
);
this
(
logicTableName
,
columnName
,
value
,
Collections
.<
T
>
emptyList
());
}
public
ShardingValue
(
final
String
logicTableName
,
final
String
columnName
,
final
Collection
<
T
>
values
)
{
this
(
logicTableName
,
columnName
,
null
,
values
,
null
);
}
public
ShardingValue
(
final
String
logicTableName
,
final
String
columnName
,
final
Range
<
T
>
valueRange
)
{
this
(
logicTableName
,
columnName
,
null
,
Collections
.<
T
>
emptyList
(),
valueRange
);
this
(
logicTableName
,
columnName
,
null
,
values
);
}
/**
* Get sharding value type.
*
* @return sharding value type
*/
@Override
public
ShardingValueType
getType
()
{
if
(
null
!=
value
)
{
return
ShardingValueType
.
SINGLE
;
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/database/NoneDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.api.strategy.database
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
java.util.Collection
;
...
...
@@ -29,7 +31,7 @@ import java.util.Collection;
public
final
class
NoneDatabaseShardingAlgorithm
implements
SingleKeyDatabaseShardingAlgorithm
<
String
>,
MultipleKeysDatabaseShardingAlgorithm
{
@Override
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
return
availableTargetNames
;
}
...
...
@@ -39,7 +41,7 @@ public final class NoneDatabaseShardingAlgorithm implements SingleKeyDatabaseSha
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
String
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
String
>
shardingValue
)
{
return
availableTargetNames
;
}
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/table/NoneTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.api.strategy.table
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
java.util.Collection
;
...
...
@@ -29,7 +31,7 @@ import java.util.Collection;
public
final
class
NoneTableShardingAlgorithm
implements
SingleKeyTableShardingAlgorithm
<
String
>,
MultipleKeysTableShardingAlgorithm
{
@Override
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTableNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTableNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
return
availableTableNames
;
}
...
...
@@ -39,7 +41,7 @@ public final class NoneTableShardingAlgorithm implements SingleKeyTableShardingA
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
String
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
String
>
shardingValue
)
{
return
availableTargetNames
;
}
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/hint/HintManagerHolder.java
浏览文件 @
01e0ba08
...
...
@@ -17,8 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.hint
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.HintManager
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.google.common.base.Optional
;
import
com.google.common.base.Preconditions
;
import
lombok.AccessLevel
;
...
...
@@ -64,8 +64,8 @@ public final class HintManagerHolder {
* @param shardingKey sharding key
* @return database sharding value
*/
public
static
Optional
<
ShardingValue
<?>
>
getDatabaseShardingValue
(
final
ShardingKey
shardingKey
)
{
return
isUseShardingHint
()
?
Optional
.
<
ShardingValue
<?>>
fromNullable
(
HINT_MANAGER_HOLDER
.
get
().
getDatabaseShardingValue
(
shardingKey
))
:
Optional
.<
ShardingValue
<?>
>
absent
();
public
static
Optional
<
BaseShardingValue
>
getDatabaseShardingValue
(
final
ShardingKey
shardingKey
)
{
return
isUseShardingHint
()
?
Optional
.
fromNullable
(
HINT_MANAGER_HOLDER
.
get
().
getDatabaseShardingValue
(
shardingKey
))
:
Optional
.<
BaseShardingValue
>
absent
();
}
/**
...
...
@@ -74,8 +74,8 @@ public final class HintManagerHolder {
* @param shardingKey sharding key
* @return table sharding value
*/
public
static
Optional
<
ShardingValue
<?>
>
getTableShardingValue
(
final
ShardingKey
shardingKey
)
{
return
isUseShardingHint
()
?
Optional
.
<
ShardingValue
<?>>
fromNullable
(
HINT_MANAGER_HOLDER
.
get
().
getTableShardingValue
(
shardingKey
))
:
Optional
.<
ShardingValue
<?>
>
absent
();
public
static
Optional
<
BaseShardingValue
>
getTableShardingValue
(
final
ShardingKey
shardingKey
)
{
return
isUseShardingHint
()
?
Optional
.
fromNullable
(
HINT_MANAGER_HOLDER
.
get
().
getTableShardingValue
(
shardingKey
))
:
Optional
.<
BaseShardingValue
>
absent
();
}
/**
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/context/condition/Condition.java
浏览文件 @
01e0ba08
package
com.dangdang.ddframe.rdb.sharding.parsing.parser.context.condition
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.constant.ShardingOperator
;
import
com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException
;
...
...
@@ -11,9 +13,9 @@ import com.google.common.collect.BoundType;
import
com.google.common.collect.Range
;
import
lombok.AccessLevel
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.ToString
;
import
lombok.Getter
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
...
...
@@ -77,7 +79,7 @@ public final class Condition {
* @param parameters parameters
* @return sharding value
*/
public
ShardingValue
<?>
getShardingValue
(
final
List
<
Object
>
parameters
)
{
public
BaseShardingValue
getShardingValue
(
final
List
<
Object
>
parameters
)
{
List
<
Comparable
<?>>
conditionValues
=
getValues
(
parameters
);
switch
(
operator
)
{
case
EQUAL:
...
...
@@ -85,7 +87,7 @@ public final class Condition {
case
IN:
return
new
ShardingValue
<>(
column
.
getTableName
(),
column
.
getName
(),
conditionValues
);
case
BETWEEN:
return
new
ShardingValue
<>(
column
.
getTableName
(),
column
.
getName
(),
Range
.
range
(
conditionValues
.
get
(
0
),
BoundType
.
CLOSED
,
conditionValues
.
get
(
1
),
BoundType
.
CLOSED
));
return
new
Range
ShardingValue
<>(
column
.
getTableName
(),
column
.
getName
(),
Range
.
range
(
conditionValues
.
get
(
0
),
BoundType
.
CLOSED
,
conditionValues
.
get
(
1
),
BoundType
.
CLOSED
));
default
:
throw
new
UnsupportedOperationException
(
operator
.
getExpression
());
}
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/MultipleKeysShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,7 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.strategy
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.
Base
ShardingValue
;
import
java.util.Collection
;
...
...
@@ -35,5 +35,5 @@ public interface MultipleKeysShardingAlgorithm extends ShardingAlgorithm {
* @param shardingValues sharding values
* @return sharding results for data sources or tables's names
*/
Collection
<
String
>
doSharding
(
Collection
<
String
>
availableTargetNames
,
Collection
<
ShardingValue
>
shardingValues
);
Collection
<
String
>
doSharding
(
Collection
<
String
>
availableTargetNames
,
Collection
<
Base
ShardingValue
>
shardingValues
);
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/NoneKeyShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,7 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.strategy
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.
Base
ShardingValue
;
import
java.util.Collection
;
...
...
@@ -38,5 +38,5 @@ public interface NoneKeyShardingAlgorithm<T extends Comparable<?>> extends Shard
* @param shardingValue sharding values
* @return sharding results for data sources or tables's names
*/
String
doSharding
(
Collection
<
String
>
availableTargetNames
,
ShardingValue
<
T
>
shardingValue
);
String
doSharding
(
Collection
<
String
>
availableTargetNames
,
Base
ShardingValue
<
T
>
shardingValue
);
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/ShardingStrategy.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.routing.strategy
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.google.common.base.Preconditions
;
import
lombok.Getter
;
...
...
@@ -71,7 +73,7 @@ public class ShardingStrategy {
* @param shardingValues sharding values
* @return sharding results for data sources or tables's names
*/
public
Collection
<
String
>
doStaticSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doStaticSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
Collection
<
String
>
result
=
new
TreeSet
<>(
String
.
CASE_INSENSITIVE_ORDER
);
if
(
shardingValues
.
isEmpty
())
{
result
.
addAll
(
availableTargetNames
);
...
...
@@ -87,7 +89,7 @@ public class ShardingStrategy {
* @param shardingValues sharding values
* @return sharding results for data sources or tables's names
*/
public
Collection
<
String
>
doDynamicSharding
(
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doDynamicSharding
(
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
Preconditions
.
checkState
(!
shardingValues
.
isEmpty
(),
"Dynamic table should contain sharding value."
);
Collection
<
String
>
availableTargetNames
=
Collections
.
emptyList
();
Collection
<
String
>
result
=
new
TreeSet
<>(
String
.
CASE_INSENSITIVE_ORDER
);
...
...
@@ -96,16 +98,16 @@ public class ShardingStrategy {
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
private
Collection
<
String
>
doSharding
(
final
Collection
<
ShardingValue
>
shardingValues
,
final
Collection
<
String
>
availableTargetNames
)
{
private
Collection
<
String
>
doSharding
(
final
Collection
<
Base
ShardingValue
>
shardingValues
,
final
Collection
<
String
>
availableTargetNames
)
{
if
(
shardingAlgorithm
instanceof
NoneKeyShardingAlgorithm
)
{
return
Collections
.
singletonList
(((
NoneKeyShardingAlgorithm
)
shardingAlgorithm
).
doSharding
(
availableTargetNames
,
shardingValues
.
iterator
().
next
()));
}
if
(
shardingAlgorithm
instanceof
SingleKeyShardingAlgorithm
)
{
SingleKeyShardingAlgorithm
<?>
singleKeyShardingAlgorithm
=
(
SingleKeyShardingAlgorithm
<?>)
shardingAlgorithm
;
ShardingValue
shardingValue
=
shardingValues
.
iterator
().
next
();
Base
ShardingValue
shardingValue
=
shardingValues
.
iterator
().
next
();
switch
(
shardingValue
.
getType
())
{
case
RANGE:
return
singleKeyShardingAlgorithm
.
doBetweenSharding
(
availableTargetNames
,
shardingValue
);
return
singleKeyShardingAlgorithm
.
doBetweenSharding
(
availableTargetNames
,
(
RangeShardingValue
)
shardingValue
);
default
:
throw
new
UnsupportedOperationException
(
shardingValue
.
getType
().
getClass
().
getName
());
}
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/strategy/SingleKeyShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.strategy
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
java.util.Collection
;
...
...
@@ -46,5 +47,5 @@ public interface SingleKeyShardingAlgorithm<T extends Comparable<?>> extends Sha
* @param shardingValue sharding value
* @return sharding results for data sources or tables's names
*/
Collection
<
String
>
doBetweenSharding
(
Collection
<
String
>
availableTargetNames
,
ShardingValue
<
T
>
shardingValue
);
Collection
<
String
>
doBetweenSharding
(
Collection
<
String
>
availableTargetNames
,
Range
ShardingValue
<
T
>
shardingValue
);
}
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/type/hint/DatabaseHintRoutingEngine.java
浏览文件 @
01e0ba08
...
...
@@ -17,7 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.type.hint
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.
Base
ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy
;
import
com.dangdang.ddframe.rdb.sharding.hint.HintManagerHolder
;
...
...
@@ -49,10 +49,10 @@ public final class DatabaseHintRoutingEngine implements RoutingEngine {
@Override
public
RoutingResult
route
()
{
Optional
<
ShardingValue
<?>
>
shardingValue
=
HintManagerHolder
.
getDatabaseShardingValue
(
new
ShardingKey
(
HintManagerHolder
.
DB_TABLE_NAME
,
HintManagerHolder
.
DB_COLUMN_NAME
));
Optional
<
BaseShardingValue
>
shardingValue
=
HintManagerHolder
.
getDatabaseShardingValue
(
new
ShardingKey
(
HintManagerHolder
.
DB_TABLE_NAME
,
HintManagerHolder
.
DB_COLUMN_NAME
));
Preconditions
.
checkState
(
shardingValue
.
isPresent
());
log
.
debug
(
"Before database sharding only db:{} sharding values: {}"
,
dataSourceRule
.
getDataSourceNames
(),
shardingValue
.
get
());
Collection
<
String
>
routingDataSources
=
databaseShardingStrategy
.
doStaticSharding
(
dataSourceRule
.
getDataSourceNames
(),
Collections
.
<
ShardingValue
>
singleton
(
shardingValue
.
get
()));
Collection
<
String
>
routingDataSources
=
databaseShardingStrategy
.
doStaticSharding
(
dataSourceRule
.
getDataSourceNames
(),
Collections
.
singleton
(
shardingValue
.
get
()));
Preconditions
.
checkState
(!
routingDataSources
.
isEmpty
(),
"no database route info"
);
log
.
debug
(
"After database sharding only result: {}"
,
routingDataSources
);
RoutingResult
result
=
new
RoutingResult
();
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/type/simple/SimpleRoutingEngine.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.type.simple
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.DataNode
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule
;
...
...
@@ -66,8 +67,8 @@ public final class SimpleRoutingEngine implements RoutingEngine {
@Override
public
RoutingResult
route
()
{
TableRule
tableRule
=
shardingRule
.
getTableRule
(
logicTableName
);
List
<
ShardingValue
>
databaseShardingValues
=
getDatabaseShardingValues
(
tableRule
);
List
<
ShardingValue
>
tableShardingValues
=
getTableShardingValues
(
tableRule
);
List
<
Base
ShardingValue
>
databaseShardingValues
=
getDatabaseShardingValues
(
tableRule
);
List
<
Base
ShardingValue
>
tableShardingValues
=
getTableShardingValues
(
tableRule
);
Collection
<
String
>
routedDataSources
=
routeDataSources
(
tableRule
,
databaseShardingValues
);
Map
<
String
,
Collection
<
String
>>
routedMap
=
new
LinkedHashMap
<>(
routedDataSources
.
size
());
for
(
String
each
:
routedDataSources
)
{
...
...
@@ -76,20 +77,20 @@ public final class SimpleRoutingEngine implements RoutingEngine {
return
generateRoutingResult
(
tableRule
,
routedMap
);
}
private
List
<
ShardingValue
>
getDatabaseShardingValues
(
final
TableRule
tableRule
)
{
private
List
<
Base
ShardingValue
>
getDatabaseShardingValues
(
final
TableRule
tableRule
)
{
DatabaseShardingStrategy
strategy
=
shardingRule
.
getDatabaseShardingStrategy
(
tableRule
);
return
HintManagerHolder
.
isUseShardingHint
()
?
getDatabaseShardingValuesFromHint
(
strategy
.
getShardingColumns
())
:
getShardingValues
(
strategy
.
getShardingColumns
());
}
private
List
<
ShardingValue
>
getTableShardingValues
(
final
TableRule
tableRule
)
{
private
List
<
Base
ShardingValue
>
getTableShardingValues
(
final
TableRule
tableRule
)
{
TableShardingStrategy
strategy
=
shardingRule
.
getTableShardingStrategy
(
tableRule
);
return
HintManagerHolder
.
isUseShardingHint
()
?
getTableShardingValuesFromHint
(
strategy
.
getShardingColumns
())
:
getShardingValues
(
strategy
.
getShardingColumns
());
}
private
List
<
ShardingValue
>
getDatabaseShardingValuesFromHint
(
final
Collection
<
String
>
shardingColumns
)
{
List
<
ShardingValue
>
result
=
new
ArrayList
<>(
shardingColumns
.
size
());
private
List
<
Base
ShardingValue
>
getDatabaseShardingValuesFromHint
(
final
Collection
<
String
>
shardingColumns
)
{
List
<
Base
ShardingValue
>
result
=
new
ArrayList
<>(
shardingColumns
.
size
());
for
(
String
each
:
shardingColumns
)
{
Optional
<
ShardingValue
<?>
>
shardingValue
=
HintManagerHolder
.
getDatabaseShardingValue
(
new
ShardingKey
(
logicTableName
,
each
));
Optional
<
BaseShardingValue
>
shardingValue
=
HintManagerHolder
.
getDatabaseShardingValue
(
new
ShardingKey
(
logicTableName
,
each
));
if
(
shardingValue
.
isPresent
())
{
result
.
add
(
shardingValue
.
get
());
}
...
...
@@ -97,10 +98,10 @@ public final class SimpleRoutingEngine implements RoutingEngine {
return
result
;
}
private
List
<
ShardingValue
>
getTableShardingValuesFromHint
(
final
Collection
<
String
>
shardingColumns
)
{
List
<
ShardingValue
>
result
=
new
ArrayList
<>(
shardingColumns
.
size
());
private
List
<
Base
ShardingValue
>
getTableShardingValuesFromHint
(
final
Collection
<
String
>
shardingColumns
)
{
List
<
Base
ShardingValue
>
result
=
new
ArrayList
<>(
shardingColumns
.
size
());
for
(
String
each
:
shardingColumns
)
{
Optional
<
ShardingValue
<?>
>
shardingValue
=
HintManagerHolder
.
getTableShardingValue
(
new
ShardingKey
(
logicTableName
,
each
));
Optional
<
BaseShardingValue
>
shardingValue
=
HintManagerHolder
.
getTableShardingValue
(
new
ShardingKey
(
logicTableName
,
each
));
if
(
shardingValue
.
isPresent
())
{
result
.
add
(
shardingValue
.
get
());
}
...
...
@@ -108,8 +109,8 @@ public final class SimpleRoutingEngine implements RoutingEngine {
return
result
;
}
private
List
<
ShardingValue
>
getShardingValues
(
final
Collection
<
String
>
shardingColumns
)
{
List
<
ShardingValue
>
result
=
new
ArrayList
<>(
shardingColumns
.
size
());
private
List
<
Base
ShardingValue
>
getShardingValues
(
final
Collection
<
String
>
shardingColumns
)
{
List
<
Base
ShardingValue
>
result
=
new
ArrayList
<>(
shardingColumns
.
size
());
for
(
String
each
:
shardingColumns
)
{
Optional
<
Condition
>
condition
=
sqlStatement
.
getConditions
().
find
(
new
Column
(
each
,
logicTableName
));
if
(
condition
.
isPresent
())
{
...
...
@@ -119,11 +120,11 @@ public final class SimpleRoutingEngine implements RoutingEngine {
return
result
;
}
private
Collection
<
String
>
routeDataSources
(
final
TableRule
tableRule
,
final
List
<
ShardingValue
>
databaseShardingValues
)
{
private
Collection
<
String
>
routeDataSources
(
final
TableRule
tableRule
,
final
List
<
Base
ShardingValue
>
databaseShardingValues
)
{
DatabaseShardingStrategy
strategy
=
shardingRule
.
getDatabaseShardingStrategy
(
tableRule
);
if
(
isAccurateSharding
(
databaseShardingValues
,
strategy
))
{
Collection
<
String
>
result
=
new
LinkedList
<>();
Collection
<
ShardingValue
>
accurateDatabaseShardingValues
=
transferToShardingValues
(
databaseShardingValues
.
get
(
0
));
Collection
<
ShardingValue
>
accurateDatabaseShardingValues
=
transferToShardingValues
(
(
ShardingValue
<?>)
databaseShardingValues
.
get
(
0
));
for
(
ShardingValue
<?>
eachDatabaseShardingValue
:
accurateDatabaseShardingValues
)
{
result
.
add
(
strategy
.
doAccurateSharding
(
tableRule
.
getActualDatasourceNames
(),
eachDatabaseShardingValue
));
}
...
...
@@ -134,11 +135,11 @@ public final class SimpleRoutingEngine implements RoutingEngine {
return
result
;
}
private
Collection
<
String
>
routeTables
(
final
TableRule
tableRule
,
final
String
routedDataSource
,
final
List
<
ShardingValue
>
tableShardingValues
)
{
private
Collection
<
String
>
routeTables
(
final
TableRule
tableRule
,
final
String
routedDataSource
,
final
List
<
Base
ShardingValue
>
tableShardingValues
)
{
TableShardingStrategy
strategy
=
shardingRule
.
getTableShardingStrategy
(
tableRule
);
if
(
isAccurateSharding
(
tableShardingValues
,
strategy
))
{
Collection
<
String
>
result
=
new
HashSet
<>();
Collection
<
ShardingValue
>
accurateTableShardingValues
=
transferToShardingValues
(
tableShardingValues
.
get
(
0
));
Collection
<
ShardingValue
>
accurateTableShardingValues
=
transferToShardingValues
(
(
ShardingValue
<?>)
tableShardingValues
.
get
(
0
));
for
(
ShardingValue
<?>
eachTableShardingValue
:
accurateTableShardingValues
)
{
result
.
add
(
shardingRule
.
getTableShardingStrategy
(
tableRule
).
doAccurateSharding
(
tableRule
.
isDynamic
()
?
Collections
.<
String
>
emptyList
()
:
tableRule
.
getActualTableNames
(
routedDataSource
),
eachTableShardingValue
));
...
...
@@ -151,7 +152,7 @@ public final class SimpleRoutingEngine implements RoutingEngine {
return
result
;
}
private
boolean
isAccurateSharding
(
final
List
<
ShardingValue
>
shardingValues
,
final
ShardingStrategy
shardingStrategy
)
{
private
boolean
isAccurateSharding
(
final
List
<
Base
ShardingValue
>
shardingValues
,
final
ShardingStrategy
shardingStrategy
)
{
return
1
==
shardingValues
.
size
()
&&
shardingStrategy
.
getShardingAlgorithm
()
instanceof
SingleKeyShardingAlgorithm
&&
ShardingValue
.
ShardingValueType
.
RANGE
!=
shardingValues
.
get
(
0
).
getType
();
}
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/MultipleKeysModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.integrate.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.MultipleKeysDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -29,15 +31,15 @@ public final class MultipleKeysModuloDatabaseShardingAlgorithm implements Multip
@SuppressWarnings
(
"unchecked"
)
@Override
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
ShardingValue
<?>
shardingValue
=
shardingValues
.
iterator
().
next
();
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
BaseShardingValue
shardingValue
=
shardingValues
.
iterator
().
next
();
switch
(
shardingValue
.
getType
())
{
case
SINGLE:
return
doEqualSharding
(
availableTargetNames
,
(
ShardingValue
<
Integer
>)
shardingValue
);
case
LIST:
return
doInSharding
(
availableTargetNames
,
(
ShardingValue
<
Integer
>)
shardingValue
);
case
RANGE:
return
doBetweenSharding
(
availableTargetNames
,
(
ShardingValue
<
Integer
>)
shardingValue
);
return
doBetweenSharding
(
availableTargetNames
,
(
Range
ShardingValue
<
Integer
>)
shardingValue
);
default
:
throw
new
UnsupportedOperationException
();
}
...
...
@@ -66,7 +68,7 @@ public final class MultipleKeysModuloDatabaseShardingAlgorithm implements Multip
return
result
;
}
private
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
private
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/NoneKeyModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.integrate.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneKeyDatabaseShardingAlgorithm
;
...
...
@@ -25,9 +26,9 @@ import java.util.Collection;
public
class
NoneKeyModuloDatabaseShardingAlgorithm
implements
NoneKeyDatabaseShardingAlgorithm
<
Integer
>
{
@Override
public
String
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
String
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Base
ShardingValue
<
Integer
>
shardingValue
)
{
for
(
String
each
:
availableTargetNames
)
{
if
(
each
.
endsWith
(
shardingValue
.
getValue
()
%
10
+
""
))
{
if
(
each
.
endsWith
(
(
int
)
((
ShardingValue
)
shardingValue
)
.
getValue
()
%
10
+
""
))
{
return
each
;
}
}
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/SingleKeyDynamicModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.integrate.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -36,7 +37,7 @@ public final class SingleKeyDynamicModuloTableShardingAlgorithm implements Singl
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/SingleKeyModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,13 +17,14 @@
package
com.dangdang.ddframe.rdb.integrate.fixture
;
import
java.util.Collection
;
import
java.util.LinkedHashSet
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
import
java.util.Collection
;
import
java.util.LinkedHashSet
;
public
final
class
SingleKeyModuloDatabaseShardingAlgorithm
implements
SingleKeyDatabaseShardingAlgorithm
<
Integer
>
{
@Override
...
...
@@ -37,7 +38,7 @@ public final class SingleKeyModuloDatabaseShardingAlgorithm implements SingleKey
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/fixture/SingleKeyModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.integrate.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class SingleKeyModuloTableShardingAlgorithm implements SingleKeyTab
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/HintManagerTest.java
浏览文件 @
01e0ba08
...
...
@@ -36,7 +36,7 @@ public final class HintManagerTest {
assertTrue
(
HintManagerHolder
.
getDatabaseShardingValue
(
shardingKey
).
isPresent
());
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getColumnName
(),
is
(
"shardingColumn"
));
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
SINGLE
));
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getValue
(),
is
((
Comparable
)
1
));
assertThat
(
((
ShardingValue
)
hintManager
.
getDatabaseShardingValue
(
shardingKey
)
).
getValue
(),
is
((
Comparable
)
1
));
}
}
...
...
@@ -48,7 +48,7 @@ public final class HintManagerTest {
assertTrue
(
HintManagerHolder
.
getDatabaseShardingValue
(
shardingKey
).
isPresent
());
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getColumnName
(),
is
(
"shardingColumn"
));
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
LIST
));
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getValues
().
size
(),
is
(
3
));
assertThat
(
((
ShardingValue
)
hintManager
.
getDatabaseShardingValue
(
shardingKey
)
).
getValues
().
size
(),
is
(
3
));
}
}
...
...
@@ -60,8 +60,8 @@ public final class HintManagerTest {
assertTrue
(
HintManagerHolder
.
getDatabaseShardingValue
(
shardingKey
).
isPresent
());
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getColumnName
(),
is
(
"shardingColumn"
));
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
RANGE
));
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getValueRange
().
lowerEndpoint
(),
is
((
Comparable
)
1
));
assertThat
(
hintManager
.
getDatabaseShardingValue
(
shardingKey
).
getValueRange
().
upperEndpoint
(),
is
((
Comparable
)
10
));
assertThat
(
((
RangeShardingValue
)
hintManager
.
getDatabaseShardingValue
(
shardingKey
)
).
getValueRange
().
lowerEndpoint
(),
is
((
Comparable
)
1
));
assertThat
(
((
RangeShardingValue
)
hintManager
.
getDatabaseShardingValue
(
shardingKey
)
).
getValueRange
().
upperEndpoint
(),
is
((
Comparable
)
10
));
}
}
...
...
@@ -73,7 +73,7 @@ public final class HintManagerTest {
assertTrue
(
HintManagerHolder
.
getTableShardingValue
(
shardingKey
).
isPresent
());
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getColumnName
(),
is
(
"shardingColumn"
));
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
SINGLE
));
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getValue
(),
is
((
Comparable
)
1
));
assertThat
(
((
ShardingValue
)
hintManager
.
getTableShardingValue
(
shardingKey
)
).
getValue
(),
is
((
Comparable
)
1
));
}
}
...
...
@@ -85,7 +85,7 @@ public final class HintManagerTest {
assertTrue
(
HintManagerHolder
.
getTableShardingValue
(
shardingKey
).
isPresent
());
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getColumnName
(),
is
(
"shardingColumn"
));
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
LIST
));
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getValues
().
size
(),
is
(
3
));
assertThat
(
((
ShardingValue
)
hintManager
.
getTableShardingValue
(
shardingKey
)
).
getValues
().
size
(),
is
(
3
));
}
}
...
...
@@ -97,8 +97,8 @@ public final class HintManagerTest {
assertTrue
(
HintManagerHolder
.
getTableShardingValue
(
shardingKey
).
isPresent
());
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getColumnName
(),
is
(
"shardingColumn"
));
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
RANGE
));
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getValueRange
().
lowerEndpoint
(),
is
((
Comparable
)
1
));
assertThat
(
hintManager
.
getTableShardingValue
(
shardingKey
).
getValueRange
().
upperEndpoint
(),
is
((
Comparable
)
10
));
assertThat
(
((
RangeShardingValue
)
hintManager
.
getTableShardingValue
(
shardingKey
)
).
getValueRange
().
lowerEndpoint
(),
is
((
Comparable
)
1
));
assertThat
(
((
RangeShardingValue
)
hintManager
.
getTableShardingValue
(
shardingKey
)
).
getValueRange
().
upperEndpoint
(),
is
((
Comparable
)
10
));
}
}
...
...
@@ -108,7 +108,7 @@ public final class HintManagerTest {
hintManager
.
setDatabaseShardingValue
(
"1"
);
assertTrue
(
hintManager
.
isDatabaseShardingOnly
());
assertTrue
(
hintManager
.
isShardingHint
());
assertThat
((
String
)
hintManager
.
getDatabaseShardingValue
(
new
ShardingKey
(
HintManagerHolder
.
DB_TABLE_NAME
,
HintManagerHolder
.
DB_COLUMN_NAME
)).
getValue
(),
is
(
"1"
));
assertThat
((
String
)
((
ShardingValue
)
hintManager
.
getDatabaseShardingValue
(
new
ShardingKey
(
HintManagerHolder
.
DB_TABLE_NAME
,
HintManagerHolder
.
DB_COLUMN_NAME
)
)).
getValue
(),
is
(
"1"
));
}
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/ShardingValueTest.java
浏览文件 @
01e0ba08
...
...
@@ -40,24 +40,24 @@ public final class ShardingValueTest {
@Test
public
void
assertGetTypeWithRangeValue
()
{
assertThat
(
new
ShardingValue
<>(
"logicTableName"
,
"columnName"
,
Range
.
closed
(
10
,
20
)).
getType
(),
is
(
ShardingValueType
.
RANGE
));
assertThat
(
new
Range
ShardingValue
<>(
"logicTableName"
,
"columnName"
,
Range
.
closed
(
10
,
20
)).
getType
(),
is
(
ShardingValueType
.
RANGE
));
}
@Test
public
void
assertToStringWithSingleValue
()
{
assertThat
(
new
ShardingValue
<>(
"logicTableName"
,
"columnName"
,
"value"
).
toString
(),
is
(
"ShardingValue(logicTableName=logicTableName, columnName=columnName, value=value, values=[]
, valueRange=null
)"
));
"ShardingValue(logicTableName=logicTableName, columnName=columnName, value=value, values=[])"
));
}
@Test
public
void
assertToStringWithMultipleValue
()
{
assertThat
(
new
ShardingValue
<>(
"logicTableName"
,
"columnName"
,
Collections
.
singletonList
(
"value"
)).
toString
(),
is
(
"ShardingValue(logicTableName=logicTableName, columnName=columnName, value=null, values=[value]
, valueRange=null
)"
));
"ShardingValue(logicTableName=logicTableName, columnName=columnName, value=null, values=[value])"
));
}
@Test
public
void
assertToStringWithRangeValue
()
{
assertThat
(
new
ShardingValue
<>(
"logicTableName"
,
"columnName"
,
Range
.
closed
(
10
,
20
)).
toString
(),
is
(
"
ShardingValue(logicTableName=logicTableName, columnName=columnName, value=null, values=[]
, valueRange=[10‥20])"
));
assertThat
(
new
Range
ShardingValue
<>(
"logicTableName"
,
"columnName"
,
Range
.
closed
(
10
,
20
)).
toString
(),
is
(
"
RangeShardingValue(logicTableName=logicTableName, columnName=columnName
, valueRange=[10‥20])"
));
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/strategy/common/ShardingStrategyTest.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.api.strategy.common
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.fixture.TestMultipleKeysShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.fixture.TestSingleKeyShardingAlgorithm
;
...
...
@@ -39,13 +41,13 @@ public final class ShardingStrategyTest {
@Test
public
void
assertDoStaticShardingWithoutShardingColumns
()
{
ShardingStrategy
strategy
=
new
ShardingStrategy
(
Sets
.
newHashSet
(
"column"
),
null
);
assertThat
(
strategy
.
doStaticSharding
(
targets
,
Collections
.<
ShardingValue
>
emptySet
()),
is
(
targets
));
assertThat
(
strategy
.
doStaticSharding
(
targets
,
Collections
.<
Base
ShardingValue
>
emptySet
()),
is
(
targets
));
}
@Test
public
void
assertDoStaticShardingForBetweenSingleKey
()
{
ShardingStrategy
strategy
=
new
ShardingStrategy
(
"column"
,
new
TestSingleKeyShardingAlgorithm
());
assertThat
(
strategy
.
doStaticSharding
(
targets
,
createShardingValues
(
new
ShardingValue
<>(
"logicTable"
,
"column"
,
Range
.
open
(
"1"
,
"3"
)))),
assertThat
(
strategy
.
doStaticSharding
(
targets
,
createShardingValues
(
new
Range
ShardingValue
<>(
"logicTable"
,
"column"
,
Range
.
open
(
"1"
,
"3"
)))),
is
((
Collection
<
String
>)
Sets
.
newHashSet
(
"1"
,
"2"
,
"3"
)));
}
...
...
@@ -59,13 +61,13 @@ public final class ShardingStrategyTest {
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
assertDoDynamicShardingWithoutShardingColumns
()
{
ShardingStrategy
strategy
=
new
ShardingStrategy
(
Sets
.
newHashSet
(
"column"
),
null
);
strategy
.
doDynamicSharding
(
Collections
.<
ShardingValue
>
emptySet
());
strategy
.
doDynamicSharding
(
Collections
.<
Base
ShardingValue
>
emptySet
());
}
@Test
public
void
assertDoDynamicShardingForBetweenSingleKey
()
{
ShardingStrategy
strategy
=
new
ShardingStrategy
(
"column"
,
new
TestSingleKeyShardingAlgorithm
());
assertThat
(
strategy
.
doDynamicSharding
(
createShardingValues
(
new
ShardingValue
<>(
"logicTable"
,
"column"
,
Range
.
open
(
"1"
,
"3"
)))),
is
((
Collection
<
String
>)
Sets
.
newHashSet
(
"1"
,
"2"
,
"3"
)));
assertThat
(
strategy
.
doDynamicSharding
(
createShardingValues
(
new
Range
ShardingValue
<>(
"logicTable"
,
"column"
,
Range
.
open
(
"1"
,
"3"
)))),
is
((
Collection
<
String
>)
Sets
.
newHashSet
(
"1"
,
"2"
,
"3"
)));
}
@Test
...
...
@@ -74,8 +76,8 @@ public final class ShardingStrategyTest {
assertThat
(
strategy
.
doDynamicSharding
(
createShardingValues
(
new
ShardingValue
<>(
"logicTable"
,
"column"
,
"1"
))),
is
((
Collection
<
String
>)
Collections
.<
String
>
emptySet
()));
}
private
Collection
<
ShardingValue
>
createShardingValues
(
final
ShardingValue
<
String
>
shardingValue
)
{
Collection
<
ShardingValue
>
result
=
new
ArrayList
<>(
1
);
private
Collection
<
BaseShardingValue
>
createShardingValues
(
final
BaseShardingValue
shardingValue
)
{
Collection
<
Base
ShardingValue
>
result
=
new
ArrayList
<>(
1
);
result
.
add
(
shardingValue
);
return
result
;
}
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/strategy/fixture/TestMultipleKeysShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,7 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.api.strategy.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.
Base
ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.routing.strategy.MultipleKeysShardingAlgorithm
;
...
...
@@ -27,7 +27,7 @@ import java.util.Collection;
public
final
class
TestMultipleKeysShardingAlgorithm
implements
MultipleKeysShardingAlgorithm
,
DatabaseShardingAlgorithm
,
TableShardingAlgorithm
{
@Override
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
ShardingValue
>
shardingValues
)
{
public
Collection
<
String
>
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Collection
<
Base
ShardingValue
>
shardingValues
)
{
return
availableTargetNames
;
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/strategy/fixture/TestSingleKeyShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.api.strategy.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingAlgorithm
;
...
...
@@ -33,7 +34,7 @@ public final class TestSingleKeyShardingAlgorithm implements SingleKeyShardingAl
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
String
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
String
>
shardingValue
)
{
Collection
<
String
>
result
=
new
ArrayList
<>();
for
(
Integer
i
=
Integer
.
parseInt
(
shardingValue
.
getValueRange
().
lowerEndpoint
());
i
<=
Integer
.
parseInt
(
shardingValue
.
getValueRange
().
upperEndpoint
());
i
++)
{
result
.
add
(
i
.
toString
());
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/context/condition/ConditionTest.java
浏览文件 @
01e0ba08
package
com.dangdang.ddframe.rdb.sharding.parsing.parser.context.condition
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.parsing.parser.expression.SQLExpression
;
import
com.dangdang.ddframe.rdb.sharding.parsing.parser.expression.SQLNumberExpression
;
...
...
@@ -17,19 +19,19 @@ public final class ConditionTest {
@Test
public
void
assertGetShardingValue
()
{
Condition
condition
=
new
Condition
(
new
Column
(
"test"
,
"test"
),
new
SQLNumberExpression
(
1
));
ShardingValue
<?>
shardingValue
=
condition
.
getShardingValue
(
Collections
.
emptyList
());
BaseShardingValue
shardingValue
=
condition
.
getShardingValue
(
Collections
.
emptyList
());
assertThat
(
shardingValue
.
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
SINGLE
));
assertThat
((
Integer
)
shardingValue
.
getValue
(),
is
(
1
));
assertThat
((
Integer
)
((
ShardingValue
)
shardingValue
)
.
getValue
(),
is
(
1
));
condition
=
new
Condition
(
new
Column
(
"test"
,
"test"
),
Arrays
.<
SQLExpression
>
asList
(
new
SQLNumberExpression
(
1
),
new
SQLNumberExpression
(
2
)));
shardingValue
=
condition
.
getShardingValue
(
Collections
.
emptyList
());
assertThat
(
shardingValue
.
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
LIST
));
Iterator
<?>
iterator
=
shardingValue
.
getValues
().
iterator
();
Iterator
<?>
iterator
=
((
ShardingValue
)
shardingValue
)
.
getValues
().
iterator
();
assertThat
((
Integer
)
iterator
.
next
(),
is
(
1
));
assertThat
((
Integer
)
iterator
.
next
(),
is
(
2
));
condition
=
new
Condition
(
new
Column
(
"test"
,
"test"
),
new
SQLNumberExpression
(
1
),
new
SQLNumberExpression
(
2
));
shardingValue
=
condition
.
getShardingValue
(
Collections
.
emptyList
());
assertThat
(
shardingValue
.
getType
(),
is
(
ShardingValue
.
ShardingValueType
.
RANGE
));
assertThat
((
Integer
)
shardingValue
.
getValueRange
().
lowerEndpoint
(),
is
(
1
));
assertThat
((
Integer
)
shardingValue
.
getValueRange
().
upperEndpoint
(),
is
(
2
));
assertThat
((
Integer
)
((
RangeShardingValue
)
shardingValue
)
.
getValueRange
().
lowerEndpoint
(),
is
(
1
));
assertThat
((
Integer
)
((
RangeShardingValue
)
shardingValue
)
.
getValueRange
().
upperEndpoint
(),
is
(
2
));
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/sql/DeleteStatementParserTest.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.parsing.parser.sql
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule
;
import
com.dangdang.ddframe.rdb.sharding.constant.DatabaseType
;
import
com.dangdang.ddframe.rdb.sharding.constant.ShardingOperator
;
...
...
@@ -61,16 +63,16 @@ public final class DeleteStatementParserTest extends AbstractStatementParserTest
assertThat
(
deleteStatement
.
getTables
().
find
(
"xxx"
).
get
().
getAlias
().
get
(),
is
(
"xxx"
));
Condition
condition1
=
deleteStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition1
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition1
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValue
(),
is
((
Object
)
1
));
assertThat
(
((
ShardingValue
)
condition1
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValue
(),
is
((
Object
)
1
));
Condition
condition2
=
deleteStatement
.
getConditions
().
find
(
new
Column
(
"field2"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition2
.
getOperator
(),
is
(
ShardingOperator
.
IN
));
Iterator
<?>
shardingValues2
=
condition2
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValues
().
iterator
();
Iterator
<?>
shardingValues2
=
((
ShardingValue
)
condition2
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValues
().
iterator
();
assertThat
(
shardingValues2
.
next
(),
is
((
Object
)
1
));
assertThat
(
shardingValues2
.
next
(),
is
((
Object
)
3
));
assertFalse
(
shardingValues2
.
hasNext
());
Condition
condition3
=
deleteStatement
.
getConditions
().
find
(
new
Column
(
"field3"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition3
.
getOperator
(),
is
(
ShardingOperator
.
BETWEEN
));
Range
shardingValues3
=
condition3
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValueRange
();
Range
shardingValues3
=
((
RangeShardingValue
)
condition3
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValueRange
();
assertThat
(
shardingValues3
.
lowerEndpoint
(),
is
((
Comparable
)
5
));
assertThat
(
shardingValues3
.
upperEndpoint
(),
is
((
Comparable
)
20
));
}
...
...
@@ -90,15 +92,15 @@ public final class DeleteStatementParserTest extends AbstractStatementParserTest
List
<
Object
>
actualParameters
=
Arrays
.<
Object
>
asList
(
0
,
10
,
20
,
30
,
40
,
50
,
60
,
70
,
80
);
Condition
condition1
=
deleteStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition1
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition1
.
getShardingValue
(
actualParameters
).
getValue
(),
is
((
Object
)
10
));
assertThat
(
((
ShardingValue
)
condition1
.
getShardingValue
(
actualParameters
)
).
getValue
(),
is
((
Object
)
10
));
Condition
condition2
=
deleteStatement
.
getConditions
().
find
(
new
Column
(
"field2"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition2
.
getOperator
(),
is
(
ShardingOperator
.
IN
));
Iterator
<?>
shardingValues2
=
condition2
.
getShardingValue
(
actualParameters
).
getValues
().
iterator
();
Iterator
<?>
shardingValues2
=
((
ShardingValue
)
condition2
.
getShardingValue
(
actualParameters
)
).
getValues
().
iterator
();
assertThat
(
shardingValues2
.
next
(),
is
((
Object
)
30
));
assertThat
(
shardingValues2
.
next
(),
is
((
Object
)
40
));
Condition
condition3
=
deleteStatement
.
getConditions
().
find
(
new
Column
(
"field3"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition3
.
getOperator
(),
is
(
ShardingOperator
.
BETWEEN
));
Range
shardingValues3
=
condition3
.
getShardingValue
(
actualParameters
).
getValueRange
();
Range
shardingValues3
=
((
RangeShardingValue
)
condition3
.
getShardingValue
(
actualParameters
)
).
getValueRange
();
assertThat
(
shardingValues3
.
lowerEndpoint
(),
is
((
Comparable
)
60
));
assertThat
(
shardingValues3
.
upperEndpoint
(),
is
((
Comparable
)
70
));
}
...
...
@@ -129,6 +131,6 @@ public final class DeleteStatementParserTest extends AbstractStatementParserTest
assertFalse
(
deleteStatement
.
getTables
().
find
(
"TABLE_XXX"
).
get
().
getAlias
().
isPresent
());
Condition
condition
=
deleteStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValue
(),
is
((
Comparable
)
1
));
assertThat
(
((
ShardingValue
)
condition
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValue
(),
is
((
Comparable
)
1
));
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/sql/InsertStatementParserTest.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.parsing.parser.sql
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.TableRule
;
...
...
@@ -77,7 +78,7 @@ public final class InsertStatementParserTest extends AbstractStatementParserTest
assertThat
(
insertStatement
.
getTables
().
find
(
"TABLE_XXX"
).
get
().
getName
(),
is
(
"TABLE_XXX"
));
Condition
condition
=
insertStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValue
(),
is
((
Comparable
)
10
));
assertThat
(
((
ShardingValue
)
condition
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValue
(),
is
((
Comparable
)
10
));
}
@Test
...
...
@@ -92,7 +93,7 @@ public final class InsertStatementParserTest extends AbstractStatementParserTest
assertThat
(
insertStatement
.
getTables
().
find
(
"TABLE_XXX"
).
get
().
getName
(),
is
(
"TABLE_XXX"
));
Condition
condition
=
insertStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition
.
getShardingValue
(
Collections
.<
Object
>
singletonList
(
0
)).
getValue
(),
is
((
Comparable
)
0
));
assertThat
(
((
ShardingValue
)
condition
.
getShardingValue
(
Collections
.<
Object
>
singletonList
(
0
)
)).
getValue
(),
is
((
Comparable
)
0
));
}
private
ShardingRule
createShardingRuleWithGenerateKeyColumns
()
{
...
...
@@ -131,7 +132,7 @@ public final class InsertStatementParserTest extends AbstractStatementParserTest
assertFalse
(
insertStatement
.
getTables
().
find
(
"TABLE_XXX"
).
get
().
getAlias
().
isPresent
());
Condition
condition
=
insertStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValue
(),
is
((
Comparable
)
1
));
assertThat
(
((
ShardingValue
)
condition
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValue
(),
is
((
Comparable
)
1
));
}
@Test
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/sql/UpdateStatementParserTest.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,8 @@
package
com.dangdang.ddframe.rdb.sharding.parsing.parser.sql
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule
;
import
com.dangdang.ddframe.rdb.sharding.constant.DatabaseType
;
import
com.dangdang.ddframe.rdb.sharding.constant.ShardingOperator
;
...
...
@@ -61,15 +63,15 @@ public final class UpdateStatementParserTest extends AbstractStatementParserTest
assertThat
(
updateStatement
.
getTables
().
find
(
"TABLE_XXX"
).
get
().
getAlias
().
get
(),
is
(
"xxx"
));
Condition
condition1
=
updateStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition1
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition1
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValue
(),
is
((
Comparable
)
1
));
assertThat
(
((
ShardingValue
)
condition1
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValue
(),
is
((
Comparable
)
1
));
Condition
condition2
=
updateStatement
.
getConditions
().
find
(
new
Column
(
"field2"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition2
.
getOperator
(),
is
(
ShardingOperator
.
IN
));
Iterator
<?>
shardingValues2
=
condition2
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValues
().
iterator
();
Iterator
<?>
shardingValues2
=
((
ShardingValue
)
condition2
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValues
().
iterator
();
assertThat
(
shardingValues2
.
next
(),
is
((
Object
)
1
));
assertThat
(
shardingValues2
.
next
(),
is
((
Object
)
3
));
assertFalse
(
shardingValues2
.
hasNext
());
Condition
condition3
=
updateStatement
.
getConditions
().
find
(
new
Column
(
"field3"
,
"TABLE_XXX"
)).
get
();
Range
shardingValues3
=
condition3
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValueRange
();
Range
shardingValues3
=
((
RangeShardingValue
)
condition3
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValueRange
();
assertThat
(
condition3
.
getOperator
(),
is
(
ShardingOperator
.
BETWEEN
));
assertThat
(
shardingValues3
.
lowerEndpoint
(),
is
((
Comparable
)
5
));
assertThat
(
shardingValues3
.
upperEndpoint
(),
is
((
Comparable
)
20
));
...
...
@@ -90,16 +92,16 @@ public final class UpdateStatementParserTest extends AbstractStatementParserTest
List
<
Object
>
actualParameters
=
Arrays
.<
Object
>
asList
(
0
,
10
,
20
,
30
,
40
,
50
,
60
,
70
,
80
);
Condition
condition1
=
updateStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition1
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition1
.
getShardingValue
(
actualParameters
).
getValue
(),
is
((
Comparable
)
20
));
assertThat
(
((
ShardingValue
)
condition1
.
getShardingValue
(
actualParameters
)
).
getValue
(),
is
((
Comparable
)
20
));
Condition
condition2
=
updateStatement
.
getConditions
().
find
(
new
Column
(
"field2"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition2
.
getOperator
(),
is
(
ShardingOperator
.
IN
));
Iterator
<?>
shardingValue2
=
condition2
.
getShardingValue
(
actualParameters
).
getValues
().
iterator
();
Iterator
<?>
shardingValue2
=
((
ShardingValue
)
condition2
.
getShardingValue
(
actualParameters
)
).
getValues
().
iterator
();
assertThat
(
shardingValue2
.
next
(),
is
((
Object
)
40
));
assertThat
(
shardingValue2
.
next
(),
is
((
Object
)
50
));
assertFalse
(
shardingValue2
.
hasNext
());
Condition
condition3
=
updateStatement
.
getConditions
().
find
(
new
Column
(
"field3"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition3
.
getOperator
(),
is
(
ShardingOperator
.
BETWEEN
));
Range
shardingValue3
=
condition3
.
getShardingValue
(
actualParameters
).
getValueRange
();
Range
shardingValue3
=
((
RangeShardingValue
)
condition3
.
getShardingValue
(
actualParameters
)
).
getValueRange
();
assertThat
(
shardingValue3
.
lowerEndpoint
(),
is
((
Comparable
)
70
));
assertThat
(
shardingValue3
.
upperEndpoint
(),
is
((
Comparable
)
80
));
}
...
...
@@ -126,6 +128,6 @@ public final class UpdateStatementParserTest extends AbstractStatementParserTest
assertFalse
(
updateStatement
.
getTables
().
find
(
"TABLE_XXX"
).
get
().
getAlias
().
isPresent
());
Condition
condition
=
updateStatement
.
getConditions
().
find
(
new
Column
(
"field1"
,
"TABLE_XXX"
)).
get
();
assertThat
(
condition
.
getOperator
(),
is
(
ShardingOperator
.
EQUAL
));
assertThat
(
condition
.
getShardingValue
(
Collections
.
emptyList
(
)).
getValue
(),
is
((
Object
)
1
));
assertThat
(
((
ShardingValue
)
condition
.
getShardingValue
(
Collections
.
emptyList
()
)).
getValue
(),
is
((
Object
)
1
));
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/routing/fixture/OrderAttrShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
...
...
@@ -36,7 +37,7 @@ public final class OrderAttrShardingAlgorithm implements SingleKeyTableShardingA
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
throw
new
UnsupportedOperationException
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/routing/fixture/OrderDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.BaseShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneKeyDatabaseShardingAlgorithm
;
...
...
@@ -25,9 +26,9 @@ import java.util.Collection;
public
class
OrderDatabaseShardingAlgorithm
implements
NoneKeyDatabaseShardingAlgorithm
<
Integer
>
{
@Override
public
String
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
String
doSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Base
ShardingValue
<
Integer
>
shardingValue
)
{
for
(
String
each
:
availableTargetNames
)
{
if
(
each
.
endsWith
(
String
.
valueOf
(
shardingValue
.
getValue
()
%
2
)))
{
if
(
each
.
endsWith
(
String
.
valueOf
(
(
int
)
((
ShardingValue
)
shardingValue
)
.
getValue
()
%
2
)))
{
return
each
;
}
}
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/routing/fixture/OrderShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.routing.fixture
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
...
...
@@ -37,7 +38,7 @@ public final class OrderShardingAlgorithm implements SingleKeyDatabaseShardingAl
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
HashSet
<>(
2
);
for
(
int
i
=
shardingValue
.
getValueRange
().
lowerEndpoint
();
i
<=
shardingValue
.
getValueRange
().
upperEndpoint
();
i
++)
{
for
(
String
each
:
availableTargetNames
)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-config-spring-masterslave/src/main/java/com/dangdang/ddframe/rdb/sharding/example/config/spring/masterslave/algorithm/SingleKeyModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -18,6 +18,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.config.spring.masterslave.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -38,7 +39,7 @@ public class SingleKeyModuloTableShardingAlgorithm implements SingleKeyTableShar
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-config-spring/src/main/java/com/dangdang/ddframe/rdb/sharding/example/config/spring/algorithm/SingleKeyModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -18,6 +18,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.config.spring.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -38,7 +39,7 @@ public class SingleKeyModuloTableShardingAlgorithm implements SingleKeyTableShar
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jdbc-masterslave/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/masterslave/algorithm/ModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jdbc.masterslave.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class ModuloDatabaseShardingAlgorithm implements SingleKeyDatabaseS
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
dataSourceNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
dataSourceNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
dataSourceNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jdbc-masterslave/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/masterslave/algorithm/ModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jdbc.masterslave.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class ModuloTableShardingAlgorithm implements SingleKeyTableShardin
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
tableNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
tableNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
tableNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jdbc-transaction/src/main/java/com/dangdang/ddframe/rdb/sharding/example/transaction/algorithm/ModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.transaction.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class ModuloDatabaseShardingAlgorithm implements SingleKeyDatabaseS
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
dataSourceNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
dataSourceNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
dataSourceNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jdbc-transaction/src/main/java/com/dangdang/ddframe/rdb/sharding/example/transaction/algorithm/ModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.transaction.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class ModuloTableShardingAlgorithm implements SingleKeyTableShardin
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
tableNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
tableNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
tableNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jdbc/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/ModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jdbc.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class ModuloDatabaseShardingAlgorithm implements SingleKeyDatabaseS
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
dataSourceNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
dataSourceNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
dataSourceNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jdbc/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/ModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jdbc.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class ModuloTableShardingAlgorithm implements SingleKeyTableShardin
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
tableNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
tableNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
tableNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jpa/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jpa/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jpa.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class SingleKeyModuloDatabaseShardingAlgorithm implements SingleKey
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-jpa/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jpa/algorithm/SingleKeyModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jpa.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class SingleKeyModuloTableShardingAlgorithm implements SingleKeyTab
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Long
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Long
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Long
>
range
=
shardingValue
.
getValueRange
();
for
(
Long
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-mybatis/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/SingleKeyModuloDatabaseShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jdbc.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class SingleKeyModuloDatabaseShardingAlgorithm implements SingleKey
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Integer
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Integer
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Integer
>
range
=
shardingValue
.
getValueRange
();
for
(
Integer
value
=
range
.
lowerEndpoint
();
value
<=
range
.
upperEndpoint
();
value
++)
{
...
...
sharding-jdbc-example/sharding-jdbc-example-mybatis/src/main/java/com/dangdang/ddframe/rdb/sharding/example/jdbc/algorithm/SingleKeyModuloTableShardingAlgorithm.java
浏览文件 @
01e0ba08
...
...
@@ -17,6 +17,7 @@
package
com.dangdang.ddframe.rdb.sharding.example.jdbc.algorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.RangeShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.ShardingValue
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm
;
import
com.google.common.collect.Range
;
...
...
@@ -37,7 +38,7 @@ public final class SingleKeyModuloTableShardingAlgorithm implements SingleKeyTab
}
@Override
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
ShardingValue
<
Long
>
shardingValue
)
{
public
Collection
<
String
>
doBetweenSharding
(
final
Collection
<
String
>
availableTargetNames
,
final
Range
ShardingValue
<
Long
>
shardingValue
)
{
Collection
<
String
>
result
=
new
LinkedHashSet
<>(
availableTargetNames
.
size
());
Range
<
Long
>
range
=
shardingValue
.
getValueRange
();
for
(
Long
i
=
range
.
lowerEndpoint
();
i
<=
range
.
upperEndpoint
();
i
++)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录