Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
4b8086f8
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,发现更多精彩内容 >>
提交
4b8086f8
编写于
4月 04, 2019
作者:
L
liya.cookie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
complete broadcast table for raw-jdbc
上级
1b8e8fd7
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
294 addition
and
96 deletion
+294
-96
example-common/repository-api/src/main/java/io/shardingsphere/example/common/DataSourceUtil.java
...java/io/shardingsphere/example/common/DataSourceUtil.java
+1
-1
example-common/repository-api/src/main/java/io/shardingsphere/example/common/entity/Country.java
...java/io/shardingsphere/example/common/entity/Country.java
+5
-1
example-common/repository-jpa/src/main/java/io/shardingsphere/example/common/jpa/entity/CountryEntity.java
...ardingsphere/example/common/jpa/entity/CountryEntity.java
+38
-0
example-common/repository-jpa/src/main/java/io/shardingsphere/example/common/jpa/repository/CountryRepositoryImpl.java
.../example/common/jpa/repository/CountryRepositoryImpl.java
+57
-0
example-common/repository-jpa/src/main/java/io/shardingsphere/example/common/jpa/service/JPACommonServiceImpl.java
...here/example/common/jpa/service/JPACommonServiceImpl.java
+67
-5
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/JavaRangeConfigurationExample.java
...ple/sharding/data/jdbc/JavaRangeConfigurationExample.java
+2
-1
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/YamlConfigurationExample.java
.../example/sharding/data/jdbc/YamlConfigurationExample.java
+2
-1
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/YamlRangeConfigurationExample.java
...ple/sharding/data/jdbc/YamlRangeConfigurationExample.java
+2
-1
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesAndTablesConfigurationPrecise.java
...onfig/ShardingDatabasesAndTablesConfigurationPrecise.java
+5
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesAndTablesConfigurationRange.java
.../config/ShardingDatabasesAndTablesConfigurationRange.java
+5
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesConfigurationPrecise.java
...ta/jdbc/config/ShardingDatabasesConfigurationPrecise.java
+4
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesConfigurationRange.java
...data/jdbc/config/ShardingDatabasesConfigurationRange.java
+5
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingMasterSlaveConfigurationPrecise.java
.../jdbc/config/ShardingMasterSlaveConfigurationPrecise.java
+5
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingMasterSlaveConfigurationRange.java
...ta/jdbc/config/ShardingMasterSlaveConfigurationRange.java
+5
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingTablesConfigurationPrecise.java
.../data/jdbc/config/ShardingTablesConfigurationPrecise.java
+6
-9
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingTablesConfigurationRange.java
...ng/data/jdbc/config/ShardingTablesConfigurationRange.java
+5
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/master-slave.yaml
...dbc-example/src/main/resources/META-INF/master-slave.yaml
+4
-4
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases-range.yaml
...src/main/resources/META-INF/sharding-databases-range.yaml
+8
-3
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases-tables-range.yaml
...n/resources/META-INF/sharding-databases-tables-range.yaml
+7
-2
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases-tables.yaml
...rc/main/resources/META-INF/sharding-databases-tables.yaml
+9
-4
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases.yaml
...ample/src/main/resources/META-INF/sharding-databases.yaml
+8
-3
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-master-slave-range.yaml
.../main/resources/META-INF/sharding-master-slave-range.yaml
+11
-6
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-master-slave.yaml
...le/src/main/resources/META-INF/sharding-master-slave.yaml
+13
-8
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables-range.yaml
...le/src/main/resources/META-INF/sharding-tables-range.yaml
+6
-1
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables.yaml
...-example/src/main/resources/META-INF/sharding-tables.yaml
+7
-2
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/java/io/shardingsphere/example/spring/boot/jpa/SpringBootExample.java
...dingsphere/example/spring/boot/jpa/SpringBootExample.java
+1
-0
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases-tables.properties
...esources/application-sharding-databases-tables.properties
+1
-0
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases.properties
.../main/resources/application-sharding-databases.properties
+3
-2
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-master-slave.properties
...in/resources/application-sharding-master-slave.properties
+1
-0
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-tables.properties
...src/main/resources/application-sharding-tables.properties
+1
-0
未找到文件。
example-common/repository-api/src/main/java/io/shardingsphere/example/common/DataSourceUtil.java
浏览文件 @
4b8086f8
...
...
@@ -29,7 +29,7 @@ public class DataSourceUtil {
private
static
final
String
USER_NAME
=
"root"
;
private
static
final
String
PASSWORD
=
"
liya76133951
"
;
private
static
final
String
PASSWORD
=
""
;
public
static
DataSource
createDataSource
(
final
String
dataSourceName
)
{
HikariDataSource
result
=
new
HikariDataSource
();
...
...
example-common/repository-api/src/main/java/io/shardingsphere/example/common/entity/Country.java
浏览文件 @
4b8086f8
...
...
@@ -17,7 +17,11 @@
package
io.shardingsphere.example.common.entity
;
public
class
Country
{
import
java.io.Serializable
;
public
class
Country
implements
Serializable
{
private
static
final
long
serialVersionUID
=
4522167390518926493L
;
private
long
id
;
...
...
example-common/repository-jpa/src/main/java/io/shardingsphere/example/common/jpa/entity/CountryEntity.java
0 → 100644
浏览文件 @
4b8086f8
package
io.shardingsphere.example.common.jpa.entity
;
import
io.shardingsphere.example.common.entity.Country
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
@Entity
@Table
(
name
=
"t_country"
)
public
class
CountryEntity
extends
Country
{
@Id
@Column
(
name
=
"id"
)
@Override
public
long
getId
()
{
return
super
.
getId
();
}
@Column
(
name
=
"name"
)
@Override
public
String
getName
()
{
return
super
.
getName
();
}
@Column
(
name
=
"code"
)
@Override
public
String
getCode
()
{
return
super
.
getCode
();
}
@Column
(
name
=
"language"
)
@Override
public
String
getLanguage
()
{
return
super
.
getLanguage
();
}
}
example-common/repository-jpa/src/main/java/io/shardingsphere/example/common/jpa/repository/CountryRepositoryImpl.java
0 → 100644
浏览文件 @
4b8086f8
package
io.shardingsphere.example.common.jpa.repository
;
import
io.shardingsphere.example.common.entity.Country
;
import
io.shardingsphere.example.common.repository.CountryRepository
;
import
org.springframework.stereotype.Repository
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.Query
;
import
javax.transaction.Transactional
;
import
java.util.List
;
import
java.util.concurrent.atomic.AtomicLong
;
@Repository
@Transactional
public
class
CountryRepositoryImpl
implements
CountryRepository
{
private
final
static
AtomicLong
ID_INCREASE
=
new
AtomicLong
();
@PersistenceContext
private
EntityManager
entityManager
;
@Override
public
void
createTableIfNotExists
()
{
throw
new
UnsupportedOperationException
(
"createTableIfNotExists for JPA"
);
}
@Override
public
void
dropTable
()
{
throw
new
UnsupportedOperationException
(
"truncateTable for JPA"
);
}
@Override
public
void
truncateTable
()
{
throw
new
UnsupportedOperationException
(
"dropTable for JPA"
);
}
@Override
public
Long
insert
(
Country
country
)
{
long
id
=
ID_INCREASE
.
incrementAndGet
();
country
.
setId
(
id
);
entityManager
.
persist
(
country
);
return
id
;
}
@Override
public
void
delete
(
Long
id
)
{
Query
query
=
entityManager
.
createQuery
(
"DELETE FROM CountryEntity o WHERE o.id = ?1"
);
query
.
setParameter
(
1
,
id
);
query
.
executeUpdate
();
}
@Override
public
List
<
Country
>
selectAll
()
{
return
(
List
<
Country
>)
entityManager
.
createQuery
(
"SELECT o FROM CountryEntity o"
).
getResultList
();
}
}
example-common/repository-jpa/src/main/java/io/shardingsphere/example/common/jpa/service/JPACommonServiceImpl.java
浏览文件 @
4b8086f8
...
...
@@ -17,8 +17,11 @@
package
io.shardingsphere.example.common.jpa.service
;
import
io.shardingsphere.example.common.entity.Country
;
import
io.shardingsphere.example.common.jpa.entity.CountryEntity
;
import
io.shardingsphere.example.common.jpa.entity.OrderEntity
;
import
io.shardingsphere.example.common.jpa.entity.OrderItemEntity
;
import
io.shardingsphere.example.common.repository.CountryRepository
;
import
io.shardingsphere.example.common.repository.OrderItemRepository
;
import
io.shardingsphere.example.common.repository.OrderRepository
;
import
org.springframework.stereotype.Service
;
...
...
@@ -27,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Locale
;
@Service
public
class
JPACommonServiceImpl
implements
JPACommonService
{
...
...
@@ -36,6 +40,9 @@ public class JPACommonServiceImpl implements JPACommonService {
@Resource
private
OrderItemRepository
orderItemRepository
;
@Resource
private
CountryRepository
countryRepository
;
@Override
public
void
initEnvironment
()
{
...
...
@@ -49,9 +56,9 @@ public class JPACommonServiceImpl implements JPACommonService {
@Transactional
public
void
processSuccess
()
{
System
.
out
.
println
(
"-------------- Process Success Begin ---------------"
);
List
<
Long
>
orderIds
=
insertData
();
InsertResult
insertResult
=
insertData
();
printData
();
deleteData
(
orderIds
);
deleteData
(
insertResult
.
getOrderIds
(),
insertResult
.
getCountryIds
()
);
printData
();
System
.
out
.
println
(
"-------------- Process Success Finish --------------"
);
}
...
...
@@ -64,9 +71,15 @@ public class JPACommonServiceImpl implements JPACommonService {
System
.
out
.
println
(
"-------------- Process Failure Finish --------------"
);
throw
new
RuntimeException
(
"Exception occur for transaction test."
);
}
private
List
<
Long
>
insertData
()
{
private
InsertResult
insertData
()
{
System
.
out
.
println
(
"---------------------------- Insert Data ----------------------------"
);
List
<
Long
>
orderIds
=
insertOrderData
();
List
<
Long
>
countryIds
=
insertCountryData
();
return
new
InsertResult
(
orderIds
,
countryIds
);
}
private
List
<
Long
>
insertOrderData
()
{
List
<
Long
>
result
=
new
ArrayList
<>(
10
);
for
(
int
i
=
1
;
i
<=
10
;
i
++)
{
OrderEntity
order
=
new
OrderEntity
();
...
...
@@ -82,13 +95,38 @@ public class JPACommonServiceImpl implements JPACommonService {
}
return
result
;
}
private
List
<
Long
>
insertCountryData
(){
List
<
Long
>
result
=
new
ArrayList
<>();
Locale
[]
locales
=
Locale
.
getAvailableLocales
();
int
i
=
0
;
for
(
Locale
l:
locales
){
final
String
country
=
l
.
getCountry
();
if
(
country
==
null
||
""
.
equals
(
country
)){
continue
;
}
CountryEntity
currCountry
=
new
CountryEntity
();
currCountry
.
setName
(
l
.
getDisplayCountry
(
l
));
currCountry
.
setLanguage
(
l
.
getLanguage
());
currCountry
.
setCode
(
l
.
getCountry
());
countryRepository
.
insert
(
currCountry
);
result
.
add
(
currCountry
.
getId
());
if
(++
i
==
10
){
break
;
}
}
return
result
;
}
private
void
deleteData
(
final
List
<
Long
>
orderIds
)
{
private
void
deleteData
(
final
List
<
Long
>
orderIds
,
final
List
<
Long
>
countryIds
)
{
System
.
out
.
println
(
"---------------------------- Delete Data ----------------------------"
);
for
(
Long
each
:
orderIds
)
{
orderRepository
.
delete
(
each
);
orderItemRepository
.
delete
(
each
);
}
for
(
Long
each:
countryIds
){
countryRepository
.
delete
(
each
);
}
}
@Override
...
...
@@ -101,5 +139,29 @@ public class JPACommonServiceImpl implements JPACommonService {
for
(
Object
each
:
orderItemRepository
.
selectAll
())
{
System
.
out
.
println
(
each
);
}
System
.
out
.
println
(
"---------------------------- Print Country Data -------------------"
);
for
(
Object
each
:
countryRepository
.
selectAll
())
{
System
.
out
.
println
(
each
);
}
}
private
static
class
InsertResult
{
private
List
<
Long
>
orderIds
;
private
List
<
Long
>
countryIds
;
public
InsertResult
(
List
<
Long
>
orderIds
,
List
<
Long
>
countryIds
)
{
this
.
orderIds
=
orderIds
;
this
.
countryIds
=
countryIds
;
}
public
List
<
Long
>
getOrderIds
()
{
return
orderIds
;
}
public
List
<
Long
>
getCountryIds
()
{
return
countryIds
;
}
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/JavaRangeConfigurationExample.java
浏览文件 @
4b8086f8
...
...
@@ -17,6 +17,7 @@
package
io.shardingsphere.example.sharding.data.jdbc
;
import
io.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl
;
import
io.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl
;
import
io.shardingsphere.example.common.jdbc.repository.RangeOrderRepositoryImpl
;
import
io.shardingsphere.example.common.jdbc.service.CommonServiceImpl
;
...
...
@@ -47,6 +48,6 @@ public class JavaRangeConfigurationExample {
}
private
static
CommonService
getCommonService
(
final
DataSource
dataSource
)
{
return
new
CommonServiceImpl
(
new
RangeOrderRepositoryImpl
(
dataSource
),
new
OrderItemRepositoryImpl
(
dataSource
));
return
new
CommonServiceImpl
(
new
RangeOrderRepositoryImpl
(
dataSource
),
new
OrderItemRepositoryImpl
(
dataSource
)
,
new
CountryRepositroyImpl
(
dataSource
)
);
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/YamlConfigurationExample.java
浏览文件 @
4b8086f8
...
...
@@ -17,6 +17,7 @@
package
io.shardingsphere.example.sharding.data.jdbc
;
import
io.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl
;
import
io.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl
;
import
io.shardingsphere.example.common.jdbc.repository.OrderRepositoryImpl
;
import
io.shardingsphere.example.common.jdbc.service.CommonServiceImpl
;
...
...
@@ -48,6 +49,6 @@ public class YamlConfigurationExample {
}
private
static
CommonService
getCommonService
(
final
DataSource
dataSource
)
{
return
new
CommonServiceImpl
(
new
OrderRepositoryImpl
(
dataSource
),
new
OrderItemRepositoryImpl
(
dataSource
));
return
new
CommonServiceImpl
(
new
OrderRepositoryImpl
(
dataSource
),
new
OrderItemRepositoryImpl
(
dataSource
)
,
new
CountryRepositroyImpl
(
dataSource
)
);
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/YamlRangeConfigurationExample.java
浏览文件 @
4b8086f8
...
...
@@ -17,6 +17,7 @@
package
io.shardingsphere.example.sharding.data.jdbc
;
import
io.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl
;
import
io.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl
;
import
io.shardingsphere.example.common.jdbc.repository.RangeOrderRepositoryImpl
;
import
io.shardingsphere.example.common.jdbc.service.CommonServiceImpl
;
...
...
@@ -48,6 +49,6 @@ public class YamlRangeConfigurationExample {
}
private
static
CommonService
getCommonService
(
final
DataSource
dataSource
)
{
return
new
CommonServiceImpl
(
new
RangeOrderRepositoryImpl
(
dataSource
),
new
OrderItemRepositoryImpl
(
dataSource
));
return
new
CommonServiceImpl
(
new
RangeOrderRepositoryImpl
(
dataSource
),
new
OrderItemRepositoryImpl
(
dataSource
)
,
new
CountryRepositroyImpl
(
dataSource
)
);
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesAndTablesConfigurationPrecise.java
浏览文件 @
4b8086f8
...
...
@@ -41,6 +41,7 @@ public final class ShardingDatabasesAndTablesConfigurationPrecise implements Exa
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderTableRuleConfiguration
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderItemTableRuleConfiguration
());
shardingRuleConfig
.
getBindingTableGroups
().
add
(
"t_order, t_order_item"
);
shardingRuleConfig
.
getBroadcastTables
().
add
(
"t_country"
);
shardingRuleConfig
.
setDefaultDatabaseShardingStrategyConfig
(
new
InlineShardingStrategyConfiguration
(
"user_id"
,
"demo_ds_${user_id % 2}"
));
shardingRuleConfig
.
setDefaultTableShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"order_id"
,
new
PreciseModuloShardingTableAlgorithm
()));
return
ShardingDataSourceFactory
.
createDataSource
(
createDataSourceMap
(),
shardingRuleConfig
,
new
Properties
());
...
...
@@ -48,12 +49,14 @@ public final class ShardingDatabasesAndTablesConfigurationPrecise implements Exa
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
,
"demo_ds_${0..1}.t_order_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds_${0..1}.t_order_item_${[0, 1]}"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds_${0..1}.t_order_item_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
Map
<
String
,
DataSource
>
createDataSourceMap
()
{
...
...
@@ -62,8 +65,4 @@ public final class ShardingDatabasesAndTablesConfigurationPrecise implements Exa
result
.
put
(
"demo_ds_1"
,
DataSourceUtil
.
createDataSource
(
"demo_ds_1"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesAndTablesConfigurationRange.java
浏览文件 @
4b8086f8
...
...
@@ -43,6 +43,7 @@ public final class ShardingDatabasesAndTablesConfigurationRange implements Examp
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderTableRuleConfiguration
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderItemTableRuleConfiguration
());
shardingRuleConfig
.
getBindingTableGroups
().
add
(
"t_order, t_order_item"
);
shardingRuleConfig
.
getBroadcastTables
().
add
(
"t_country"
);
shardingRuleConfig
.
setDefaultDatabaseShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"user_id"
,
new
PreciseModuloShardingDatabaseAlgorithm
(),
new
RangeModuloShardingDatabaseAlgorithm
()));
shardingRuleConfig
.
setDefaultTableShardingStrategyConfig
(
...
...
@@ -52,12 +53,14 @@ public final class ShardingDatabasesAndTablesConfigurationRange implements Examp
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
,
"demo_ds_${0..1}.t_order_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds_${0..1}.t_order_item_${[0, 1]}"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds_${0..1}.t_order_item_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
Map
<
String
,
DataSource
>
createDataSourceMap
()
{
...
...
@@ -66,8 +69,4 @@ public final class ShardingDatabasesAndTablesConfigurationRange implements Examp
result
.
put
(
"demo_ds_1"
,
DataSourceUtil
.
createDataSource
(
"demo_ds_1"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesConfigurationPrecise.java
浏览文件 @
4b8086f8
...
...
@@ -45,12 +45,14 @@ public final class ShardingDatabasesConfigurationPrecise implements ExampleConfi
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
Map
<
String
,
DataSource
>
createDataSourceMap
()
{
...
...
@@ -59,8 +61,4 @@ public final class ShardingDatabasesConfigurationPrecise implements ExampleConfi
result
.
put
(
"demo_ds_1"
,
DataSourceUtil
.
createDataSource
(
"demo_ds_1"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingDatabasesConfigurationRange.java
浏览文件 @
4b8086f8
...
...
@@ -40,6 +40,7 @@ public final class ShardingDatabasesConfigurationRange implements ExampleConfigu
ShardingRuleConfiguration
shardingRuleConfig
=
new
ShardingRuleConfiguration
();
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderTableRuleConfiguration
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderItemTableRuleConfiguration
());
shardingRuleConfig
.
getBroadcastTables
().
add
(
"t_country"
);
shardingRuleConfig
.
setDefaultDatabaseShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"user_id"
,
new
PreciseModuloShardingDatabaseAlgorithm
(),
new
RangeModuloShardingDatabaseAlgorithm
()));
return
ShardingDataSourceFactory
.
createDataSource
(
createDataSourceMap
(),
shardingRuleConfig
,
new
Properties
());
...
...
@@ -47,12 +48,14 @@ public final class ShardingDatabasesConfigurationRange implements ExampleConfigu
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
Map
<
String
,
DataSource
>
createDataSourceMap
()
{
...
...
@@ -61,8 +64,4 @@ public final class ShardingDatabasesConfigurationRange implements ExampleConfigu
result
.
put
(
"demo_ds_1"
,
DataSourceUtil
.
createDataSource
(
"demo_ds_1"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingMasterSlaveConfigurationPrecise.java
浏览文件 @
4b8086f8
...
...
@@ -45,6 +45,7 @@ public final class ShardingMasterSlaveConfigurationPrecise implements ExampleCon
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderTableRuleConfiguration
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderItemTableRuleConfiguration
());
shardingRuleConfig
.
getBindingTableGroups
().
add
(
"t_order, t_order_item"
);
shardingRuleConfig
.
getBroadcastTables
().
add
(
"t_country"
);
shardingRuleConfig
.
setDefaultDatabaseShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"user_id"
,
new
PreciseModuloShardingDatabaseAlgorithm
()));
shardingRuleConfig
.
setDefaultTableShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"order_id"
,
new
PreciseModuloShardingTableAlgorithm
()));
shardingRuleConfig
.
setMasterSlaveRuleConfigs
(
getMasterSlaveRuleConfigurations
());
...
...
@@ -53,12 +54,14 @@ public final class ShardingMasterSlaveConfigurationPrecise implements ExampleCon
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
,
"ds_${0..1}.t_order_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
,
"ds_${0..1}.t_order_item_${[0, 1]}"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
,
"ds_${0..1}.t_order_item_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
List
<
MasterSlaveRuleConfiguration
>
getMasterSlaveRuleConfigurations
()
{
...
...
@@ -77,8 +80,4 @@ public final class ShardingMasterSlaveConfigurationPrecise implements ExampleCon
result
.
put
(
"demo_ds_master_1_slave_1"
,
DataSourceUtil
.
createDataSource
(
"demo_ds_master_1_slave_1"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingMasterSlaveConfigurationRange.java
浏览文件 @
4b8086f8
...
...
@@ -47,6 +47,7 @@ public final class ShardingMasterSlaveConfigurationRange implements ExampleConfi
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderTableRuleConfiguration
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderItemTableRuleConfiguration
());
shardingRuleConfig
.
getBindingTableGroups
().
add
(
"t_order, t_order_item"
);
shardingRuleConfig
.
getBroadcastTables
().
add
(
"t_country"
);
shardingRuleConfig
.
setDefaultDatabaseShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"user_id"
,
new
PreciseModuloShardingDatabaseAlgorithm
(),
new
RangeModuloShardingDatabaseAlgorithm
()));
shardingRuleConfig
.
setDefaultTableShardingStrategyConfig
(
...
...
@@ -57,12 +58,14 @@ public final class ShardingMasterSlaveConfigurationRange implements ExampleConfi
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
,
"ds_${0..1}.t_order_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
,
"ds_${0..1}.t_order_item_${[0, 1]}"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
,
"ds_${0..1}.t_order_item_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
List
<
MasterSlaveRuleConfiguration
>
getMasterSlaveRuleConfigurations
()
{
...
...
@@ -81,8 +84,4 @@ public final class ShardingMasterSlaveConfigurationRange implements ExampleConfi
result
.
put
(
"demo_ds_master_1_slave_1"
,
DataSourceUtil
.
createDataSource
(
"demo_ds_master_1_slave_1"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingTablesConfigurationPrecise.java
浏览文件 @
4b8086f8
...
...
@@ -40,20 +40,21 @@ public final class ShardingTablesConfigurationPrecise implements ExampleConfigur
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderTableRuleConfiguration
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderItemTableRuleConfiguration
());
shardingRuleConfig
.
getBindingTableGroups
().
add
(
"t_order, t_order_item"
);
shardingRuleConfig
.
getBroadcastTables
().
add
(
"t_country"
);
shardingRuleConfig
.
setDefaultTableShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"order_id"
,
new
PreciseModuloShardingTableAlgorithm
()));
Properties
properties
=
new
Properties
();
properties
.
put
(
"sql.show"
,
true
);
return
ShardingDataSourceFactory
.
createDataSource
(
createDataSourceMap
(),
shardingRuleConfig
,
properties
);
return
ShardingDataSourceFactory
.
createDataSource
(
createDataSourceMap
(),
shardingRuleConfig
,
new
Properties
());
}
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
,
"demo_ds.t_order_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds.t_order_item_${[0, 1]}"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds.t_order_item_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
Map
<
String
,
DataSource
>
createDataSourceMap
()
{
...
...
@@ -61,8 +62,4 @@ public final class ShardingTablesConfigurationPrecise implements ExampleConfigur
result
.
put
(
"demo_ds"
,
DataSourceUtil
.
createDataSource
(
"demo_ds"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/java/io/shardingsphere/example/sharding/data/jdbc/config/ShardingTablesConfigurationRange.java
浏览文件 @
4b8086f8
...
...
@@ -41,6 +41,7 @@ public final class ShardingTablesConfigurationRange implements ExampleConfigurat
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderTableRuleConfiguration
());
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
getOrderItemTableRuleConfiguration
());
shardingRuleConfig
.
getBindingTableGroups
().
add
(
"t_order, t_order_item"
);
shardingRuleConfig
.
getBroadcastTables
().
add
(
"t_country"
);
shardingRuleConfig
.
setDefaultTableShardingStrategyConfig
(
new
StandardShardingStrategyConfiguration
(
"order_id"
,
new
PreciseModuloShardingTableAlgorithm
(),
new
RangeModuloShardingTableAlgorithm
()));
return
ShardingDataSourceFactory
.
createDataSource
(
createDataSourceMap
(),
shardingRuleConfig
,
new
Properties
());
...
...
@@ -48,12 +49,14 @@ public final class ShardingTablesConfigurationRange implements ExampleConfigurat
private
static
TableRuleConfiguration
getOrderTableRuleConfiguration
()
{
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order"
,
"demo_ds.t_order_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
getKeyGeneratorConfiguration
(
));
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
()
));
return
result
;
}
private
static
TableRuleConfiguration
getOrderItemTableRuleConfiguration
()
{
return
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds.t_order_item_${[0, 1]}"
);
TableRuleConfiguration
result
=
new
TableRuleConfiguration
(
"t_order_item"
,
"demo_ds.t_order_item_${[0, 1]}"
);
result
.
setKeyGeneratorConfig
(
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_item_id"
,
new
Properties
()));
return
result
;
}
private
static
Map
<
String
,
DataSource
>
createDataSourceMap
()
{
...
...
@@ -61,8 +64,4 @@ public final class ShardingTablesConfigurationRange implements ExampleConfigurat
result
.
put
(
"demo_ds"
,
DataSourceUtil
.
createDataSource
(
"demo_ds"
));
return
result
;
}
private
static
KeyGeneratorConfiguration
getKeyGeneratorConfiguration
()
{
return
new
KeyGeneratorConfiguration
(
"SNOWFLAKE"
,
"order_id"
,
new
Properties
());
}
}
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/master-slave.yaml
浏览文件 @
4b8086f8
dataSources
:
ds_master
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_slave_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_slave_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_slave_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_slave_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_slave_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_slave_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -21,4 +21,4 @@ masterSlaveRule:
slaveDataSourceNames
:
[
ds_slave_0
,
ds_slave_1
]
props
:
sql.show
:
tru
e
sql.show
:
fals
e
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases-range.yaml
浏览文件 @
4b8086f8
dataSources
:
ds_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -19,8 +19,13 @@ shardingRule:
column
:
order_id
t_order_item
:
actualDataNodes
:
ds_${0..1}.t_order_item
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
defaultDatabaseStrategy
:
standard
:
...
...
@@ -31,4 +36,4 @@ shardingRule:
none
:
props
:
sql.show
:
tru
e
sql.show
:
fals
e
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases-tables-range.yaml
浏览文件 @
4b8086f8
dataSources
:
ds_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -29,8 +29,13 @@ shardingRule:
shardingColumn
:
order_id
preciseAlgorithmClassName
:
io.shardingsphere.example.algorithm.PreciseModuloShardingTableAlgorithm
rangeAlgorithmClassName
:
io.shardingsphere.example.algorithm.RangeModuloShardingTableAlgorithm
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
defaultDatabaseStrategy
:
standard
:
...
...
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases-tables.yaml
浏览文件 @
4b8086f8
dataSources
:
ds_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -26,9 +26,14 @@ shardingRule:
tableStrategy
:
inline
:
shardingColumn
:
order_id
algorithmExpression
:
t_order_item_${order_id % 2}
algorithmExpression
:
t_order_item_${order_id % 2}
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
defaultDatabaseStrategy
:
inline
:
...
...
@@ -38,4 +43,4 @@ shardingRule:
none
:
props
:
sql.show
:
tru
e
sql.show
:
fals
e
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-databases.yaml
浏览文件 @
4b8086f8
dataSources
:
ds_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -19,8 +19,13 @@ shardingRule:
column
:
order_id
t_order_item
:
actualDataNodes
:
ds_${0..1}.t_order_item
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
defaultDatabaseStrategy
:
inline
:
...
...
@@ -30,4 +35,4 @@ shardingRule:
none
:
props
:
sql.show
:
tru
e
sql.show
:
fals
e
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-master-slave-range.yaml
浏览文件 @
4b8086f8
dataSources
:
ds_master_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_0_slave_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_0_slave_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_1_slave_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_1_slave_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -49,8 +49,13 @@ shardingRule:
shardingColumn
:
order_id
preciseAlgorithmClassName
:
io.shardingsphere.example.algorithm.PreciseModuloShardingTableAlgorithm
rangeAlgorithmClassName
:
io.shardingsphere.example.algorithm.RangeModuloShardingTableAlgorithm
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
defaultDatabaseStrategy
:
standard
:
...
...
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-master-slave.yaml
浏览文件 @
4b8086f8
dataSources
:
ds_master_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_0_slave_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_0_slave_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_1_slave_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_0
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_0
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
ds_master_1_slave_1
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_1
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds_master_1_slave_1
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -46,9 +46,14 @@ shardingRule:
tableStrategy
:
inline
:
shardingColumn
:
order_id
algorithmExpression
:
t_order_item_${order_id % 2}
algorithmExpression
:
t_order_item_${order_id % 2}
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
defaultDatabaseStrategy
:
inline
:
...
...
@@ -66,4 +71,4 @@ shardingRule:
loadBalanceAlgorithmType
:
ROUND_ROBIN
props
:
sql.show
:
tru
e
sql.show
:
fals
e
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables-range.yaml
浏览文件 @
4b8086f8
dataSources
:
ds
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -24,8 +24,13 @@ shardingRule:
shardingColumn
:
order_id
preciseAlgorithmClassName
:
io.shardingsphere.example.algorithm.PreciseModuloShardingTableAlgorithm
rangeAlgorithmClassName
:
io.shardingsphere.example.algorithm.RangeModuloShardingTableAlgorithm
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
props
:
sql.show
:
false
sharding-jdbc-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables.yaml
浏览文件 @
4b8086f8
dataSources
:
ds
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds
jdbcUrl
:
jdbc:mysql://localhost:3306/demo_ds
?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username
:
root
password
:
...
...
@@ -22,8 +22,13 @@ shardingRule:
inline
:
shardingColumn
:
order_id
algorithmExpression
:
t_order_item_${order_id % 2}
keyGenerator
:
type
:
SNOWFLAKE
column
:
order_item_id
bindingTables
:
-
t_order,t_order_item
broadcastTables
:
-
t_country
props
:
sql.show
:
tru
e
sql.show
:
fals
e
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/java/io/shardingsphere/example/spring/boot/jpa/SpringBootExample.java
浏览文件 @
4b8086f8
...
...
@@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.domain.EntityScan;
import
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.core.env.PropertySource
;
@ComponentScan
(
"io.shardingsphere.example.common.jpa"
)
@EntityScan
(
basePackages
=
"io.shardingsphere.example.common.jpa.entity"
)
...
...
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases-tables.properties
浏览文件 @
4b8086f8
...
...
@@ -27,3 +27,4 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression
=
t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column
=
order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type
=
SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables
=
t_country
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases.properties
浏览文件 @
4b8086f8
...
...
@@ -2,13 +2,13 @@ sharding.jdbc.datasource.names=ds_0,ds_1
sharding.jdbc.datasource.ds_0.type
=
com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.ds_0.driver-class-name
=
com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_0.jdbc-url
=
jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
sharding.jdbc.datasource.ds_0.jdbc-url
=
jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
&useUnicode=true&characterEncoding=UTF-8
sharding.jdbc.datasource.ds_0.username
=
root
sharding.jdbc.datasource.ds_0.password
=
sharding.jdbc.datasource.ds_1.type
=
com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.ds_1.driver-class-name
=
com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_1.jdbc-url
=
jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
sharding.jdbc.datasource.ds_1.jdbc-url
=
jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
&useUnicode=true&characterEncoding=UTF-8
sharding.jdbc.datasource.ds_1.username
=
root
sharding.jdbc.datasource.ds_1.password
=
...
...
@@ -21,3 +21,4 @@ sharding.jdbc.config.sharding.tables.t_order.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes
=
ds_$->{0..1}.t_order_item
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column
=
order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type
=
SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables
=
t_country
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-master-slave.properties
浏览文件 @
4b8086f8
...
...
@@ -55,6 +55,7 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression
=
t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column
=
order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type
=
SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables
=
t_country
sharding.jdbc.config.sharding.master-slave-rules.ds_0.master-data-source-name
=
ds_master_0
sharding.jdbc.config.sharding.master-slave-rules.ds_0.slave-data-source-names
=
ds_master_0_slave_0, ds_master_0_slave_1
...
...
sharding-jdbc-example/sharding-example/sharding-spring-boot-jpa-example/src/main/resources/application-sharding-tables.properties
浏览文件 @
4b8086f8
...
...
@@ -17,3 +17,4 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression
=
t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column
=
order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type
=
SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables
=
t_country
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录