[代码完善](master): 完善sharding-jdbc功能及测试
完善了sharding-jdbc的CRUD并测试 配置了XA事务,但是还未测试 配置了动态数据源,但是还未测试master
parent
b5935c489f
commit
24f37e5382
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
ps: 注意配置了多少分表就创建多少张
|
||||||
|
|
||||||
|
Source Server : 本地环境mysql
|
||||||
|
Source Server Type : MySQL
|
||||||
|
Source Server Version : 80026
|
||||||
|
Source Host : localhost:3306
|
||||||
|
Source Schema : shard-1
|
||||||
|
|
||||||
|
Target Server Type : MySQL
|
||||||
|
Target Server Version : 80026
|
||||||
|
File Encoding : 65001
|
||||||
|
|
||||||
|
Date: 24/10/2021 01:42:50
|
||||||
|
*/
|
||||||
|
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_order_0
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_order`;
|
||||||
|
CREATE TABLE `t_order_0` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||||
|
`user_id` bigint NOT NULL,
|
||||||
|
`order_name` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.baiye.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shardingJDBC - 事务支持
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class TransactionConfiguration {
|
||||||
|
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
public PlatformTransactionManager txManager(final DataSource dataSource) {
|
||||||
|
return new DataSourceTransactionManager(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JdbcTemplate jdbcTemplate(final DataSource dataSource) {
|
||||||
|
return new JdbcTemplate(dataSource);
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,23 @@
|
|||||||
spring.shardingsphere.datasource.names=ds0,ds1
|
spring.shardingsphere.datasource.names=ds0,ds1
|
||||||
|
|
||||||
spring.shardingsphere.datasource.ds0.type=com.alibaba.druid.pool.DruidDataSource
|
spring.shardingsphere.datasource.ds0.type=com.alibaba.druid.pool.DruidDataSource
|
||||||
spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver
|
spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.shardingsphere.datasource.ds0.url=jdbc:mysql://localhost:3306/shard-3
|
spring.shardingsphere.datasource.ds0.url=jdbc:mysql://127.0.0.1:3306/shard-1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&useTimezone=true
|
||||||
spring.shardingsphere.datasource.ds0.username=root
|
spring.shardingsphere.datasource.ds0.username=root
|
||||||
spring.shardingsphere.datasource.ds0.password=root
|
spring.shardingsphere.datasource.ds0.password=root
|
||||||
|
|
||||||
spring.shardingsphere.datasource.ds1.type=com.alibaba.druid.pool.DruidDataSource
|
spring.shardingsphere.datasource.ds1.type=com.alibaba.druid.pool.DruidDataSource
|
||||||
spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.jdbc.Driver
|
spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.shardingsphere.datasource.ds1.url=jdbc:mysql://localhost:3306/shard-4
|
spring.shardingsphere.datasource.ds1.url=jdbc:mysql://127.0.0.1:3306/shard-2?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&useTimezone=true
|
||||||
spring.shardingsphere.datasource.ds1.username=root
|
spring.shardingsphere.datasource.ds1.username=root
|
||||||
spring.shardingsphere.datasource.ds1.password=root
|
spring.shardingsphere.datasource.ds1.password=root
|
||||||
|
|
||||||
spring.shardingsphere.sharding.tables.order.actual-data-nodes=ds$->{0..1}.order$->{0..1}
|
|
||||||
spring.shardingsphere.sharding.tables.order.table-strategy.inline.sharding-column=id
|
|
||||||
spring.shardingsphere.sharding.tables.order.table-strategy.inline.algorithm-expression=id$->{id % 2}
|
|
||||||
spring.shardingsphere.sharding.tables.order.key-generator.column=userid
|
|
||||||
spring.shardingsphere.sharding.tables.order.key-generator.type=SNOWFLAKE
|
|
||||||
|
|
||||||
spring.shardingsphere.sharding.default-database-strategy.inline.sharding-column=id
|
spring.shardingsphere.sharding.default-database-strategy.inline.sharding-column=id
|
||||||
spring.shardingsphere.sharding.default-database-strategy.inline.algorithm-expression=ds$->{id % 2}
|
spring.shardingsphere.sharding.default-database-strategy.inline.algorithm-expression=ds$->{id % 2}
|
||||||
|
|
||||||
|
spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=ds$->{0..1}.t_order_$->{0..1}
|
||||||
|
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-column=user_id
|
||||||
|
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order_$->{user_id % 2}
|
||||||
|
spring.shardingsphere.sharding.tables.t_order.key-generator.column=id
|
||||||
|
spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue