Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
5864f901
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,发现更多精彩内容 >>
提交
5864f901
编写于
3月 23, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
For #647: move transfer yaml to object to yaml package
上级
25588550
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
90 addition
and
48 deletion
+90
-48
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/api/MasterSlaveDataSourceFactory.java
...o/shardingjdbc/core/api/MasterSlaveDataSourceFactory.java
+8
-24
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/api/ShardingDataSourceFactory.java
...a/io/shardingjdbc/core/api/ShardingDataSourceFactory.java
+8
-24
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/yaml/masterslave/YamlMasterSlaveConfiguration.java
...c/core/yaml/masterslave/YamlMasterSlaveConfiguration.java
+37
-0
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/yaml/sharding/YamlShardingConfiguration.java
...ingjdbc/core/yaml/sharding/YamlShardingConfiguration.java
+37
-0
未找到文件。
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/api/MasterSlaveDataSourceFactory.java
浏览文件 @
5864f901
...
...
@@ -22,15 +22,10 @@ import io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource;
import
io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveConfiguration
;
import
lombok.AccessLevel
;
import
lombok.NoArgsConstructor
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.constructor.Constructor
;
import
javax.sql.DataSource
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.sql.SQLException
;
import
java.util.Map
;
...
...
@@ -69,7 +64,7 @@ public final class MasterSlaveDataSourceFactory {
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
File
yamlFile
)
throws
SQLException
,
IOException
{
YamlMasterSlaveConfiguration
config
=
unmarshal
(
yamlFile
);
YamlMasterSlaveConfiguration
config
=
YamlMasterSlaveConfiguration
.
unmarshal
(
yamlFile
);
return
new
MasterSlaveDataSource
(
config
.
getDataSources
(),
config
.
getMasterSlaveRule
().
getMasterSlaveRuleConfiguration
().
build
(),
config
.
getMasterSlaveRule
().
getConfigMap
());
}
...
...
@@ -85,7 +80,7 @@ public final class MasterSlaveDataSourceFactory {
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
File
yamlFile
)
throws
SQLException
,
IOException
{
YamlMasterSlaveConfiguration
config
=
unmarshal
(
yamlFile
);
YamlMasterSlaveConfiguration
config
=
YamlMasterSlaveConfiguration
.
unmarshal
(
yamlFile
);
return
new
MasterSlaveDataSource
(
dataSourceMap
,
config
.
getMasterSlaveRule
().
getMasterSlaveRuleConfiguration
().
build
(),
config
.
getMasterSlaveRule
().
getConfigMap
());
}
...
...
@@ -97,9 +92,10 @@ public final class MasterSlaveDataSourceFactory {
* @param yamlByteArray yaml byte array for master-slave rule configuration with data sources
* @return master-slave data source
* @throws SQLException SQL exception
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
byte
[]
yamlByteArray
)
throws
SQLException
{
YamlMasterSlaveConfiguration
config
=
unmarshal
(
yamlByteArray
);
public
static
DataSource
createDataSource
(
final
byte
[]
yamlByteArray
)
throws
SQLException
,
IOException
{
YamlMasterSlaveConfiguration
config
=
YamlMasterSlaveConfiguration
.
unmarshal
(
yamlByteArray
);
return
new
MasterSlaveDataSource
(
config
.
getDataSources
(),
config
.
getMasterSlaveRule
().
getMasterSlaveRuleConfiguration
().
build
(),
config
.
getMasterSlaveRule
().
getConfigMap
());
}
...
...
@@ -112,22 +108,10 @@ public final class MasterSlaveDataSourceFactory {
* @param yamlByteArray yaml byte array for master-slave rule configuration without data sources
* @return master-slave data source
* @throws SQLException SQL exception
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
byte
[]
yamlByteArray
)
throws
SQLException
{
YamlMasterSlaveConfiguration
config
=
unmarshal
(
yamlByteArray
);
public
static
DataSource
createDataSource
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
byte
[]
yamlByteArray
)
throws
SQLException
,
IOException
{
YamlMasterSlaveConfiguration
config
=
YamlMasterSlaveConfiguration
.
unmarshal
(
yamlByteArray
);
return
new
MasterSlaveDataSource
(
dataSourceMap
,
config
.
getMasterSlaveRule
().
getMasterSlaveRuleConfiguration
().
build
(),
config
.
getMasterSlaveRule
().
getConfigMap
());
}
private
static
YamlMasterSlaveConfiguration
unmarshal
(
final
File
yamlFile
)
throws
IOException
{
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
yamlFile
);
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
fileInputStream
,
"UTF-8"
)
)
{
return
new
Yaml
(
new
Constructor
(
YamlMasterSlaveConfiguration
.
class
)).
loadAs
(
inputStreamReader
,
YamlMasterSlaveConfiguration
.
class
);
}
}
private
static
YamlMasterSlaveConfiguration
unmarshal
(
final
byte
[]
yamlByteArray
)
{
return
new
Yaml
(
new
Constructor
(
YamlMasterSlaveConfiguration
.
class
)).
loadAs
(
new
ByteArrayInputStream
(
yamlByteArray
),
YamlMasterSlaveConfiguration
.
class
);
}
}
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/api/ShardingDataSourceFactory.java
浏览文件 @
5864f901
...
...
@@ -23,15 +23,10 @@ import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource;
import
io.shardingjdbc.core.yaml.sharding.YamlShardingConfiguration
;
import
lombok.AccessLevel
;
import
lombok.NoArgsConstructor
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.constructor.Constructor
;
import
javax.sql.DataSource
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.sql.SQLException
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
...
...
@@ -71,7 +66,7 @@ public final class ShardingDataSourceFactory {
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
File
yamlFile
)
throws
SQLException
,
IOException
{
YamlShardingConfiguration
config
=
unmarshal
(
yamlFile
);
YamlShardingConfiguration
config
=
YamlShardingConfiguration
.
unmarshal
(
yamlFile
);
Map
<
String
,
DataSource
>
dataSourceMap
=
config
.
getDataSources
();
processDataSourceMapWithMasterSlave
(
dataSourceMap
,
config
.
getShardingRule
().
getShardingRuleConfiguration
());
return
new
ShardingDataSource
(
dataSourceMap
,
config
.
getShardingRule
(
dataSourceMap
.
keySet
()),
config
.
getShardingRule
().
getConfigMap
(),
config
.
getShardingRule
().
getProps
());
...
...
@@ -87,7 +82,7 @@ public final class ShardingDataSourceFactory {
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
File
yamlFile
)
throws
SQLException
,
IOException
{
YamlShardingConfiguration
config
=
unmarshal
(
yamlFile
);
YamlShardingConfiguration
config
=
YamlShardingConfiguration
.
unmarshal
(
yamlFile
);
processDataSourceMapWithMasterSlave
(
dataSourceMap
,
config
.
getShardingRule
().
getShardingRuleConfiguration
());
return
new
ShardingDataSource
(
dataSourceMap
,
config
.
getShardingRule
(
dataSourceMap
.
keySet
()),
config
.
getShardingRule
().
getConfigMap
(),
config
.
getShardingRule
().
getProps
());
}
...
...
@@ -98,9 +93,10 @@ public final class ShardingDataSourceFactory {
* @param yamlByteArray yaml byte array for rule configuration of databases and tables sharding with data sources
* @return sharding data source
* @throws SQLException SQL exception
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
byte
[]
yamlByteArray
)
throws
SQLException
{
YamlShardingConfiguration
config
=
unmarshal
(
yamlByteArray
);
public
static
DataSource
createDataSource
(
final
byte
[]
yamlByteArray
)
throws
SQLException
,
IOException
{
YamlShardingConfiguration
config
=
YamlShardingConfiguration
.
unmarshal
(
yamlByteArray
);
Map
<
String
,
DataSource
>
dataSourceMap
=
config
.
getDataSources
();
processDataSourceMapWithMasterSlave
(
dataSourceMap
,
config
.
getShardingRule
().
getShardingRuleConfiguration
());
return
new
ShardingDataSource
(
dataSourceMap
,
config
.
getShardingRule
(
dataSourceMap
.
keySet
()),
config
.
getShardingRule
().
getConfigMap
(),
config
.
getShardingRule
().
getProps
());
...
...
@@ -113,26 +109,14 @@ public final class ShardingDataSourceFactory {
* @param yamlByteArray yaml byte array for rule configuration of databases and tables sharding without data sources
* @return sharding data source
* @throws SQLException SQL exception
* @throws IOException IO exception
*/
public
static
DataSource
createDataSource
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
byte
[]
yamlByteArray
)
throws
SQLException
{
YamlShardingConfiguration
config
=
unmarshal
(
yamlByteArray
);
public
static
DataSource
createDataSource
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
byte
[]
yamlByteArray
)
throws
SQLException
,
IOException
{
YamlShardingConfiguration
config
=
YamlShardingConfiguration
.
unmarshal
(
yamlByteArray
);
processDataSourceMapWithMasterSlave
(
dataSourceMap
,
config
.
getShardingRule
().
getShardingRuleConfiguration
());
return
new
ShardingDataSource
(
dataSourceMap
,
config
.
getShardingRule
(
dataSourceMap
.
keySet
()),
config
.
getShardingRule
().
getConfigMap
(),
config
.
getShardingRule
().
getProps
());
}
private
static
YamlShardingConfiguration
unmarshal
(
final
File
yamlFile
)
throws
IOException
{
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
yamlFile
);
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
fileInputStream
,
"UTF-8"
)
)
{
return
new
Yaml
(
new
Constructor
(
YamlShardingConfiguration
.
class
)).
loadAs
(
inputStreamReader
,
YamlShardingConfiguration
.
class
);
}
}
private
static
YamlShardingConfiguration
unmarshal
(
final
byte
[]
yamlByteArray
)
{
return
new
Yaml
(
new
Constructor
(
YamlShardingConfiguration
.
class
)).
loadAs
(
new
ByteArrayInputStream
(
yamlByteArray
),
YamlShardingConfiguration
.
class
);
}
private
static
void
processDataSourceMapWithMasterSlave
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
ShardingRuleConfiguration
shardingRuleConfiguration
)
throws
SQLException
{
for
(
MasterSlaveRuleConfiguration
each
:
shardingRuleConfiguration
.
getMasterSlaveRuleConfigs
())
{
processDataSourceMapWithMasterSlave
(
dataSourceMap
,
each
);
...
...
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/yaml/masterslave/YamlMasterSlaveConfiguration.java
浏览文件 @
5864f901
...
...
@@ -19,8 +19,16 @@ package io.shardingjdbc.core.yaml.masterslave;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.constructor.Constructor
;
import
javax.sql.DataSource
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -36,4 +44,33 @@ public class YamlMasterSlaveConfiguration {
private
Map
<
String
,
DataSource
>
dataSources
=
new
HashMap
<>();
private
YamlMasterSlaveRuleConfiguration
masterSlaveRule
;
/**
* Unmarshal yaml master slave configuration from yaml file.
*
* @param yamlFile yaml file
* @return yaml sharding configuration
* @throws IOException IO Exception
*/
public
static
YamlMasterSlaveConfiguration
unmarshal
(
final
File
yamlFile
)
throws
IOException
{
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
yamlFile
);
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
fileInputStream
,
"UTF-8"
)
)
{
return
new
Yaml
(
new
Constructor
(
YamlMasterSlaveConfiguration
.
class
)).
loadAs
(
inputStreamReader
,
YamlMasterSlaveConfiguration
.
class
);
}
}
/**
* Unmarshal yaml sharding configuration from yaml bytes.
*
* @param yamlBytes yaml bytes
* @return yaml sharding configuration
* @throws IOException IO Exception
*/
public
static
YamlMasterSlaveConfiguration
unmarshal
(
final
byte
[]
yamlBytes
)
throws
IOException
{
try
(
InputStream
inputStream
=
new
ByteArrayInputStream
(
yamlBytes
))
{
return
new
Yaml
(
new
Constructor
(
YamlMasterSlaveConfiguration
.
class
)).
loadAs
(
inputStream
,
YamlMasterSlaveConfiguration
.
class
);
}
}
}
sharding-jdbc-core/src/main/java/io/shardingjdbc/core/yaml/sharding/YamlShardingConfiguration.java
浏览文件 @
5864f901
...
...
@@ -20,8 +20,16 @@ package io.shardingjdbc.core.yaml.sharding;
import
io.shardingjdbc.core.rule.ShardingRule
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.constructor.Constructor
;
import
javax.sql.DataSource
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -39,6 +47,35 @@ public class YamlShardingConfiguration {
private
YamlShardingRuleConfiguration
shardingRule
;
/**
* Unmarshal yaml sharding configuration from yaml file.
*
* @param yamlFile yaml file
* @return yaml sharding configuration
* @throws IOException IO Exception
*/
public
static
YamlShardingConfiguration
unmarshal
(
final
File
yamlFile
)
throws
IOException
{
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
yamlFile
);
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
fileInputStream
,
"UTF-8"
)
)
{
return
new
Yaml
(
new
Constructor
(
YamlShardingConfiguration
.
class
)).
loadAs
(
inputStreamReader
,
YamlShardingConfiguration
.
class
);
}
}
/**
* Unmarshal yaml sharding configuration from yaml bytes.
*
* @param yamlBytes yaml bytes
* @return yaml sharding configuration
* @throws IOException IO Exception
*/
public
static
YamlShardingConfiguration
unmarshal
(
final
byte
[]
yamlBytes
)
throws
IOException
{
try
(
InputStream
inputStream
=
new
ByteArrayInputStream
(
yamlBytes
))
{
return
new
Yaml
(
new
Constructor
(
YamlShardingConfiguration
.
class
)).
loadAs
(
inputStream
,
YamlShardingConfiguration
.
class
);
}
}
/**
* Get sharding rule from yaml.
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录