Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
dd056c11
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,发现更多精彩内容 >>
提交
dd056c11
编写于
3月 27, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
For #673: polish TableRuleConfiguration
上级
57300a63
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
17 addition
and
16 deletion
+17
-16
sharding-core/src/main/java/io/shardingjdbc/core/api/config/TableRuleConfiguration.java
.../shardingjdbc/core/api/config/TableRuleConfiguration.java
+2
-1
sharding-core/src/main/java/io/shardingjdbc/core/rule/TableRule.java
...re/src/main/java/io/shardingjdbc/core/rule/TableRule.java
+1
-7
sharding-core/src/main/java/io/shardingjdbc/core/yaml/sharding/YamlTableRuleConfiguration.java
...ngjdbc/core/yaml/sharding/YamlTableRuleConfiguration.java
+5
-1
sharding-core/src/test/java/io/shardingjdbc/core/rule/TableRuleTest.java
...rc/test/java/io/shardingjdbc/core/rule/TableRuleTest.java
+1
-1
sharding-core/src/test/java/io/shardingjdbc/core/yaml/sharding/YamlTableRuleConfigurationTest.java
...bc/core/yaml/sharding/YamlTableRuleConfigurationTest.java
+1
-1
sharding-jdbc-core-spring/sharding-jdbc-core-spring-namespace/src/main/java/io/shardingjdbc/spring/namespace/parser/ShardingDataSourceBeanDefinitionParser.java
...espace/parser/ShardingDataSourceBeanDefinitionParser.java
+2
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java
...common/base/AbstractShardingJDBCDatabaseAndTableTest.java
+1
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/integrate/type/sharding/AbstractShardingDatabaseOnlyTest.java
...grate/type/sharding/AbstractShardingDatabaseOnlyTest.java
+1
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/integrate/type/sharding/AbstractShardingTableOnlyTest.java
...ntegrate/type/sharding/AbstractShardingTableOnlyTest.java
+1
-1
sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingjdbc/orchestration/spring/namespace/parser/OrchestrationShardingDataSourceBeanDefinitionParser.java
.../OrchestrationShardingDataSourceBeanDefinitionParser.java
+2
-1
未找到文件。
sharding-core/src/main/java/io/shardingjdbc/core/api/config/TableRuleConfiguration.java
浏览文件 @
dd056c11
...
...
@@ -18,6 +18,7 @@
package
io.shardingjdbc.core.api.config
;
import
io.shardingjdbc.core.api.config.strategy.ShardingStrategyConfiguration
;
import
io.shardingjdbc.core.keygen.KeyGenerator
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -40,7 +41,7 @@ public final class TableRuleConfiguration {
private
String
keyGeneratorColumnName
;
private
String
keyGeneratorClass
;
private
KeyGenerator
keyGenerator
;
private
String
logicIndex
;
}
sharding-core/src/main/java/io/shardingjdbc/core/rule/TableRule.java
浏览文件 @
dd056c11
...
...
@@ -18,11 +18,9 @@
package
io.shardingjdbc.core.rule
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Strings
;
import
io.shardingjdbc.core.api.config.TableRuleConfiguration
;
import
io.shardingjdbc.core.exception.ShardingJdbcException
;
import
io.shardingjdbc.core.keygen.KeyGenerator
;
import
io.shardingjdbc.core.keygen.KeyGeneratorFactory
;
import
io.shardingjdbc.core.routing.strategy.ShardingStrategy
;
import
io.shardingjdbc.core.routing.strategy.ShardingStrategyFactory
;
import
io.shardingjdbc.core.util.InlineExpressionParser
;
...
...
@@ -64,7 +62,7 @@ public final class TableRule {
databaseShardingStrategy
=
null
==
tableRuleConfig
.
getDatabaseShardingStrategyConfig
()
?
null
:
ShardingStrategyFactory
.
newInstance
(
tableRuleConfig
.
getDatabaseShardingStrategyConfig
());
tableShardingStrategy
=
null
==
tableRuleConfig
.
getTableShardingStrategyConfig
()
?
null
:
ShardingStrategyFactory
.
newInstance
(
tableRuleConfig
.
getTableShardingStrategyConfig
());
generateKeyColumn
=
tableRuleConfig
.
getKeyGeneratorColumnName
();
keyGenerator
=
!
hasKeyGenerator
(
tableRuleConfig
)
?
null
:
KeyGeneratorFactory
.
newInstance
(
tableRuleConfig
.
getKeyGeneratorClass
()
);
keyGenerator
=
tableRuleConfig
.
getKeyGenerator
(
);
logicIndex
=
null
==
tableRuleConfig
.
getLogicIndex
()
?
null
:
tableRuleConfig
.
getLogicIndex
().
toLowerCase
();
Preconditions
.
checkNotNull
(
logicTable
);
}
...
...
@@ -93,10 +91,6 @@ public final class TableRule {
return
result
;
}
private
boolean
hasKeyGenerator
(
final
TableRuleConfiguration
tableRuleConfig
)
{
return
!
Strings
.
isNullOrEmpty
(
generateKeyColumn
)
&&
!
Strings
.
isNullOrEmpty
(
tableRuleConfig
.
getKeyGeneratorClass
());
}
/**
* Get actual data source names.
*
...
...
sharding-core/src/main/java/io/shardingjdbc/core/yaml/sharding/YamlTableRuleConfiguration.java
浏览文件 @
dd056c11
...
...
@@ -18,7 +18,9 @@
package
io.shardingjdbc.core.yaml.sharding
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Strings
;
import
io.shardingjdbc.core.api.config.TableRuleConfiguration
;
import
io.shardingjdbc.core.keygen.KeyGeneratorFactory
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -61,7 +63,9 @@ public class YamlTableRuleConfiguration {
if
(
null
!=
tableStrategy
)
{
result
.
setTableShardingStrategyConfig
(
tableStrategy
.
build
());
}
result
.
setKeyGeneratorClass
(
keyGeneratorClass
);
if
(!
Strings
.
isNullOrEmpty
(
keyGeneratorClass
))
{
result
.
setKeyGenerator
(
KeyGeneratorFactory
.
newInstance
(
keyGeneratorClass
));
}
result
.
setKeyGeneratorColumnName
(
keyGeneratorColumnName
);
result
.
setLogicIndex
(
logicIndex
);
return
result
;
...
...
sharding-core/src/test/java/io/shardingjdbc/core/rule/TableRuleTest.java
浏览文件 @
dd056c11
...
...
@@ -59,7 +59,7 @@ public final class TableRuleTest {
tableRuleConfig
.
setDatabaseShardingStrategyConfig
(
new
NoneShardingStrategyConfiguration
());
tableRuleConfig
.
setTableShardingStrategyConfig
(
new
NoneShardingStrategyConfiguration
());
tableRuleConfig
.
setKeyGeneratorColumnName
(
"col_1"
);
tableRuleConfig
.
setKeyGenerator
Class
(
IncrementKeyGenerator
.
class
.
getName
());
tableRuleConfig
.
setKeyGenerator
(
new
IncrementKeyGenerator
());
tableRuleConfig
.
setLogicIndex
(
"LOGIC_INDEX"
);
TableRule
actual
=
new
TableRule
(
tableRuleConfig
,
createDataSourceNames
());
assertThat
(
actual
.
getLogicTable
(),
is
(
"logic_table"
));
...
...
sharding-core/src/test/java/io/shardingjdbc/core/yaml/sharding/YamlTableRuleConfigurationTest.java
浏览文件 @
dd056c11
...
...
@@ -72,7 +72,7 @@ public final class YamlTableRuleConfigurationTest {
assertThat
(
actual
.
getLogicTable
(),
is
(
"t_order"
));
assertThat
(
actual
.
getActualDataNodes
(),
is
(
"ds_${0..1}.t_order_${0..1}"
));
assertThat
(
actual
.
getKeyGeneratorColumnName
(),
is
(
"order_id"
));
assertThat
(
actual
.
getKeyGenerator
Class
(),
is
(
DefaultKeyGenerator
.
class
.
getName
()
));
assertThat
(
actual
.
getKeyGenerator
(),
instanceOf
(
DefaultKeyGenerator
.
class
));
assertThat
(
actual
.
getLogicIndex
(),
is
(
"order_index"
));
}
...
...
sharding-jdbc-core-spring/sharding-jdbc-core-spring-namespace/src/main/java/io/shardingjdbc/spring/namespace/parser/ShardingDataSourceBeanDefinitionParser.java
浏览文件 @
dd056c11
...
...
@@ -21,6 +21,7 @@ import com.google.common.base.Splitter;
import
com.google.common.base.Strings
;
import
io.shardingjdbc.core.api.config.ShardingRuleConfiguration
;
import
io.shardingjdbc.core.api.config.TableRuleConfiguration
;
import
io.shardingjdbc.core.keygen.KeyGeneratorFactory
;
import
io.shardingjdbc.spring.datasource.SpringShardingDataSource
;
import
io.shardingjdbc.spring.namespace.constants.ShardingDataSourceBeanDefinitionParserTag
;
import
org.springframework.beans.factory.config.BeanDefinition
;
...
...
@@ -139,7 +140,7 @@ public class ShardingDataSourceBeanDefinitionParser extends AbstractBeanDefiniti
}
String
keyGeneratorClass
=
tableElement
.
getAttribute
(
ShardingDataSourceBeanDefinitionParserTag
.
COLUMN_KEY_GENERATOR_CLASS
);
if
(!
Strings
.
isNullOrEmpty
(
keyGeneratorClass
))
{
factory
.
addPropertyValue
(
"keyGenerator
Class"
,
keyGeneratorClass
);
factory
.
addPropertyValue
(
"keyGenerator
"
,
KeyGeneratorFactory
.
newInstance
(
keyGeneratorClass
)
);
}
String
logicIndex
=
tableElement
.
getAttribute
(
ShardingDataSourceBeanDefinitionParserTag
.
LOGIC_INDEX
);
if
(!
Strings
.
isNullOrEmpty
(
logicIndex
))
{
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java
浏览文件 @
dd056c11
...
...
@@ -78,7 +78,7 @@ public abstract class AbstractShardingJDBCDatabaseAndTableTest extends AbstractS
}
orderItemTableRuleConfig
.
setActualDataNodes
(
Joiner
.
on
(
","
).
join
(
orderItemActualDataNodes
));
orderItemTableRuleConfig
.
setKeyGeneratorColumnName
(
"item_id"
);
orderItemTableRuleConfig
.
setKeyGenerator
Class
(
IncrementKeyGenerator
.
class
.
getName
());
orderItemTableRuleConfig
.
setKeyGenerator
(
new
IncrementKeyGenerator
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
orderItemTableRuleConfig
);
TableRuleConfiguration
configTableRuleConfig
=
new
TableRuleConfiguration
();
configTableRuleConfig
.
setLogicTable
(
"t_config"
);
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/integrate/type/sharding/AbstractShardingDatabaseOnlyTest.java
浏览文件 @
dd056c11
...
...
@@ -77,7 +77,7 @@ public abstract class AbstractShardingDatabaseOnlyTest extends AbstractSQLAssert
orderTableRuleConfig
.
setLogicTable
(
"t_order"
);
orderTableRuleConfig
.
setLogicIndex
(
"t_order_index"
);
orderTableRuleConfig
.
setKeyGeneratorColumnName
(
"order_id"
);
orderTableRuleConfig
.
setKeyGenerator
Class
(
IncrementKeyGenerator
.
class
.
getName
());
orderTableRuleConfig
.
setKeyGenerator
(
new
IncrementKeyGenerator
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
orderTableRuleConfig
);
TableRuleConfiguration
orderItemTableRuleConfig
=
new
TableRuleConfiguration
();
orderItemTableRuleConfig
.
setLogicTable
(
"t_order_item"
);
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/integrate/type/sharding/AbstractShardingTableOnlyTest.java
浏览文件 @
dd056c11
...
...
@@ -81,7 +81,7 @@ public abstract class AbstractShardingTableOnlyTest extends AbstractSQLAssertTes
}
orderItemTableRuleConfig
.
setActualDataNodes
(
Joiner
.
on
(
","
).
join
(
orderItemActualDataNodes
));
orderItemTableRuleConfig
.
setLogicTable
(
"t_order_item"
);
orderItemTableRuleConfig
.
setKeyGeneratorC
lass
(
"item_id"
);
orderItemTableRuleConfig
.
setKeyGeneratorC
olumnName
(
"item_id"
);
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
orderItemTableRuleConfig
);
TableRuleConfiguration
logTableRuleConfig
=
new
TableRuleConfiguration
();
logTableRuleConfig
.
setLogicIndex
(
"t_log_index"
);
...
...
sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingjdbc/orchestration/spring/namespace/parser/OrchestrationShardingDataSourceBeanDefinitionParser.java
浏览文件 @
dd056c11
...
...
@@ -21,6 +21,7 @@ import com.google.common.base.Splitter;
import
com.google.common.base.Strings
;
import
io.shardingjdbc.core.api.config.ShardingRuleConfiguration
;
import
io.shardingjdbc.core.api.config.TableRuleConfiguration
;
import
io.shardingjdbc.core.keygen.KeyGeneratorFactory
;
import
io.shardingjdbc.orchestration.internal.OrchestrationShardingDataSource
;
import
io.shardingjdbc.orchestration.spring.namespace.constants.ShardingDataSourceBeanDefinitionParserTag
;
import
org.springframework.beans.factory.config.BeanDefinition
;
...
...
@@ -141,7 +142,7 @@ public class OrchestrationShardingDataSourceBeanDefinitionParser extends Abstrac
}
String
keyGeneratorClass
=
tableElement
.
getAttribute
(
ShardingDataSourceBeanDefinitionParserTag
.
COLUMN_KEY_GENERATOR_CLASS
);
if
(!
Strings
.
isNullOrEmpty
(
keyGeneratorClass
))
{
factory
.
addPropertyValue
(
"keyGenerator
Class"
,
keyGeneratorClass
);
factory
.
addPropertyValue
(
"keyGenerator
"
,
KeyGeneratorFactory
.
newInstance
(
keyGeneratorClass
)
);
}
String
logicIndex
=
tableElement
.
getAttribute
(
ShardingDataSourceBeanDefinitionParserTag
.
LOGIC_INDEX_ATTRIBUTE
);
if
(!
Strings
.
isNullOrEmpty
(
logicIndex
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录