Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
b06c7b52
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,发现更多精彩内容 >>
提交
b06c7b52
编写于
1月 09, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor ShardingRule
上级
1c9a5b4e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
60 deletion
+56
-60
sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java
...c/main/java/io/shardingsphere/core/rule/ShardingRule.java
+56
-60
未找到文件。
sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java
浏览文件 @
b06c7b52
...
...
@@ -200,6 +200,50 @@ public class ShardingRule {
return
null
==
tableRule
.
getTableShardingStrategy
()
?
defaultTableShardingStrategy
:
tableRule
.
getTableShardingStrategy
();
}
/**
* Judge logic tables is all belong to binding tables.
*
* @param logicTableNames logic table names
* @return logic tables is all belong to binding tables or not
*/
public
boolean
isAllBindingTables
(
final
Collection
<
String
>
logicTableNames
)
{
if
(
logicTableNames
.
isEmpty
())
{
return
false
;
}
Optional
<
BindingTableRule
>
bindingTableRule
=
findBindingTableRule
(
logicTableNames
);
if
(!
bindingTableRule
.
isPresent
())
{
return
false
;
}
Collection
<
String
>
result
=
new
TreeSet
<>(
String
.
CASE_INSENSITIVE_ORDER
);
result
.
addAll
(
bindingTableRule
.
get
().
getAllLogicTables
());
return
!
result
.
isEmpty
()
&&
result
.
containsAll
(
logicTableNames
);
}
private
Optional
<
BindingTableRule
>
findBindingTableRule
(
final
Collection
<
String
>
logicTableNames
)
{
for
(
String
each
:
logicTableNames
)
{
Optional
<
BindingTableRule
>
result
=
findBindingTableRule
(
each
);
if
(
result
.
isPresent
())
{
return
result
;
}
}
return
Optional
.
absent
();
}
/**
* Find binding table rule via logic table name.
*
* @param logicTableName logic table name
* @return binding table rule
*/
public
Optional
<
BindingTableRule
>
findBindingTableRule
(
final
String
logicTableName
)
{
for
(
BindingTableRule
each
:
bindingTableRules
)
{
if
(
each
.
hasLogicTable
(
logicTableName
))
{
return
Optional
.
of
(
each
);
}
}
return
Optional
.
absent
();
}
/**
* Judge logic tables is all belong to broadcast tables.
*
...
...
@@ -233,25 +277,6 @@ public class ShardingRule {
return
false
;
}
/**
* Judge logic tables is all belong to binding tables.
*
* @param logicTables names of logic tables
* @return logic tables is all belong to binding tables or not
*/
public
boolean
isAllBindingTables
(
final
Collection
<
String
>
logicTables
)
{
if
(
logicTables
.
isEmpty
())
{
return
false
;
}
Optional
<
BindingTableRule
>
bindingTableRule
=
findBindingTableRule
(
logicTables
);
if
(!
bindingTableRule
.
isPresent
())
{
return
false
;
}
Collection
<
String
>
result
=
new
TreeSet
<>(
String
.
CASE_INSENSITIVE_ORDER
);
result
.
addAll
(
bindingTableRule
.
get
().
getAllLogicTables
());
return
!
result
.
isEmpty
()
&&
result
.
containsAll
(
logicTables
);
}
/**
* Judge logic tables is all belong to default data source.
*
...
...
@@ -267,31 +292,6 @@ public class ShardingRule {
return
!
logicTableNames
.
isEmpty
();
}
private
Optional
<
BindingTableRule
>
findBindingTableRule
(
final
Collection
<
String
>
logicTables
)
{
for
(
String
each
:
logicTables
)
{
Optional
<
BindingTableRule
>
result
=
findBindingTableRule
(
each
);
if
(
result
.
isPresent
())
{
return
result
;
}
}
return
Optional
.
absent
();
}
/**
* Get binding table rule via logic table name.
*
* @param logicTable logic table name
* @return binding table rule
*/
public
Optional
<
BindingTableRule
>
findBindingTableRule
(
final
String
logicTable
)
{
for
(
BindingTableRule
each
:
bindingTableRules
)
{
if
(
each
.
hasLogicTable
(
logicTable
))
{
return
Optional
.
of
(
each
);
}
}
return
Optional
.
absent
();
}
/**
* Judge is sharding column or not.
*
...
...
@@ -300,21 +300,19 @@ public class ShardingRule {
*/
public
boolean
isShardingColumn
(
final
Column
column
)
{
for
(
TableRule
each
:
tableRules
)
{
if
(!
each
.
getLogicTable
().
equalsIgnoreCase
(
column
.
getTableName
()))
{
continue
;
}
ShardingStrategy
databaseShardingStrategy
=
getDatabaseShardingStrategy
(
each
);
if
(
null
!=
databaseShardingStrategy
&&
databaseShardingStrategy
.
getShardingColumns
().
contains
(
column
.
getName
()))
{
if
(
each
.
getLogicTable
().
equalsIgnoreCase
(
column
.
getTableName
())
&&
isShardingColumn
(
each
,
column
))
{
return
true
;
}
ShardingStrategy
tableShardingStrategy
=
getTableShardingStrategy
(
each
);
return
null
!=
tableShardingStrategy
&&
tableShardingStrategy
.
getShardingColumns
().
contains
(
column
.
getName
());
}
return
false
;
}
private
boolean
isShardingColumn
(
final
TableRule
tableRule
,
final
Column
column
)
{
return
getDatabaseShardingStrategy
(
tableRule
).
getShardingColumns
().
contains
(
column
.
getName
())
||
getTableShardingStrategy
(
tableRule
).
getShardingColumns
().
contains
(
column
.
getName
());
}
/**
*
get generated key's column
.
*
Get column of generated key
.
*
* @param logicTableName logic table name
* @return generated key's column
...
...
@@ -339,10 +337,8 @@ public class ShardingRule {
if
(!
tableRule
.
isPresent
())
{
throw
new
ShardingConfigurationException
(
"Cannot find strategy for generate keys."
);
}
if
(
null
!=
tableRule
.
get
().
getKeyGenerator
())
{
return
tableRule
.
get
().
getKeyGenerator
().
generateKey
();
}
return
defaultKeyGenerator
.
generateKey
();
KeyGenerator
keyGenerator
=
null
==
tableRule
.
get
().
getKeyGenerator
()
?
defaultKeyGenerator
:
tableRule
.
get
().
getKeyGenerator
();
return
keyGenerator
.
generateKey
();
}
/**
...
...
@@ -361,7 +357,7 @@ public class ShardingRule {
}
/**
* Find data node by logic table.
* Find data node by logic table
name
.
*
* @param logicTableName logic table name
* @return data node
...
...
@@ -461,11 +457,11 @@ public class ShardingRule {
/**
* Judge contains table in sharding rule.
*
* @param
tableName
table name
* @param
logicTableName logic
table name
* @return contains table in sharding rule or not
*/
public
boolean
contains
(
final
String
t
ableName
)
{
return
findTableRule
(
tableName
).
isPresent
()
||
findBindingTableRule
(
tableName
).
isPresent
()
||
isBroadcastTable
(
t
ableName
);
public
boolean
contains
(
final
String
logicT
ableName
)
{
return
findTableRule
(
logicTableName
).
isPresent
()
||
findBindingTableRule
(
logicTableName
).
isPresent
()
||
isBroadcastTable
(
logicT
ableName
);
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录