Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
75d28f9d
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,发现更多精彩内容 >>
提交
75d28f9d
编写于
3月 19, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
IllegalStateException => ShardingRuleException for rule package
上级
560a8e00
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
15 addition
and
9 deletion
+15
-9
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/BindingTableRule.java
...main/java/io/shardingjdbc/core/rule/BindingTableRule.java
+3
-2
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/DataNode.java
...ore/src/main/java/io/shardingjdbc/core/rule/DataNode.java
+3
-2
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/TableRule.java
...re/src/main/java/io/shardingjdbc/core/rule/TableRule.java
+4
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/rule/BindingTableRuleTest.java
.../java/io/shardingjdbc/core/rule/BindingTableRuleTest.java
+1
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/rule/DataNodeTest.java
...src/test/java/io/shardingjdbc/core/rule/DataNodeTest.java
+2
-2
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/yaml/sharding/YamlShardingDataSourceTest.java
...ngjdbc/core/yaml/sharding/YamlShardingDataSourceTest.java
+2
-1
未找到文件。
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/BindingTableRule.java
浏览文件 @
75d28f9d
...
...
@@ -18,7 +18,6 @@
package
io.shardingjdbc.core.rule
;
import
com.google.common.base.Function
;
import
com.google.common.base.Preconditions
;
import
com.google.common.collect.Lists
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
...
...
@@ -70,7 +69,9 @@ public final class BindingTableRule {
break
;
}
}
Preconditions
.
checkState
(-
1
!=
index
,
String
.
format
(
"Actual table [%s].[%s] is not in table config"
,
dataSource
,
otherActualTable
));
if
(-
1
==
index
)
{
throw
new
ShardingRuleException
(
"Actual table [%s].[%s] is not in table config"
,
dataSource
,
otherActualTable
);
}
for
(
TableRule
each
:
tableRules
)
{
if
(
each
.
getLogicTable
().
equals
(
logicTable
.
toLowerCase
()))
{
return
each
.
getActualDataNodes
().
get
(
index
).
getTableName
().
toLowerCase
();
...
...
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/DataNode.java
浏览文件 @
75d28f9d
...
...
@@ -17,7 +17,6 @@
package
io.shardingjdbc.core.rule
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Splitter
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
...
...
@@ -49,7 +48,9 @@ public class DataNode {
* @param dataNode string of data node. use {@code .} to split data source name and table name.
*/
public
DataNode
(
final
String
dataNode
)
{
Preconditions
.
checkArgument
(
DataNode
.
isValidDataNode
(
dataNode
),
String
.
format
(
"Invalid format for actual data nodes: '%s'"
,
dataNode
));
if
(!
isValidDataNode
(
dataNode
))
{
throw
new
ShardingRuleException
(
"Invalid format for actual data nodes: '%s'"
,
dataNode
);
}
List
<
String
>
segments
=
Splitter
.
on
(
DELIMITER
).
splitToList
(
dataNode
);
dataSourceName
=
segments
.
get
(
0
);
tableName
=
segments
.
get
(
1
);
...
...
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/TableRule.java
浏览文件 @
75d28f9d
...
...
@@ -18,6 +18,7 @@
package
io.shardingjdbc.core.rule
;
import
com.google.common.base.Preconditions
;
import
io.shardingjdbc.core.exception.ShardingJdbcException
;
import
io.shardingjdbc.core.keygen.KeyGenerator
;
import
io.shardingjdbc.core.routing.strategy.ShardingStrategy
;
import
lombok.Getter
;
...
...
@@ -77,7 +78,9 @@ public final class TableRule {
List
<
DataNode
>
result
=
new
LinkedList
<>();
for
(
String
each
:
actualDataNodes
)
{
DataNode
dataNode
=
new
DataNode
(
each
);
Preconditions
.
checkArgument
(
dataSourceMap
.
containsKey
(
dataNode
.
getDataSourceName
()),
String
.
format
(
"Cannot find data source in sharding rule, invalid actual data node is: '%s'"
,
each
));
if
(!
dataSourceMap
.
containsKey
(
dataNode
.
getDataSourceName
()))
{
throw
new
ShardingJdbcException
(
"Cannot find data source in sharding rule, invalid actual data node is: '%s'"
,
each
);
}
result
.
add
(
dataNode
);
}
return
result
;
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/rule/BindingTableRuleTest.java
浏览文件 @
75d28f9d
...
...
@@ -48,7 +48,7 @@ public final class BindingTableRuleTest {
assertThat
(
createBindingTableRule
().
getBindingActualTable
(
"ds1"
,
"Sub_Logic_Table"
,
"table_1"
),
is
(
"sub_table_1"
));
}
@Test
(
expected
=
IllegalStat
eException
.
class
)
@Test
(
expected
=
ShardingRul
eException
.
class
)
public
void
assertGetBindingActualTablesFailureWhenNotFound
()
{
createBindingTableRule
().
getBindingActualTable
(
"no_ds"
,
"Sub_Logic_Table"
,
"table_1"
);
}
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/rule/DataNodeTest.java
浏览文件 @
75d28f9d
...
...
@@ -31,12 +31,12 @@ public class DataNodeTest {
assertThat
(
dataNode
.
getTableName
(),
is
(
"tbl_0"
));
}
@Test
(
expected
=
IllegalArgument
Exception
.
class
)
@Test
(
expected
=
ShardingRule
Exception
.
class
)
public
void
assertNewInValidDataNodeWithoutDelimiter
()
{
new
DataNode
(
"ds_0tbl_0"
);
}
@Test
(
expected
=
IllegalArgument
Exception
.
class
)
@Test
(
expected
=
ShardingRule
Exception
.
class
)
public
void
assertNewInValidDataNodeWithTwoDelimiters
()
{
new
DataNode
(
"ds_0.tbl_0.tbl_1"
);
}
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/yaml/sharding/YamlShardingDataSourceTest.java
浏览文件 @
75d28f9d
...
...
@@ -23,6 +23,7 @@ import io.shardingjdbc.core.jdbc.core.ShardingContext;
import
io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource
;
import
io.shardingjdbc.core.rule.BindingTableRule
;
import
io.shardingjdbc.core.rule.ShardingRule
;
import
io.shardingjdbc.core.rule.ShardingRuleException
;
import
org.apache.commons.dbcp.BasicDataSource
;
import
org.h2.Driver
;
import
org.junit.Test
;
...
...
@@ -65,7 +66,7 @@ public class YamlShardingDataSourceTest {
getShardingRule
(
"/yaml/config/config-classNotFound.yaml"
);
}
@Test
(
expected
=
IllegalStat
eException
.
class
)
@Test
(
expected
=
ShardingRul
eException
.
class
)
public
void
assertBindingError
()
throws
SQLException
,
IOException
,
URISyntaxException
,
ReflectiveOperationException
{
Map
<
String
,
DataSource
>
dataSourceMap
=
new
HashMap
<>(
1
);
dataSourceMap
.
put
(
"ds"
,
createDataSource
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录