Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
e73924b0
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,体验更适合开发者的 AI 搜索 >>
提交
e73924b0
编写于
1月 08, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor RoutingEngineFactory
上级
03dd94c7
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
137 addition
and
101 deletion
+137
-101
sharding-core/src/main/java/io/shardingsphere/core/merger/MergedResult.java
...main/java/io/shardingsphere/core/merger/MergedResult.java
+1
-1
sharding-core/src/main/java/io/shardingsphere/core/merger/QueryResult.java
.../main/java/io/shardingsphere/core/merger/QueryResult.java
+1
-1
sharding-core/src/main/java/io/shardingsphere/core/optimizer/condition/ShardingConditions.java
...ngsphere/core/optimizer/condition/ShardingConditions.java
+1
-1
sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/LexerEngine.java
...ava/io/shardingsphere/core/parsing/lexer/LexerEngine.java
+5
-5
sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/analyzer/CharType.java
.../shardingsphere/core/parsing/lexer/analyzer/CharType.java
+10
-10
sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/SelectStatement.java
...e/core/parsing/parser/sql/dql/select/SelectStatement.java
+2
-2
sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterVisitedManager.java
...core/routing/router/masterslave/MasterVisitedManager.java
+1
-1
sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java
...sphere/core/routing/router/sharding/ParsingSQLRouter.java
+3
-11
sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/RoutingEngineFactory.java
...re/core/routing/router/sharding/RoutingEngineFactory.java
+47
-37
sharding-core/src/main/java/io/shardingsphere/core/routing/type/RoutingResult.java
...va/io/shardingsphere/core/routing/type/RoutingResult.java
+1
-1
sharding-core/src/main/java/io/shardingsphere/core/rule/BindingTableRule.java
...in/java/io/shardingsphere/core/rule/BindingTableRule.java
+1
-1
sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java
...c/main/java/io/shardingsphere/core/rule/ShardingRule.java
+37
-18
sharding-core/src/main/java/io/shardingsphere/core/util/StringUtil.java
...src/main/java/io/shardingsphere/core/util/StringUtil.java
+6
-6
sharding-core/src/test/java/io/shardingsphere/core/rule/ShardingRuleTest.java
...st/java/io/shardingsphere/core/rule/ShardingRuleTest.java
+20
-5
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-api/src/main/java/io/shardingsphere/orchestration/reg/api/RegistryCenter.java
.../shardingsphere/orchestration/reg/api/RegistryCenter.java
+1
-1
未找到文件。
sharding-core/src/main/java/io/shardingsphere/core/merger/MergedResult.java
浏览文件 @
e73924b0
...
...
@@ -99,7 +99,7 @@ public interface MergedResult {
InputStream
getInputStream
(
String
columnLabel
,
String
type
)
throws
SQLException
;
/**
*
Adjust
ResultSet is null or not.
*
Judge
ResultSet is null or not.
*
* @return ResultSet is null or not
* @throws SQLException SQL Exception
...
...
sharding-core/src/main/java/io/shardingsphere/core/merger/QueryResult.java
浏览文件 @
e73924b0
...
...
@@ -116,7 +116,7 @@ public interface QueryResult {
InputStream
getInputStream
(
String
columnLabel
,
String
type
)
throws
SQLException
;
/**
*
Adjust
ResultSet is null or not.
*
Judge
ResultSet is null or not.
*
* @return ResultSet is null or not
* @throws SQLException SQL Exception
...
...
sharding-core/src/main/java/io/shardingsphere/core/optimizer/condition/ShardingConditions.java
浏览文件 @
e73924b0
...
...
@@ -36,7 +36,7 @@ public final class ShardingConditions {
private
final
List
<
ShardingCondition
>
shardingConditions
;
/**
*
Adjust
sharding conditions is always false or not.
*
Judge
sharding conditions is always false or not.
*
* @return sharding conditions is always false or not
*/
...
...
sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/LexerEngine.java
浏览文件 @
e73924b0
...
...
@@ -125,9 +125,9 @@ public final class LexerEngine {
}
/**
*
Adjust
current token equals one of input tokens or not.
*
Judge
current token equals one of input tokens or not.
*
* @param tokenTypes to be
adjust
ed token types
* @param tokenTypes to be
judg
ed token types
* @return current token equals one of input tokens or not
*/
public
boolean
equalAny
(
final
TokenType
...
tokenTypes
)
{
...
...
@@ -142,7 +142,7 @@ public final class LexerEngine {
/**
* Skip current token if equals one of input tokens.
*
* @param tokenTypes to be
adjust
ed token types
* @param tokenTypes to be
judg
ed token types
* @return skipped current token or not
*/
public
boolean
skipIfEqual
(
final
TokenType
...
tokenTypes
)
{
...
...
@@ -181,7 +181,7 @@ public final class LexerEngine {
/**
* Throw unsupported exception if current token equals one of input tokens.
*
* @param tokenTypes to be
adjust
ed token types
* @param tokenTypes to be
judg
ed token types
*/
public
void
unsupportedIfEqual
(
final
TokenType
...
tokenTypes
)
{
if
(
equalAny
(
tokenTypes
))
{
...
...
@@ -192,7 +192,7 @@ public final class LexerEngine {
/**
* Throw unsupported exception if current token not equals one of input tokens.
*
* @param tokenTypes to be
adjust
ed token types
* @param tokenTypes to be
judg
ed token types
*/
public
void
unsupportedIfNotSkip
(
final
TokenType
...
tokenTypes
)
{
if
(!
skipIfEqual
(
tokenTypes
))
{
...
...
sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/analyzer/CharType.java
浏览文件 @
e73924b0
...
...
@@ -34,9 +34,9 @@ public final class CharType {
public
static
final
byte
EOI
=
0x1A
;
/**
*
Adjust
is whitespace or not.
*
Judge
is whitespace or not.
*
* @param ch to be
adjust
ed char
* @param ch to be
judg
ed char
* @return is whitespace or not
*/
public
static
boolean
isWhitespace
(
final
char
ch
)
{
...
...
@@ -44,9 +44,9 @@ public final class CharType {
}
/**
*
Adjust
is end of input or not.
*
Judge
is end of input or not.
*
* @param ch to be
adjust
ed char
* @param ch to be
judg
ed char
* @return is end of input or not
*/
public
static
boolean
isEndOfInput
(
final
char
ch
)
{
...
...
@@ -54,9 +54,9 @@ public final class CharType {
}
/**
*
Adjust
is alphabet or not.
*
Judge
is alphabet or not.
*
* @param ch to be
adjust
ed char
* @param ch to be
judg
ed char
* @return is alphabet or not
*/
public
static
boolean
isAlphabet
(
final
char
ch
)
{
...
...
@@ -64,9 +64,9 @@ public final class CharType {
}
/**
*
Adjust
is digital or not.
*
Judge
is digital or not.
*
* @param ch to be
adjust
ed char
* @param ch to be
judg
ed char
* @return is alphabet or not
*/
public
static
boolean
isDigital
(
final
char
ch
)
{
...
...
@@ -74,9 +74,9 @@ public final class CharType {
}
/**
*
Adjust
is symbol or not.
*
Judge
is symbol or not.
*
* @param ch to be
adjust
ed char
* @param ch to be
judg
ed char
* @return is symbol or not
*/
public
static
boolean
isSymbol
(
final
char
ch
)
{
...
...
sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/SelectStatement.java
浏览文件 @
e73924b0
...
...
@@ -198,7 +198,7 @@ public final class SelectStatement extends DQLStatement {
}
/**
*
Adjust
group by and order by sequence is same or not.
*
Judge
group by and order by sequence is same or not.
*
* @return group by and order by sequence is same or not
*/
...
...
@@ -251,7 +251,7 @@ public final class SelectStatement extends DQLStatement {
}
/**
*
Adjust
contains subquery statement or not.
*
Judge
contains subquery statement or not.
*
* @return contains subquery statement or not
*/
...
...
sharding-core/src/main/java/io/shardingsphere/core/routing/router/masterslave/MasterVisitedManager.java
浏览文件 @
e73924b0
...
...
@@ -35,7 +35,7 @@ public final class MasterVisitedManager {
};
/**
*
Adjust
master data source visited in current thread.
*
Judge
master data source visited in current thread.
*
* @return master data source visited or not in current thread
*/
...
...
sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java
浏览文件 @
e73924b0
...
...
@@ -96,7 +96,7 @@ public final class ParsingSQLRouter implements ShardingRouter {
if
(
generatedKey
.
isPresent
())
{
setGeneratedKeys
(
result
,
generatedKey
.
get
());
}
if
(
isNeedMergeShardingValues
(
sqlStatement
))
{
if
(
sqlStatement
instanceof
SelectStatement
&&
isNeedMergeShardingValues
((
SelectStatement
)
sqlStatement
))
{
checkSubqueryShardingValues
(
sqlStatement
.
getConditions
(),
shardingConditions
);
mergeShardingValues
(
shardingConditions
);
}
...
...
@@ -151,16 +151,8 @@ public final class ParsingSQLRouter implements ShardingRouter {
sqlRouteResult
.
getGeneratedKey
().
getGeneratedKeys
().
addAll
(
generatedKeys
);
}
private
boolean
isNeedMergeShardingValues
(
final
SQLStatement
sqlStatement
)
{
if
(!(
sqlStatement
instanceof
SelectStatement
)
||
((
SelectStatement
)
sqlStatement
).
getSubqueryConditions
().
isEmpty
())
{
return
false
;
}
for
(
String
each
:
sqlStatement
.
getTables
().
getTableNames
())
{
if
(
shardingRule
.
findTableRuleByLogicTable
(
each
).
isPresent
())
{
return
true
;
}
}
return
false
;
private
boolean
isNeedMergeShardingValues
(
final
SelectStatement
selectStatement
)
{
return
!
selectStatement
.
getSubqueryConditions
().
isEmpty
()
&&
!
shardingRule
.
getShardingLogicTableNames
(
selectStatement
.
getTables
().
getTableNames
()).
isEmpty
();
}
private
void
checkSubqueryShardingValues
(
final
Conditions
conditions
,
final
ShardingConditions
shardingConditions
)
{
...
...
sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/RoutingEngineFactory.java
浏览文件 @
e73924b0
...
...
@@ -29,6 +29,7 @@ import io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.ResetP
import
io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.SetParamStatement
;
import
io.shardingsphere.core.parsing.parser.sql.SQLStatement
;
import
io.shardingsphere.core.parsing.parser.sql.dal.DALStatement
;
import
io.shardingsphere.core.parsing.parser.sql.dml.DMLStatement
;
import
io.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement
;
import
io.shardingsphere.core.routing.type.RoutingEngine
;
import
io.shardingsphere.core.routing.type.broadcast.DatabaseBroadcastRoutingEngine
;
...
...
@@ -44,7 +45,6 @@ import lombok.AccessLevel;
import
lombok.NoArgsConstructor
;
import
java.util.Collection
;
import
java.util.LinkedList
;
/**
* Routing engine factory.
...
...
@@ -66,45 +66,55 @@ public final class RoutingEngineFactory {
public
static
RoutingEngine
newInstance
(
final
ShardingRule
shardingRule
,
final
ShardingDataSourceMetaData
shardingDataSourceMetaData
,
final
SQLStatement
sqlStatement
,
final
ShardingConditions
shardingConditions
)
{
Collection
<
String
>
tableNames
=
sqlStatement
.
getTables
().
getTableNames
();
Collection
<
String
>
WithOutBroadcastTableNames
=
removeBroadcastTables
(
shardingRule
,
tableNames
);
RoutingEngine
result
;
if
(
sqlStatement
instanceof
UseStatement
)
{
result
=
new
IgnoreRoutingEngine
();
}
else
if
(
shardingRule
.
isAllBroadcastTables
(
tableNames
)
&&
!(
sqlStatement
instanceof
SelectStatement
))
{
result
=
new
DatabaseBroadcastRoutingEngine
(
shardingRule
);
}
else
if
(
sqlStatement
instanceof
DDLStatement
||
(
sqlStatement
instanceof
DCLStatement
&&
((
DCLStatement
)
sqlStatement
).
isGrantForSingleTable
()))
{
result
=
new
TableBroadcastRoutingEngine
(
shardingRule
,
sqlStatement
);
}
else
if
(
sqlStatement
instanceof
ShowDatabasesStatement
||
((
sqlStatement
instanceof
ShowTablesStatement
||
sqlStatement
instanceof
ShowTableStatusStatement
)
&&
tableNames
.
isEmpty
())
||
sqlStatement
instanceof
SetParamStatement
||
sqlStatement
instanceof
ResetParamStatement
)
{
result
=
new
DatabaseBroadcastRoutingEngine
(
shardingRule
);
}
else
if
(
sqlStatement
instanceof
DCLStatement
)
{
result
=
new
InstanceBroadcastRoutingEngine
(
shardingRule
,
shardingDataSourceMetaData
);
}
else
if
(
shardingRule
.
isAllInDefaultDataSource
(
tableNames
))
{
result
=
new
DefaultDatabaseRoutingEngine
(
shardingRule
,
tableNames
);
}
else
if
(
shardingConditions
.
isAlwaysFalse
())
{
result
=
new
UnicastRoutingEngine
(
shardingRule
,
tableNames
);
}
else
if
(
sqlStatement
instanceof
DALStatement
)
{
result
=
new
UnicastRoutingEngine
(
shardingRule
,
tableNames
);
}
else
if
(
tableNames
.
isEmpty
()
&&
sqlStatement
instanceof
SelectStatement
||
shardingRule
.
isAllBroadcastTables
(
tableNames
)
&&
sqlStatement
instanceof
SelectStatement
)
{
result
=
new
UnicastRoutingEngine
(
shardingRule
,
tableNames
);
}
else
if
(
tableNames
.
isEmpty
())
{
result
=
new
DatabaseBroadcastRoutingEngine
(
shardingRule
);
}
else
if
(
1
==
WithOutBroadcastTableNames
.
size
()
||
shardingRule
.
isAllBindingTables
(
WithOutBroadcastTableNames
))
{
result
=
new
StandardRoutingEngine
(
shardingRule
,
WithOutBroadcastTableNames
.
iterator
().
next
(),
shardingConditions
);
}
else
{
// TODO config for cartesian set
result
=
new
ComplexRoutingEngine
(
shardingRule
,
tableNames
,
shardingConditions
);
return
new
IgnoreRoutingEngine
();
}
return
result
;
if
(
isDatabaseAdministrationCommand
(
sqlStatement
,
tableNames
)
||
isDMLBroadcastTable
(
shardingRule
,
sqlStatement
,
tableNames
))
{
return
new
DatabaseBroadcastRoutingEngine
(
shardingRule
);
}
if
(
sqlStatement
instanceof
DDLStatement
||
isDCLForTable
(
sqlStatement
))
{
return
new
TableBroadcastRoutingEngine
(
shardingRule
,
sqlStatement
);
}
if
(
sqlStatement
instanceof
DCLStatement
)
{
return
new
InstanceBroadcastRoutingEngine
(
shardingRule
,
shardingDataSourceMetaData
);
}
if
(
shardingRule
.
isAllInDefaultDataSource
(
tableNames
))
{
return
new
DefaultDatabaseRoutingEngine
(
shardingRule
,
tableNames
);
}
if
(
shardingConditions
.
isAlwaysFalse
())
{
return
new
UnicastRoutingEngine
(
shardingRule
,
tableNames
);
}
if
(
sqlStatement
instanceof
DALStatement
)
{
return
new
UnicastRoutingEngine
(
shardingRule
,
tableNames
);
}
if
(
isUnicastDQL
(
shardingRule
,
sqlStatement
,
tableNames
))
{
return
new
UnicastRoutingEngine
(
shardingRule
,
tableNames
);
}
if
(
tableNames
.
isEmpty
())
{
return
new
DatabaseBroadcastRoutingEngine
(
shardingRule
);
}
Collection
<
String
>
shardingTableNames
=
shardingRule
.
getShardingLogicTableNames
(
tableNames
);
if
(
1
==
shardingTableNames
.
size
()
||
shardingRule
.
isAllBindingTables
(
shardingTableNames
))
{
return
new
StandardRoutingEngine
(
shardingRule
,
shardingTableNames
.
iterator
().
next
(),
shardingConditions
);
}
// TODO config for cartesian set
return
new
ComplexRoutingEngine
(
shardingRule
,
tableNames
,
shardingConditions
);
}
private
static
Collection
<
String
>
removeBroadcastTables
(
final
ShardingRule
shardingRule
,
final
Collection
<
String
>
tableNames
)
{
Collection
<
String
>
result
=
new
LinkedList
<>();
for
(
String
each
:
tableNames
)
{
if
(!
shardingRule
.
getBroadcastTables
().
contains
(
each
))
{
result
.
add
(
each
);
}
}
return
result
;
private
static
boolean
isDatabaseAdministrationCommand
(
final
SQLStatement
sqlStatement
,
final
Collection
<
String
>
tableNames
)
{
return
sqlStatement
instanceof
ShowDatabasesStatement
||
((
sqlStatement
instanceof
ShowTablesStatement
||
sqlStatement
instanceof
ShowTableStatusStatement
)
&&
tableNames
.
isEmpty
())
||
sqlStatement
instanceof
SetParamStatement
||
sqlStatement
instanceof
ResetParamStatement
;
}
private
static
boolean
isDMLBroadcastTable
(
final
ShardingRule
shardingRule
,
final
SQLStatement
sqlStatement
,
final
Collection
<
String
>
tableNames
)
{
return
sqlStatement
instanceof
DMLStatement
&&
shardingRule
.
isAllBroadcastTables
(
tableNames
);
}
private
static
boolean
isDCLForTable
(
final
SQLStatement
sqlStatement
)
{
return
sqlStatement
instanceof
DCLStatement
&&
((
DCLStatement
)
sqlStatement
).
isGrantForSingleTable
();
}
private
static
boolean
isUnicastDQL
(
final
ShardingRule
shardingRule
,
final
SQLStatement
sqlStatement
,
final
Collection
<
String
>
tableNames
)
{
return
sqlStatement
instanceof
SelectStatement
&&
(
tableNames
.
isEmpty
()
||
shardingRule
.
isAllBroadcastTables
(
tableNames
));
}
}
sharding-core/src/main/java/io/shardingsphere/core/routing/type/RoutingResult.java
浏览文件 @
e73924b0
...
...
@@ -30,7 +30,7 @@ public class RoutingResult {
private
final
TableUnits
tableUnits
=
new
TableUnits
();
/**
*
Adjust
is route for single database and table only or not.
*
Judge
is route for single database and table only or not.
*
* @return is route for single database and table only or not
*/
...
...
sharding-core/src/main/java/io/shardingsphere/core/rule/BindingTableRule.java
浏览文件 @
e73924b0
...
...
@@ -40,7 +40,7 @@ public final class BindingTableRule {
private
final
List
<
TableRule
>
tableRules
;
/**
*
Adjust
contains this logic table in this rule.
*
Judge
contains this logic table in this rule.
*
* @param logicTableName logic table name
* @return contains this logic table or not
...
...
sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java
浏览文件 @
e73924b0
...
...
@@ -172,17 +172,22 @@ public class ShardingRule {
}
/**
*
Adjust
logic table is belong to broadcast tables.
*
Judge
logic table is belong to broadcast tables.
*
* @param logicTable logic table name
* @param logicTable
Name
logic table name
* @return logic table is belong to broadcast tables or not
*/
public
boolean
isBroadcastTable
(
final
String
logicTable
)
{
return
broadcastTables
.
contains
(
logicTable
);
public
boolean
isBroadcastTable
(
final
String
logicTableName
)
{
for
(
String
each
:
broadcastTables
)
{
if
(
each
.
equalsIgnoreCase
(
logicTableName
))
{
return
true
;
}
}
return
false
;
}
/**
*
Adjust
logic tables is all belong to broadcast tables.
*
Judge
logic tables is all belong to broadcast tables.
*
* @param logicTables names of logic tables
* @return logic tables is all belong to broadcast tables or not
...
...
@@ -200,7 +205,7 @@ public class ShardingRule {
}
/**
*
Adjust
logic tables is all belong to binding tables.
*
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
...
...
@@ -219,21 +224,18 @@ public class ShardingRule {
}
/**
*
Adjust
logic tables is all belong to default data source.
*
Judge
logic tables is all belong to default data source.
*
* @param logicTable
s names of logic tabl
es
* @param logicTable
Names logic table nam
es
* @return logic tables is all belong to default data source
*/
public
boolean
isAllInDefaultDataSource
(
final
Collection
<
String
>
logicTables
)
{
for
(
String
each
:
logicTables
)
{
if
(
findTableRuleByLogicTable
(
each
).
isPresent
())
{
return
false
;
}
if
(
isBroadcastTable
(
each
))
{
public
boolean
isAllInDefaultDataSource
(
final
Collection
<
String
>
logicTableNames
)
{
for
(
String
each
:
logicTableNames
)
{
if
(
findTableRuleByLogicTable
(
each
).
isPresent
()
||
isBroadcastTable
(
each
))
{
return
false
;
}
}
return
!
logicTables
.
isEmpty
();
return
!
logicTable
Name
s
.
isEmpty
();
}
private
Optional
<
BindingTableRule
>
findBindingTableRule
(
final
Collection
<
String
>
logicTables
)
{
...
...
@@ -262,7 +264,7 @@ public class ShardingRule {
}
/**
*
Adjust
is sharding column or not.
*
Judge
is sharding column or not.
*
* @param column column object
* @return is sharding column or not
...
...
@@ -361,7 +363,7 @@ public class ShardingRule {
}
/**
*
Adjust
is logic index or not.
*
Judge
is logic index or not.
*
* @param logicIndexName logic index name
* @param logicTableName logic table name
...
...
@@ -428,7 +430,7 @@ public class ShardingRule {
}
/**
*
Adjust
contains table in sharding rule.
*
Judge
contains table in sharding rule.
*
* @param tableName table name
* @return contains table in sharding rule or not
...
...
@@ -436,4 +438,21 @@ public class ShardingRule {
public
boolean
contains
(
final
String
tableName
)
{
return
findTableRuleByLogicTable
(
tableName
).
isPresent
()
||
findBindingTableRule
(
tableName
).
isPresent
()
||
isBroadcastTable
(
tableName
);
}
/**
* Get sharding logic table names.
*
* @param logicTableNames logic table names
* @return sharding logic table names
*/
public
Collection
<
String
>
getShardingLogicTableNames
(
final
Collection
<
String
>
logicTableNames
)
{
Collection
<
String
>
result
=
new
LinkedList
<>();
for
(
String
each
:
logicTableNames
)
{
Optional
<
TableRule
>
tableRule
=
findTableRuleByLogicTable
(
each
);
if
(
tableRule
.
isPresent
())
{
result
.
add
(
each
);
}
}
return
result
;
}
}
sharding-core/src/main/java/io/shardingsphere/core/util/StringUtil.java
浏览文件 @
e73924b0
...
...
@@ -32,9 +32,9 @@ import java.util.List;
public
final
class
StringUtil
{
/**
*
Adjust
is boolean value or not.
*
Judge
is boolean value or not.
*
* @param value to be
adjust
ed string value
* @param value to be
judg
ed string value
* @return is boolean value or not
*/
public
static
boolean
isBooleanValue
(
final
String
value
)
{
...
...
@@ -42,9 +42,9 @@ public final class StringUtil {
}
/**
*
Adjust
is int value or not.
*
Judge
is int value or not.
*
* @param value to be
adjust
ed string value
* @param value to be
judg
ed string value
* @return is int value or not
*/
public
static
boolean
isIntValue
(
final
String
value
)
{
...
...
@@ -57,9 +57,9 @@ public final class StringUtil {
}
/**
*
Adjust
is long value or not.
*
Judge
is long value or not.
*
* @param value to be
adjust
ed string value
* @param value to be
judg
ed string value
* @return is long value or not
*/
public
static
boolean
isLongValue
(
final
String
value
)
{
...
...
sharding-core/src/test/java/io/shardingsphere/core/rule/ShardingRuleTest.java
浏览文件 @
e73924b0
...
...
@@ -27,6 +27,7 @@ import io.shardingsphere.core.exception.ShardingConfigurationException;
import
io.shardingsphere.core.keygen.fixture.IncrementKeyGenerator
;
import
io.shardingsphere.core.parsing.parser.context.condition.Column
;
import
io.shardingsphere.core.routing.strategy.none.NoneShardingStrategy
;
import
org.hamcrest.CoreMatchers
;
import
org.junit.Test
;
import
java.util.Arrays
;
...
...
@@ -324,12 +325,20 @@ public final class ShardingRuleTest {
@Test
public
void
assertIsAllInDefaultDataSource
()
{
ShardingRuleConfiguration
shardingRuleConfig
=
new
ShardingRuleConfiguration
();
TableRuleConfiguration
tableRuleConfig
=
createTableRuleConfig
();
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
tableRuleConfig
);
ShardingRule
actual
=
new
ShardingRule
(
shardingRuleConfig
,
createDataSourceNames
());
ShardingRule
actual
=
createShardingRule
();
assertTrue
(
actual
.
isAllInDefaultDataSource
(
Collections
.
singletonList
(
"table_0"
)));
assertFalse
(
actual
.
isAllInDefaultDataSource
(
Collections
.
singletonList
(
"logic_table"
)));
}
@Test
public
void
assertIsNotAllInDefaultDataSourceWithShardingTable
()
{
ShardingRule
actual
=
createShardingRule
();
assertFalse
(
actual
.
isAllInDefaultDataSource
(
Arrays
.
asList
(
"table_0"
,
"logic_table"
)));
}
@Test
public
void
assertIsNotAllInDefaultDataSourceWithBroadcastTable
()
{
ShardingRule
actual
=
createShardingRule
();
assertFalse
(
actual
.
isAllInDefaultDataSource
(
Arrays
.
asList
(
"table_0"
,
"broadcast_logic_table"
)));
}
@Test
...
...
@@ -437,6 +446,12 @@ public final class ShardingRuleTest {
assertFalse
(
createShardingRule
().
contains
(
"NEW_TABLE"
));
}
@Test
public
void
assertGetShardingLogicTableNames
()
{
ShardingRule
actual
=
createShardingRule
();
assertThat
(
actual
.
getShardingLogicTableNames
(
Arrays
.
asList
(
"LOGIC_TABLE"
,
"BROADCAST_LOGIC_TABLE"
)),
CoreMatchers
.<
Collection
<
String
>>
is
(
Collections
.
singletonList
(
"LOGIC_TABLE"
)));
}
private
ShardingRule
createShardingRule
()
{
ShardingRuleConfiguration
shardingRuleConfig
=
new
ShardingRuleConfiguration
();
TableRuleConfiguration
tableRuleConfig
=
createTableRuleConfig
();
...
...
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-api/src/main/java/io/shardingsphere/orchestration/reg/api/RegistryCenter.java
浏览文件 @
e73924b0
...
...
@@ -56,7 +56,7 @@ public interface RegistryCenter extends AutoCloseable {
String
getDirectly
(
String
key
);
/**
*
Adjust
data is existed or not.
*
Judge
data is existed or not.
*
* @param key key of data
* @return data is existed or not
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录