Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
9c72ae75
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,发现更多精彩内容 >>
提交
9c72ae75
编写于
4月 04, 2019
作者:
C
cherrylzhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add hint-database-tables & hint-database-only.
上级
96ca47f1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
89 addition
and
7 deletion
+89
-7
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/java/io/shardingsphere/example/hint/raw/jdbc/HintType.java
...ava/io/shardingsphere/example/hint/raw/jdbc/HintType.java
+23
-0
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/java/io/shardingsphere/example/hint/raw/jdbc/YamlConfigurationExample.java
...phere/example/hint/raw/jdbc/YamlConfigurationExample.java
+32
-5
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/resources/META-INF/hint-databases-only.yaml
...mple/src/main/resources/META-INF/hint-databases-only.yaml
+29
-0
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/resources/META-INF/hint-databases-tables.yaml
...le/src/main/resources/META-INF/hint-databases-tables.yaml
+5
-2
未找到文件。
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/java/io/shardingsphere/example/hint/raw/jdbc/HintType.java
0 → 100644
浏览文件 @
9c72ae75
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
io.shardingsphere.example.hint.raw.jdbc
;
public
enum
HintType
{
DATABASE_ONLY
,
DATABASE_TABLES
,
MASTER_ONLY
}
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/java/io/shardingsphere/example/hint/raw/jdbc/YamlConfigurationExample.java
浏览文件 @
9c72ae75
...
...
@@ -36,8 +36,11 @@ import java.sql.Statement;
*/
public
class
YamlConfigurationExample
{
// private static final HintType TYPE = HintType.DATABASE_ONLY;
private
static
final
HintType
TYPE
=
HintType
.
DATABASE_TABLES
;
public
static
void
main
(
final
String
[]
args
)
throws
SQLException
,
IOException
{
DataSource
dataSource
=
YamlShardingDataSourceFactory
.
createDataSource
(
getFile
(
"/META-INF/hint-databases.yaml"
));
DataSource
dataSource
=
YamlShardingDataSourceFactory
.
createDataSource
(
getFile
());
CommonService
commonService
=
getCommonService
(
dataSource
);
commonService
.
initEnvironment
();
try
(
HintManager
hintManager
=
HintManager
.
getInstance
())
{
...
...
@@ -46,8 +49,17 @@ public class YamlConfigurationExample {
commonService
.
cleanEnvironment
();
}
private
static
File
getFile
(
final
String
fileName
)
{
return
new
File
(
Thread
.
currentThread
().
getClass
().
getResource
(
fileName
).
getFile
());
private
static
File
getFile
()
{
switch
(
TYPE
)
{
case
DATABASE_ONLY:
return
new
File
(
Thread
.
currentThread
().
getClass
().
getResource
(
"/META-INF/hint-databases-only.yaml"
).
getFile
());
case
DATABASE_TABLES:
return
new
File
(
Thread
.
currentThread
().
getClass
().
getResource
(
"/META-INF/hint-databases-tables.yaml"
).
getFile
());
case
MASTER_ONLY:
return
new
File
(
Thread
.
currentThread
().
getClass
().
getResource
(
"/META-INF/hint-databases-only.yaml"
).
getFile
());
default
:
throw
new
UnsupportedOperationException
(
"unsupported type"
);
}
}
private
static
CommonService
getCommonService
(
final
DataSource
dataSource
)
{
...
...
@@ -55,12 +67,27 @@ public class YamlConfigurationExample {
}
private
static
void
processWithHintValue
(
final
DataSource
dataSource
,
final
HintManager
hintManager
)
throws
SQLException
{
hintManager
.
addDatabaseShardingValue
(
"t_order"
,
1L
);
hintManager
.
addTableShardingValue
(
"t_order"
,
1L
);
setHintValue
(
hintManager
);
try
(
Connection
connection
=
dataSource
.
getConnection
();
Statement
statement
=
connection
.
createStatement
())
{
statement
.
execute
(
"select * from t_order"
);
statement
.
execute
(
"SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id"
);
statement
.
execute
(
"select * from t_order_item"
);
statement
.
execute
(
"INSERT INTO t_order (user_id, status) VALUES (1, 'init')"
);
}
}
private
static
void
setHintValue
(
final
HintManager
hintManager
)
{
switch
(
TYPE
)
{
case
DATABASE_ONLY:
hintManager
.
setDatabaseShardingValue
(
1L
);
return
;
case
DATABASE_TABLES:
hintManager
.
addDatabaseShardingValue
(
"t_order"
,
1L
);
hintManager
.
addTableShardingValue
(
"t_order"
,
1L
);
return
;
default
:
throw
new
UnsupportedOperationException
(
"unsupported type"
);
}
}
}
...
...
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/resources/META-INF/hint-databases-only.yaml
0 → 100644
浏览文件 @
9c72ae75
dataSources
:
ds_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
username
:
root
password
:
ds_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
username
:
root
password
:
shardingRule
:
tables
:
t_order
:
actualDataNodes
:
ds_${0..1}.t_order
t_order_item
:
actualDataNodes
:
ds_${0..1}.t_order_item
bindingTables
:
-
t_order,t_order_item
defaultDatabaseStrategy
:
hint
:
algorithmClassName
:
io.shardingsphere.example.hint.raw.jdbc.ModuloHintShardingAlgorithm
defaultTableStrategy
:
none
:
props
:
sql.show
:
true
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/resources/META-INF/hint-databases.yaml
→
sharding-jdbc-example/hint-example/hint-raw-jdbc-example/src/main/resources/META-INF/hint-databases
-tables
.yaml
浏览文件 @
9c72ae75
...
...
@@ -13,15 +13,18 @@ dataSources:
shardingRule
:
tables
:
t_order
:
actualDataNodes
:
ds_${0..1}.t_order
actualDataNodes
:
ds_${0..1}.t_order
_${0..1}
databaseStrategy
:
hint
:
algorithmClassName
:
io.shardingsphere.example.hint.raw.jdbc.ModuloHintShardingAlgorithm
tableStrategy
:
hint
:
algorithmClassName
:
io.shardingsphere.example.hint.raw.jdbc.ModuloHintShardingAlgorithm
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_id
t_order_item
:
actualDataNodes
:
ds_${0..1}.t_order_item
actualDataNodes
:
ds_${0..1}.t_order_item
_${0..1}
bindingTables
:
-
t_order,t_order_item
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录