当前位置: 首页 > news >正文

【java_wxid项目】【第八章】【Apache ShardingSphere集成】

文章目录

      • 创建apache-shardingsphere-demo项目
        • 修改pom.xml
          • 修改ApacheShardingsphereDemoApplication
          • 创建application.properties
          • 创建application01.properties
          • 创建application02.properties
          • 创建application03.properties
          • 创建application04.properties
          • 创建Course
          • 创建Dict
          • 创建User
          • 创建CourseMapper
          • 创建DictMapper
          • 创建UserMapper
          • 创建MyComplexDSShardingAlgorithm
          • 创建MyComplexTableShardingAlgorithm
          • 创建MyHintTableShardingAlgorithm
          • 创建MyPreciseDSShardingAlgorithm
          • 创建MyPreciseTableShardingAlgorithm
          • 创建MyRangeDSShardingAlgorithm
          • 创建MyRangeTableShardingAlgorithm
          • 创建course.sql
          • 创建t_dict.sql
          • 创建t_user.sql
          • 修改ApacheShardingsphereDemoApplicationTests
      • 校验Apache ShardingSphere是否正常工作
        • 分表插入

创建apache-shardingsphere-demo项目

项目代码:https://gitee.com/java_wxid/java_wxid/tree/master/demo/apache-shardingsphere-demo
项目结构如下(示例):
在这里插入图片描述

修改pom.xml

代码如下(示例):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>apache-shardingsphere-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>apache-shardingsphere-demo</name>
    <description>Demo project for Spring Boot</description>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.3.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.4.1</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.23</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.22</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

修改ApacheShardingsphereDemoApplication

代码如下(示例):

package com.example.apacheshardingspheredemo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@MapperScan("com.example.apacheshardingspheredemo.mapper")
@SpringBootApplication
public class ApacheShardingsphereDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApacheShardingsphereDemoApplication.class, args);
    }

}

创建application.properties

真正运行的配置
代码如下(示例):

#配置数据源
spring.shardingsphere.datasource.names=m1

spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://110.42.239.246:3306/coursedb?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=591e242ca29b9c37
#course是逻辑表名,actual-data-nodes是真实表分布,也就是sharding里面的逻辑表course对应的是m0库中course_1和course_2
spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}
#主键生成策略,cid作为主键
spring.shardingsphere.sharding.tables.course.key-generator.column=cid
#使用雪花算法生成主键
spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE
#雪花算法需要有一个参数worker.id,这个是可选的
spring.shardingsphere.sharding.tables.course.key-generator.props.worker.id=1
#表策略:选择inline依赖策略,sharding-column分片键cid
spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=cid
#表策略:algorithm-expression分片算法cid模21
spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{cid%2+1}
#其他运行属性
spring.shardingsphere.props.sql.show = true
spring.main.allow-bean-definition-overriding=true
创建application01.properties

代码如下(示例):

#配置数据源
spring.shardingsphere.datasource.names=m1

spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://110.42.239.246:3306/coursedb?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=591e242ca29b9c37
#course是逻辑表名,actual-data-nodes是真实表分布,也就是sharding里面的逻辑表course对应的是m0库中course_1和course_2
spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}
#主键生成策略,cid作为主键
spring.shardingsphere.sharding.tables.course.key-generator.column=cid
#使用雪花算法生成主键
spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE
#雪花算法需要有一个参数worker.id,这个是可选的
spring.shardingsphere.sharding.tables.course.key-generator.props.worker.id=1
#表策略:选择inline依赖策略,sharding-column分片键cid
spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=cid
#表策略:algorithm-expression分片算法cid模21
spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{cid%2+1}
#其他运行属性
spring.shardingsphere.props.sql.show = true
spring.main.allow-bean-definition-overriding=true


创建application02.properties

代码如下(示例):

#配置多个数据源
spring.shardingsphere.datasource.names=m1,m2

spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://110.42.239.246:3306/coursedb?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=591e242ca29b9c37


spring.shardingsphere.datasource.m2.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m2.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m2.url=jdbc:mysql://110.42.239.246:3306/coursedb2?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m2.username=root
spring.shardingsphere.datasource.m2.password=591e242ca29b9c37

#真实表分布,分库,分表
spring.shardingsphere.sharding.tables.course.actual-data-nodes=m$->{1..2}.course_$->{1..2}

spring.shardingsphere.sharding.tables.course.key-generator.column=cid
spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.course.key-generator.props.worker.id=1
#inline分片策略
#spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=cid
#spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{cid%2+1}

#spring.shardingsphere.sharding.tables.course.database-strategy.inline.sharding-column=cid
#spring.shardingsphere.sharding.tables.course.database-strategy.inline.algorithm-expression=m$->{cid%2+1}
#standard标准分片策略
#spring.shardingsphere.sharding.tables.course.table-strategy.standard.sharding-column=cid
#spring.shardingsphere.sharding.tables.course.table-strategy.standard.precise-algorithm-class-name=com.roy.shardingDemo.algorithem.MyPreciseTableShardingAlgorithm
#spring.shardingsphere.sharding.tables.course.table-strategy.standard.range-algorithm-class-name=com.roy.shardingDemo.algorithem.MyRangeTableShardingAlgorithm

spring.shardingsphere.sharding.tables.course.database-strategy.standard.sharding-column=cid
spring.shardingsphere.sharding.tables.course.database-strategy.standard.precise-algorithm-class-name=com.roy.shardingDemo.algorithem.MyPreciseDSShardingAlgorithm
spring.shardingsphere.sharding.tables.course.database-strategy.standard.range-algorithm-class-name=com.roy.shardingDemo.algorithem.MyRangeDSShardingAlgorithm
#complex复杂分片策略
#spring.shardingsphere.sharding.tables.course.table-strategy.complex.sharding-columns= cid, user_id
#spring.shardingsphere.sharding.tables.course.table-strategy.complex.algorithm-class-name=com.roy.shardingDemo.algorithem.MyComplexTableShardingAlgorithm
#
#spring.shardingsphere.sharding.tables.course.database-strategy.complex.sharding-columns=cid, user_id
#spring.shardingsphere.sharding.tables.course.database-strategy.complex.algorithm-class-name=com.roy.shardingDemo.algorithem.MyComplexDSShardingAlgorithm
#hint强制路由策略
spring.shardingsphere.sharding.tables.course.table-strategy.hint.algorithm-class-name=com.roy.shardingDemo.algorithem.MyHintTableShardingAlgorithm
#广播表配置
spring.shardingsphere.sharding.broadcast-tables=t_dict
spring.shardingsphere.sharding.tables.t_dict.key-generator.column=dict_id
spring.shardingsphere.sharding.tables.t_dict.key-generator.type=SNOWFLAKE

spring.shardingsphere.props.sql.show = true
spring.main.allow-bean-definition-overriding=true


创建application03.properties

代码如下(示例):

spring.shardingsphere.datasource.names=m1

spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://110.42.239.246:3306/coursedb?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=591e242ca29b9c37


spring.shardingsphere.sharding.tables.t_dict.actual-data-nodes=m1.t_dict_$->{1..2}

spring.shardingsphere.sharding.tables.t_dict.key-generator.column=dict_id
spring.shardingsphere.sharding.tables.t_dict.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.t_dict.key-generator.props.worker.id=1
spring.shardingsphere.sharding.tables.t_dict.table-strategy.inline.sharding-column=ustatus
spring.shardingsphere.sharding.tables.t_dict.table-strategy.inline.algorithm-expression=t_dict_$->{ustatus.toInteger()%2+1}

spring.shardingsphere.sharding.tables.user.actual-data-nodes=m1.t_user_$->{1..2}
spring.shardingsphere.sharding.tables.user.key-generator.column=user_id
spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.user.key-generator.props.worker.id=1
spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=ustatus
spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=t_user_$->{ustatus.toInteger()%2+1}
#绑定表示例
spring.shardingsphere.sharding.binding-tables[0]=user,t_dict

spring.shardingsphere.props.sql.show = true
spring.main.allow-bean-definition-overriding=true


创建application04.properties

代码如下(示例):

#配置主从数据源,要基于MySQL主从架构。
spring.shardingsphere.datasource.names=m0,s0

spring.shardingsphere.datasource.m0.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m0.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m0.url=jdbc:mysql://139.224.137.74:3307/masterdemo?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m0.username=root
spring.shardingsphere.datasource.m0.password=ca0a997ee4770063

spring.shardingsphere.datasource.s0.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.s0.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.s0.url=jdbc:mysql://106.14.132.94:3308/masterdemo?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.s0.username=root
spring.shardingsphere.datasource.s0.password=JHWLXeT56iJiBwDG
#读写分离规则, m0 主库,s0 从库
spring.shardingsphere.sharding.master-slave-rules.ds0.master-data-source-name=m0
spring.shardingsphere.sharding.master-slave-rules.ds0.slave-data-source-names[0]=s0
#基于读写分离的表分片
spring.shardingsphere.sharding.tables.t_dict.actual-data-nodes=ds0.t_dict

spring.shardingsphere.sharding.tables.t_dict.key-generator.column=dict_id
spring.shardingsphere.sharding.tables.t_dict.key-generator.type=SNOWFLAKE
spring.shardingsphere.sharding.tables.t_dict.key-generator.props.worker.id=1

spring.shardingsphere.props.sql.show = true
spring.main.allow-bean-definition-overriding=true


创建Course

代码如下(示例):

package com.example.apacheshardingspheredemo.entity;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class Course {

    private Long cid;
    private String cname;
    private Long userId;
    private String cstatus;

    public Long getCid() {
        return cid;
    }

    public void setCid(Long cid) {
        this.cid = cid;
    }

    public String getCname() {
        return cname;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getCstatus() {
        return cstatus;
    }

    public void setCstatus(String cstatus) {
        this.cstatus = cstatus;
    }

    @Override
    public String toString() {
        return "Course{" +
                "cid=" + cid +
                ", cname='" + cname + '\'' +
                ", userId=" + userId +
                ", cstatus='" + cstatus + '\'' +
                '}';
    }
}

创建Dict

代码如下(示例):

package com.example.apacheshardingspheredemo.entity;

import com.baomidou.mybatisplus.annotation.TableName;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
@TableName("t_dict")
public class Dict {
    private Long dictId;
    private String ustatus;
    private String uvalue;

    public Long getDictId() {
        return dictId;
    }

    public void setDictId(Long dictId) {
        this.dictId = dictId;
    }

    public String getUstatus() {
        return ustatus;
    }

    public void setUstatus(String ustatus) {
        this.ustatus = ustatus;
    }

    public String getUvalue() {
        return uvalue;
    }

    public void setUvalue(String uvalue) {
        this.uvalue = uvalue;
    }

    @Override
    public String toString() {
        return "Dict{" +
                "dictId=" + dictId +
                ", ustatus='" + ustatus + '\'' +
                ", uvalue='" + uvalue + '\'' +
                '}';
    }
}

创建User

代码如下(示例):

package com.example.apacheshardingspheredemo.entity;

import com.baomidou.mybatisplus.annotation.TableName;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
@TableName("user")
public class User {

    private Long userId;
    private String username;
    private String ustatus;
    private int uage;

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUstatus() {
        return ustatus;
    }

    public void setUstatus(String ustatus) {
        this.ustatus = ustatus;
    }

    public int getUage() {
        return uage;
    }

    public void setUage(int uage) {
        this.uage = uage;
    }

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", ustatus='" + ustatus + '\'' +
                ", uage=" + uage +
                '}';
    }
}

创建CourseMapper

代码如下(示例):

package com.example.apacheshardingspheredemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.apacheshardingspheredemo.entity.Course;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public interface CourseMapper extends BaseMapper<Course> {
}

创建DictMapper

代码如下(示例):

package com.example.apacheshardingspheredemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.apacheshardingspheredemo.entity.Dict;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public interface DictMapper extends BaseMapper<Dict> {
}

创建UserMapper

代码如下(示例):

package com.example.apacheshardingspheredemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.apacheshardingspheredemo.entity.User;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("select u.user_id,u.username,d.uvalue ustatus from user u left join t_dict d on u.ustatus = d.ustatus")
    public List<User> queryUserStatus();
}

创建MyComplexDSShardingAlgorithm

代码如下(示例):

package com.example.apacheshardingspheredemo.algorithem;

import com.google.common.collect.Range;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class MyComplexDSShardingAlgorithm implements ComplexKeysShardingAlgorithm<Long> {
    //    SELECT  cid,cname,user_id,cstatus  FROM course
    //    WHERE  cid BETWEEN ? AND ? AND user_id = ?
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Long> shardingValue) {
        Range<Long> cidRange = shardingValue.getColumnNameAndRangeValuesMap().get("cid");
        Collection<Long> userIdCol = shardingValue.getColumnNameAndShardingValuesMap().get("user_id");

        Long upperVal = cidRange.upperEndpoint();
        Long lowerVal = cidRange.lowerEndpoint();

        List<String> res = new ArrayList<>();

        for(Long userId: userIdCol){
            //course_{userID%2+1}
            BigInteger userIdB = BigInteger.valueOf(userId);
            BigInteger target = (userIdB.mod(new BigInteger("2"))).add(new BigInteger("1"));

            res.add("m"+target);
        }

        return res;
    }
}

创建MyComplexTableShardingAlgorithm

代码如下(示例):

package com.example.apacheshardingspheredemo.algorithem;

import com.google.common.collect.Range;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class MyComplexTableShardingAlgorithm implements ComplexKeysShardingAlgorithm<Long> {
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Long> shardingValue) {
        Range<Long> cidRange = shardingValue.getColumnNameAndRangeValuesMap().get("cid");
        Collection<Long> userIdCol = shardingValue.getColumnNameAndShardingValuesMap().get("user_id");

        Long upperVal = cidRange.upperEndpoint();
        Long lowerVal = cidRange.lowerEndpoint();

        List<String> res = new ArrayList<>();

        for(Long userId: userIdCol){
            //course_{userID%2+1}
            BigInteger userIdB = BigInteger.valueOf(userId);
            BigInteger target = (userIdB.mod(new BigInteger("2"))).add(new BigInteger("1"));

            res.add(shardingValue.getLogicTableName()+"_"+target);
        }

        return res;
    }
}

创建MyHintTableShardingAlgorithm

代码如下(示例):

package com.example.apacheshardingspheredemo.algorithem;

import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;

import java.util.Arrays;
import java.util.Collection;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class MyHintTableShardingAlgorithm implements HintShardingAlgorithm<Integer> {
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, HintShardingValue<Integer> shardingValue) {
        String key = shardingValue.getLogicTableName() + "_" + shardingValue.getValues().toArray()[0];
        if(availableTargetNames.contains(key)){
            return Arrays.asList(key);
        }
        throw new UnsupportedOperationException("route "+ key +" is not supported ,please check your config");
    }
}

创建MyPreciseDSShardingAlgorithm

代码如下(示例):

package com.example.apacheshardingspheredemo.algorithem;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.math.BigInteger;
import java.util.Collection;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class MyPreciseDSShardingAlgorithm implements PreciseShardingAlgorithm<Long> {
    //select * from course where cid = ? or cid in (?,?)
    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
        String logicTableName = shardingValue.getLogicTableName();
        String cid = shardingValue.getColumnName();
        Long cidValue = shardingValue.getValue();
        //实现 course_$->{cid%2+1)
        BigInteger shardingValueB = BigInteger.valueOf(cidValue);
        BigInteger resB = (shardingValueB.mod(new BigInteger("2"))).add(new BigInteger("1"));
        String key = "m"+resB;
        if(availableTargetNames.contains(key)){
            return key;
        }
        //couse_1, course_2
        throw new UnsupportedOperationException("route "+ key +" is not supported ,please check your config");
    }
}

创建MyPreciseTableShardingAlgorithm

代码如下(示例):

package com.example.apacheshardingspheredemo.algorithem;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.math.BigInteger;
import java.util.Collection;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class MyPreciseTableShardingAlgorithm implements PreciseShardingAlgorithm<Long> {
    //select * from course where cid = ? or cid in (?,?)
    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
        String logicTableName = shardingValue.getLogicTableName();
        String cid = shardingValue.getColumnName();
        Long cidValue = shardingValue.getValue();
        //实现 course_$->{cid%2+1)
        BigInteger shardingValueB = BigInteger.valueOf(cidValue);
        BigInteger resB = (shardingValueB.mod(new BigInteger("2"))).add(new BigInteger("1"));
        String key = logicTableName+"_"+resB;
        if(availableTargetNames.contains(key)){
            return key;
        }
        //couse_1, course_2
        throw new UnsupportedOperationException("route "+ key +" is not supported ,please check your config");
    }
}

创建MyRangeDSShardingAlgorithm

代码如下(示例):

package com.example.apacheshardingspheredemo.algorithem;

import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Arrays;
import java.util.Collection;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class MyRangeDSShardingAlgorithm implements RangeShardingAlgorithm<Long> {
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<Long> shardingValue) {
        //select * from course where cid between 1 and 100;
        Long upperVal = shardingValue.getValueRange().upperEndpoint();//100
        Long lowerVal = shardingValue.getValueRange().lowerEndpoint();//1

        String logicTableName = shardingValue.getLogicTableName();
        return Arrays.asList("m1","m2");
    }
}

创建MyRangeTableShardingAlgorithm

代码如下(示例):

package com.example.apacheshardingspheredemo.algorithem;

import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Arrays;
import java.util.Collection;

/**
 * @Author: liaozhiwei
 * @Description: TODO
 * @Date: Created in 21:16 2022/9/2
 */
public class MyRangeTableShardingAlgorithm implements RangeShardingAlgorithm<Long> {
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<Long> shardingValue) {
        //select * from course where cid between 1 and 100;
        Long upperVal = shardingValue.getValueRange().upperEndpoint();//100
        Long lowerVal = shardingValue.getValueRange().lowerEndpoint();//1

        String logicTableName = shardingValue.getLogicTableName();
        return Arrays.asList(logicTableName+"_1",logicTableName+"_2");
    }
}

创建course.sql

代码如下(示例):

-- 在三个库中创建
CREATE TABLE course_1 (
	cid BIGINT(20) PRIMARY KEY,
	cname VARCHAR(50) NOT NULL,
	user_id BIGINT(20) NOT NULL,
	cstatus varchar(10) NOT NULL
);

CREATE TABLE course_2 (
	cid BIGINT(20) PRIMARY KEY,
	cname VARCHAR(50) NOT NULL,
	user_id BIGINT(20) NOT NULL,
	cstatus varchar(10) NOT NULL
);
创建t_dict.sql

代码如下(示例):

-- 在三个库中创建
CREATE TABLE `t_dict`  (
  `dict_id` bigint(0) PRIMARY KEY NOT NULL,
  `ustatus` varchar(100) NOT NULL,
  `uvalue` varchar(100) NOT NULL
);
-- 在userdb中创建
CREATE TABLE `t_dict_1`  (
  `dict_id` bigint(0) PRIMARY KEY NOT NULL,
  `ustatus` varchar(100) NOT NULL,
  `uvalue` varchar(100) NOT NULL
);
CREATE TABLE `t_dict_2`  (
  `dict_id` bigint(0) PRIMARY KEY NOT NULL,
  `ustatus` varchar(100) NOT NULL,
  `uvalue` varchar(100) NOT NULL
);
创建t_user.sql

代码如下(示例):

--在userdb中创建
CREATE TABLE `t_user`  (
  `user_id` bigint(0) PRIMARY KEY NOT NULL,
  `username` varchar(100) NOT NULL,
  `ustatus` varchar(50) NOT NULL,
  `uage` int(3)
);

CREATE TABLE `t_user_1`  (
  `user_id` bigint(0) PRIMARY KEY NOT NULL,
  `username` varchar(100) NOT NULL,
  `ustatus` varchar(50) NOT NULL,
  `uage` int(3)
);
CREATE TABLE `t_user_2`  (
  `user_id` bigint(0) PRIMARY KEY NOT NULL,
  `username` varchar(100) NOT NULL,
  `ustatus` varchar(50) NOT NULL,
  `uage` int(3)
);
修改ApacheShardingsphereDemoApplicationTests

代码如下(示例):

package com.example.apacheshardingspheredemo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.apacheshardingspheredemo.entity.Course;
import com.example.apacheshardingspheredemo.entity.Dict;
import com.example.apacheshardingspheredemo.entity.User;
import com.example.apacheshardingspheredemo.mapper.CourseMapper;
import com.example.apacheshardingspheredemo.mapper.DictMapper;
import com.example.apacheshardingspheredemo.mapper.UserMapper;
import org.apache.shardingsphere.api.hint.HintManager;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
class ApacheShardingsphereDemoApplicationTests {

    @Resource
    CourseMapper courseMapper;
    @Resource
    DictMapper dictMapper;
    @Resource
    UserMapper userMapper;

    @Test
    public void addCourse(){
        for(int i = 0 ; i < 10 ; i ++){
            Course c = new Course();
//            c.setCid(Long.valueOf(i));//配置文件里面选择了雪花算法生成主键id,所以这里就不需要cid自己生成了
            c.setCname("shardingsphere");
            c.setUserId(Long.valueOf(""+(1000+i)));
            c.setCstatus("1");
            courseMapper.insert(c);
        }
    }

    @Test
    public void queryCourse(){
        //select * from course
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("cid");
        wrapper.eq("cid",553684818806706177L);
//        wrapper.in()
        List<Course> courses = courseMapper.selectList(wrapper);
        courses.forEach(course -> System.out.println(course));
    }

    @Test
    public void queryOrderRange(){
        //select * from course
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.between("cid",553684818806706177L,553684819184193537L);
//        wrapper.in()
        List<Course> courses = courseMapper.selectList(wrapper);
        courses.forEach(course -> System.out.println(course));
    }

    @Test
    public void queryCourseComplex(){
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.between("cid",553684818806706177L,553684819184193537L);
        wrapper.eq("user_id",1009L);
//        wrapper.in()
        List<Course> courses = courseMapper.selectList(wrapper);
        courses.forEach(course -> System.out.println(course));
    }

    @Test
    public void queryCourseByHint(){
        HintManager hintManager = HintManager.getInstance();
        hintManager.addTableShardingValue("course",2);
        List<Course> courses = courseMapper.selectList(null);
        courses.forEach(course -> System.out.println(course));
        hintManager.close();
    }

    @Test
    public void addDict(){
        Dict d1 = new Dict();
        d1.setUstatus("1");
        d1.setUvalue("正常");
        dictMapper.insert(d1);

        Dict d2 = new Dict();
        d2.setUstatus("0");
        d2.setUvalue("不正常");
        dictMapper.insert(d2);

        for(int i = 0 ; i < 10 ; i ++){
            User user = new User();
            user.setUsername("user No "+i);
            user.setUstatus(""+(i%2));
            user.setUage(i*10);
            userMapper.insert(user);
        }
    }

    @Test
    public void queryUserStatus(){
        List<User> users = userMapper.queryUserStatus();
        users.forEach(user -> System.out.println(user));
    }

    @Test
    public void addDictByMS(){
        Dict d1 = new Dict();
        d1.setUstatus("1");
        d1.setUvalue("正常");
        dictMapper.insert(d1);

        Dict d2 = new Dict();
        d2.setUstatus("0");
        d2.setUvalue("不正常");
        dictMapper.insert(d2);
    }

    @Test
    public void queryDictByMS(){
        List<Dict> dicts = dictMapper.selectList(null);
        dicts.forEach(dict -> System.out.println(dict));
    }

}

校验Apache ShardingSphere是否正常工作

分表插入

把application01.properties的配置复制粘贴到application.properties里面
生成coursedb库,同时把course.sql执行一下,生成二个表
去ApacheShardingsphereDemoApplicationTests运行addCourse方法
控制台打印的日志:

E:\Company\JDK\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50297,suspend=y,server=n -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:S:\SoftWare\IntelliJIDEA\plugins\java\lib\rt\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath S:\SoftWare\IntelliJIDEA\lib\idea_rt.jar;C:\Users\Machenike\.m2\repository\org\junit\platform\junit-platform-launcher\1.6.2\junit-platform-launcher-1.6.2.jar;C:\Users\Machenike\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Machenike\.m2\repository\org\junit\platform\junit-platform-engine\1.6.2\junit-platform-engine-1.6.2.jar;C:\Users\Machenike\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Machenike\.m2\repository\org\junit\platform\junit-platform-commons\1.6.2\junit-platform-commons-1.6.2.jar;C:\Users\Machenike\.m2\repository\org\junit\vintage\junit-vintage-engine\5.6.2\junit-vintage-engine-5.6.2.jar;S:\SoftWare\IntelliJIDEA\plugins\junit\lib\junit5-rt.jar;S:\SoftWare\IntelliJIDEA\plugins\junit\lib\junit-rt.jar;E:\Company\JDK\jre\lib\charsets.jar;E:\Company\JDK\jre\lib\deploy.jar;E:\Company\JDK\jre\lib\ext\access-bridge-64.jar;E:\Company\JDK\jre\lib\ext\cldrdata.jar;E:\Company\JDK\jre\lib\ext\dnsns.jar;E:\Company\JDK\jre\lib\ext\jaccess.jar;E:\Company\JDK\jre\lib\ext\jfxrt.jar;E:\Company\JDK\jre\lib\ext\localedata.jar;E:\Company\JDK\jre\lib\ext\nashorn.jar;E:\Company\JDK\jre\lib\ext\sunec.jar;E:\Company\JDK\jre\lib\ext\sunjce_provider.jar;E:\Company\JDK\jre\lib\ext\sunmscapi.jar;E:\Company\JDK\jre\lib\ext\sunpkcs11.jar;E:\Company\JDK\jre\lib\ext\zipfs.jar;E:\Company\JDK\jre\lib\javaws.jar;E:\Company\JDK\jre\lib\jce.jar;E:\Company\JDK\jre\lib\jfr.jar;E:\Company\JDK\jre\lib\jfxswt.jar;E:\Company\JDK\jre\lib\jsse.jar;E:\Company\JDK\jre\lib\management-agent.jar;E:\Company\JDK\jre\lib\plugin.jar;E:\Company\JDK\jre\lib\resources.jar;E:\Company\JDK\jre\lib\rt.jar;W:\Personal\java_wxid\demo\apache-shardingsphere-demo\target\test-classes;W:\Personal\java_wxid\demo\apache-shardingsphere-demo\target\classes;E:\Company\RepMaven\org\apache\shardingsphere\sharding-jdbc-spring-boot-starter\4.1.1\sharding-jdbc-spring-boot-starter-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-spring-boot-util\4.1.1\sharding-spring-boot-util-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-core-common\4.1.1\sharding-core-common-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-common\4.1.1\shardingsphere-common-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-spi\4.1.1\shardingsphere-spi-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-binder\4.1.1\shardingsphere-sql-parser-binder-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-core-api\4.1.1\sharding-core-api-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\encrypt-core-api\4.1.1\encrypt-core-api-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\encrypt-core-common\4.1.1\encrypt-core-common-4.1.1.jar;E:\Company\RepMaven\org\codehaus\groovy\groovy\2.4.5\groovy-2.4.5-indy.jar;E:\Company\RepMaven\commons-codec\commons-codec\1.14\commons-codec-1.14.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-transaction-spring\4.1.1\sharding-transaction-spring-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-transaction-core\4.1.1\sharding-transaction-core-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-jdbc-core\4.1.1\sharding-jdbc-core-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-pluggable\4.1.1\shardingsphere-pluggable-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-route\4.1.1\shardingsphere-route-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-rewrite-engine\4.1.1\shardingsphere-rewrite-engine-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-executor\4.1.1\shardingsphere-executor-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-merge\4.1.1\shardingsphere-merge-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-sql92\4.1.1\shardingsphere-sql-parser-sql92-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-engine\4.1.1\shardingsphere-sql-parser-engine-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-spi\4.1.1\shardingsphere-sql-parser-spi-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-statement\4.1.1\shardingsphere-sql-parser-statement-4.1.1.jar;E:\Company\RepMaven\org\apache\commons\commons-collections4\4.2\commons-collections4-4.2.jar;E:\Company\RepMaven\org\antlr\antlr4-runtime\4.7.2\antlr4-runtime-4.7.2.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-mysql\4.1.1\shardingsphere-sql-parser-mysql-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-postgresql\4.1.1\shardingsphere-sql-parser-postgresql-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-oracle\4.1.1\shardingsphere-sql-parser-oracle-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shardingsphere-sql-parser-sqlserver\4.1.1\shardingsphere-sql-parser-sqlserver-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-core-route\4.1.1\sharding-core-route-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\master-slave-core-route\4.1.1\master-slave-core-route-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-core-rewrite\4.1.1\sharding-core-rewrite-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\encrypt-core-rewrite\4.1.1\encrypt-core-rewrite-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\shadow-core-rewrite\4.1.1\shadow-core-rewrite-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-core-execute\4.1.1\sharding-core-execute-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\sharding-core-merge\4.1.1\sharding-core-merge-4.1.1.jar;E:\Company\RepMaven\org\apache\shardingsphere\encrypt-core-merge\4.1.1\encrypt-core-merge-4.1.1.jar;E:\Company\RepMaven\com\google\guava\guava\18.0\guava-18.0.jar;E:\Company\RepMaven\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;E:\Company\RepMaven\org\slf4j\jcl-over-slf4j\1.7.30\jcl-over-slf4j-1.7.30.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot-starter\2.4.5\spring-boot-starter-2.4.5.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot\2.3.1.RELEASE\spring-boot-2.3.1.RELEASE.jar;E:\Company\RepMaven\org\springframework\spring-context\5.2.7.RELEASE\spring-context-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\springframework\spring-aop\5.2.7.RELEASE\spring-aop-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\springframework\spring-beans\5.2.7.RELEASE\spring-beans-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\springframework\spring-expression\5.2.7.RELEASE\spring-expression-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot-autoconfigure\2.3.1.RELEASE\spring-boot-autoconfigure-2.3.1.RELEASE.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot-starter-logging\2.3.1.RELEASE\spring-boot-starter-logging-2.3.1.RELEASE.jar;E:\Company\RepMaven\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\Company\RepMaven\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\Company\RepMaven\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;E:\Company\RepMaven\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;E:\Company\RepMaven\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;E:\Company\RepMaven\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\Company\RepMaven\org\springframework\spring-core\5.2.7.RELEASE\spring-core-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\springframework\spring-jcl\5.2.7.RELEASE\spring-jcl-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot-starter-test\2.4.1\spring-boot-starter-test-2.4.1.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot-test\2.3.1.RELEASE\spring-boot-test-2.3.1.RELEASE.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot-test-autoconfigure\2.3.1.RELEASE\spring-boot-test-autoconfigure-2.3.1.RELEASE.jar;E:\Company\RepMaven\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;E:\Company\RepMaven\net\minidev\json-smart\2.3\json-smart-2.3.jar;E:\Company\RepMaven\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;E:\Company\RepMaven\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;E:\Company\RepMaven\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;E:\Company\RepMaven\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;E:\Company\RepMaven\org\assertj\assertj-core\3.16.1\assertj-core-3.16.1.jar;E:\Company\RepMaven\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;E:\Company\RepMaven\org\junit\jupiter\junit-jupiter\5.6.2\junit-jupiter-5.6.2.jar;E:\Company\RepMaven\org\junit\jupiter\junit-jupiter-api\5.6.2\junit-jupiter-api-5.6.2.jar;E:\Company\RepMaven\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;E:\Company\RepMaven\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;E:\Company\RepMaven\org\junit\platform\junit-platform-commons\1.6.2\junit-platform-commons-1.6.2.jar;E:\Company\RepMaven\org\junit\jupiter\junit-jupiter-params\5.6.2\junit-jupiter-params-5.6.2.jar;E:\Company\RepMaven\org\junit\jupiter\junit-jupiter-engine\5.6.2\junit-jupiter-engine-5.6.2.jar;E:\Company\RepMaven\org\junit\platform\junit-platform-engine\1.6.2\junit-platform-engine-1.6.2.jar;E:\Company\RepMaven\org\mockito\mockito-core\3.3.3\mockito-core-3.3.3.jar;E:\Company\RepMaven\net\bytebuddy\byte-buddy\1.10.11\byte-buddy-1.10.11.jar;E:\Company\RepMaven\net\bytebuddy\byte-buddy-agent\1.10.11\byte-buddy-agent-1.10.11.jar;E:\Company\RepMaven\org\objenesis\objenesis\2.6\objenesis-2.6.jar;E:\Company\RepMaven\org\mockito\mockito-junit-jupiter\3.3.3\mockito-junit-jupiter-3.3.3.jar;E:\Company\RepMaven\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;E:\Company\RepMaven\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;E:\Company\RepMaven\org\springframework\spring-test\5.2.7.RELEASE\spring-test-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\xmlunit\xmlunit-core\2.7.0\xmlunit-core-2.7.0.jar;E:\Company\RepMaven\com\alibaba\druid\1.1.23\druid-1.1.23.jar;E:\Company\RepMaven\mysql\mysql-connector-java\8.0.22\mysql-connector-java-8.0.22.jar;E:\Company\RepMaven\com\baomidou\mybatis-plus-boot-starter\3.3.2\mybatis-plus-boot-starter-3.3.2.jar;E:\Company\RepMaven\com\baomidou\mybatis-plus\3.3.2\mybatis-plus-3.3.2.jar;E:\Company\RepMaven\com\baomidou\mybatis-plus-extension\3.3.2\mybatis-plus-extension-3.3.2.jar;E:\Company\RepMaven\com\baomidou\mybatis-plus-core\3.3.2\mybatis-plus-core-3.3.2.jar;E:\Company\RepMaven\com\baomidou\mybatis-plus-annotation\3.3.2\mybatis-plus-annotation-3.3.2.jar;E:\Company\RepMaven\com\github\jsqlparser\jsqlparser\3.1\jsqlparser-3.1.jar;E:\Company\RepMaven\org\mybatis\mybatis\3.5.4\mybatis-3.5.4.jar;E:\Company\RepMaven\org\mybatis\mybatis-spring\2.0.4\mybatis-spring-2.0.4.jar;E:\Company\RepMaven\org\springframework\boot\spring-boot-starter-jdbc\2.3.1.RELEASE\spring-boot-starter-jdbc-2.3.1.RELEASE.jar;E:\Company\RepMaven\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;E:\Company\RepMaven\org\springframework\spring-jdbc\5.2.7.RELEASE\spring-jdbc-5.2.7.RELEASE.jar;E:\Company\RepMaven\org\springframework\spring-tx\5.2.7.RELEASE\spring-tx-5.2.7.RELEASE.jar;E:\Company\RepMaven\junit\junit\4.13\junit-4.13.jar;E:\Company\RepMaven\org\hamcrest\hamcrest-core\2.2\hamcrest-core-2.2.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests,addCourse
Connected to the target VM, address: '127.0.0.1:50297', transport: 'socket'
21:45:10.534 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
21:45:10.554 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
21:45:10.584 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
21:45:10.604 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests], using SpringBootContextLoader
21:45:10.604 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests]: class path resource [com/example/apacheshardingspheredemo/ApacheShardingsphereDemoApplicationTests-context.xml] does not exist
21:45:10.604 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests]: class path resource [com/example/apacheshardingspheredemo/ApacheShardingsphereDemoApplicationTestsContext.groovy] does not exist
21:45:10.604 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
21:45:10.604 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests]: ApacheShardingsphereDemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
21:45:10.645 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests]
21:45:10.757 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [W:\Personal\java_wxid\demo\apache-shardingsphere-demo\target\classes\com\example\apacheshardingspheredemo\ApacheShardingsphereDemoApplication.class]
21:45:10.757 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplication for test class com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests
21:45:10.864 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests]: using defaults.
21:45:10.864 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
21:45:10.879 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [javax/servlet/ServletContext]
21:45:10.879 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@4b41e4dd, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@22ffa91a, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@74960bfa, org.springframework.test.context.support.DirtiesContextTestExecutionListener@42721fe, org.springframework.test.context.transaction.TransactionalTestExecutionListener@40844aab, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@1f6c9cd8, org.springframework.test.context.event.EventPublishingTestExecutionListener@5b619d14, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@66746f57, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@447a020, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@7f36662c, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@28e8dde3, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@6d23017e, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@54dcfa5a]
21:45:10.895 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@1d730606 testClass = ApacheShardingsphereDemoApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@3bcbb589 testClass = ApacheShardingsphereDemoApplicationTests, locations = '{}', classes = '{class com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@2dfaea86, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@14fc5f04, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@34bde49d, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@169bb4dd, org.springframework.boot.test.context.SpringBootTestArgs@1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]], class annotated with @DirtiesContext [false] with mode [null].
21:45:10.895 [main] DEBUG org.springframework.test.context.support.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[DefaultTestContext@1d730606 testClass = ApacheShardingsphereDemoApplicationTests, testInstance = com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplicationTests@25a6944c, testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@3bcbb589 testClass = ApacheShardingsphereDemoApplicationTests, locations = '{}', classes = '{class com.example.apacheshardingspheredemo.ApacheShardingsphereDemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@2dfaea86, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@14fc5f04, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@34bde49d, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@169bb4dd, org.springframework.boot.test.context.SpringBootTestArgs@1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]]].
21:45:10.926 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2022-09-03 21:45:11.279  INFO 31084 --- [           main] ApacheShardingsphereDemoApplicationTests : Starting ApacheShardingsphereDemoApplicationTests on DESKTOP-42NQPIS with PID 31084 (started by Machenike in W:\Personal\java_wxid\demo\apache-shardingsphere-demo)
2022-09-03 21:45:11.279  INFO 31084 --- [           main] ApacheShardingsphereDemoApplicationTests : No active profile set, falling back to default profiles: default
2022-09-03 21:45:12.108  INFO 31084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'stringToNoneShardingStrategyConfigurationConverter' of type [org.apache.shardingsphere.spring.boot.converter.StringToNoneShardingStrategyConfigurationConverter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-09-03 21:45:12.124  INFO 31084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.shardingsphere.sharding-org.apache.shardingsphere.shardingjdbc.spring.boot.sharding.SpringBootShardingRuleConfigurationProperties' of type [org.apache.shardingsphere.shardingjdbc.spring.boot.sharding.SpringBootShardingRuleConfigurationProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-09-03 21:45:12.124  INFO 31084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.shardingsphere.masterslave-org.apache.shardingsphere.shardingjdbc.spring.boot.masterslave.SpringBootMasterSlaveRuleConfigurationProperties' of type [org.apache.shardingsphere.shardingjdbc.spring.boot.masterslave.SpringBootMasterSlaveRuleConfigurationProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-09-03 21:45:12.124  INFO 31084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.shardingsphere.encrypt-org.apache.shardingsphere.shardingjdbc.spring.boot.encrypt.SpringBootEncryptRuleConfigurationProperties' of type [org.apache.shardingsphere.shardingjdbc.spring.boot.encrypt.SpringBootEncryptRuleConfigurationProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-09-03 21:45:12.140  INFO 31084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.shardingsphere.shadow-org.apache.shardingsphere.shardingjdbc.spring.boot.shadow.SpringBootShadowRuleConfigurationProperties' of type [org.apache.shardingsphere.shardingjdbc.spring.boot.shadow.SpringBootShadowRuleConfigurationProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-09-03 21:45:12.140  INFO 31084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.shardingsphere-org.apache.shardingsphere.shardingjdbc.spring.boot.common.SpringBootPropertiesConfigurationProperties' of type [org.apache.shardingsphere.shardingjdbc.spring.boot.common.SpringBootPropertiesConfigurationProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-09-03 21:45:12.403  INFO 31084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration' of type [org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration$$EnhancerBySpringCGLIB$$9d45b047] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-09-03 21:45:12.773  INFO 31084 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
2022-09-03 21:45:14.393  INFO 31084 --- [           main] o.a.s.core.log.ConfigurationLogger       : ShardingRuleConfiguration:
tables:
  course:
    actualDataNodes: m1.course_$->{1..2}
    keyGenerator:
      column: cid
      props:
        worker.id: '1'
      type: SNOWFLAKE
    logicTable: course
    tableStrategy:
      inline:
        algorithmExpression: course_$->{cid%2+1}
        shardingColumn: cid

2022-09-03 21:45:14.409  INFO 31084 --- [           main] o.a.s.core.log.ConfigurationLogger       : Properties:
sql.show: 'true'

2022-09-03 21:45:14.462  INFO 31084 --- [           main] ShardingSphere-metadata                  : Loading 1 logic tables' meta data.
2022-09-03 21:45:15.828  INFO 31084 --- [           main] ShardingSphere-metadata                  : Loading 7 tables' meta data.
2022-09-03 21:45:16.730  INFO 31084 --- [           main] ShardingSphere-metadata                  : Meta data load finished, cost 2321 milliseconds.
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.3.2 
2022-09-03 21:45:18.840  WARN 31084 --- [           main] c.b.m.core.metadata.TableInfoHelper      : Can not find table primary key in Class: "com.example.apacheshardingspheredemo.entity.Course".
2022-09-03 21:45:18.978  WARN 31084 --- [           main] c.b.m.core.metadata.TableInfoHelper      : Can not find table primary key in Class: "com.example.apacheshardingspheredemo.entity.Dict".
2022-09-03 21:45:19.009  WARN 31084 --- [           main] c.b.m.core.metadata.TableInfoHelper      : Can not find table primary key in Class: "com.example.apacheshardingspheredemo.entity.User".
2022-09-03 21:45:19.056  INFO 31084 --- [           main] ApacheShardingsphereDemoApplicationTests : Started ApacheShardingsphereDemoApplicationTests in 8.12 seconds (JVM running for 10.404)
2022-09-03 21:45:19.896  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:19.896  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2d4a0671), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2d4a0671, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1000, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939426555760640])])
2022-09-03 21:45:19.896  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_1  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1000, 1, 772939426555760640]
2022-09-03 21:45:20.213  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.213  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@32d1d6c5), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@32d1d6c5, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1001, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939428241870849])])
2022-09-03 21:45:20.213  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_2  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1001, 1, 772939428241870849]
2022-09-03 21:45:20.277  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.277  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@3e8afc2d), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@3e8afc2d, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1002, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939428510306304])])
2022-09-03 21:45:20.285  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_1  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1002, 1, 772939428510306304]
2022-09-03 21:45:20.359  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.359  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@8ce3f27), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@8ce3f27, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1003, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939428854239233])])
2022-09-03 21:45:20.359  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_2  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1003, 1, 772939428854239233]
2022-09-03 21:45:20.440  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.440  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@70805849), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@70805849, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1004, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939429193977856])])
2022-09-03 21:45:20.440  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_1  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1004, 1, 772939429193977856]
2022-09-03 21:45:20.511  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.511  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2567c091), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2567c091, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1005, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939429491773441])])
2022-09-03 21:45:20.511  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_2  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1005, 1, 772939429491773441]
2022-09-03 21:45:20.573  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.573  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@74bfdd66), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@74bfdd66, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1006, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939429751820288])])
2022-09-03 21:45:20.573  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_1  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1006, 1, 772939429751820288]
2022-09-03 21:45:20.624  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.624  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@7e76a66f), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@7e76a66f, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1007, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939429965729793])])
2022-09-03 21:45:20.624  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_2  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1007, 1, 772939429965729793]
2022-09-03 21:45:20.673  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.673  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@23f8036d), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@23f8036d, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1008, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939430171250688])])
2022-09-03 21:45:20.673  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_1  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1008, 1, 772939430171250688]
2022-09-03 21:45:20.720  INFO 31084 --- [           main] ShardingSphere-SQL                       : Logic SQL: INSERT INTO course  ( cname,
user_id,
cstatus )  VALUES  ( ?,
?,
? )
2022-09-03 21:45:20.720  INFO 31084 --- [           main] ShardingSphere-SQL                       : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@31433df9, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2b058bfd), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@2b058bfd, columnNames=[cname, user_id, cstatus], insertValueContexts=[InsertValueContext(parametersCount=3, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=59, stopIndex=59, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=62, stopIndex=62, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=65, stopIndex=65, parameterMarkerIndex=2), DerivedParameterMarkerExpressionSegment(super=ParameterMarkerExpressionSegment(startIndex=0, stopIndex=0, parameterMarkerIndex=3))], parameters=[shardingsphere, 1009, 1])], generatedKeyContext=Optional[GeneratedKeyContext(columnName=cid, generated=true, generatedValues=[772939430368382977])])
2022-09-03 21:45:20.720  INFO 31084 --- [           main] ShardingSphere-SQL                       : Actual SQL: m1 ::: INSERT INTO course_2  ( cname,
user_id,
cstatus , cid)  VALUES  (?, ?, ?, ?) ::: [shardingsphere, 1009, 1, 772939430368382977]
2022-09-03 21:45:20.773  INFO 31084 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closing ...
2022-09-03 21:45:20.789  INFO 31084 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed
Disconnected from the target VM, address: '127.0.0.1:50297', transport: 'socket'

Process finished with exit code 0

在这里插入图片描述在这里插入图片描述

相关文章:

  • CTF-PUT上传漏洞【超详细】
  • 程序人生 | 编程的上帝视角应该怎么去找
  • KingbaseES V8R3集群运维案例之---主库系统down failover切换过程分析
  • 夏日水果茶饮店如何引流?这四款饮品必学
  • ESP32_esp-idf_lvgl_V8环境搭建移植
  • 人工智能第2版学习——产生式系统2
  • Cortex-A核的异常的处理过程
  • 基于IDEA 工程项目的git实操
  • SAP 多个smartforms同时打印页码问题
  • 离线数仓搭建_03_Hadoop的配置与优化测试
  • 【设计模式】Java设计模式 - 命令模式
  • openstack-mitaka(二) 基于vmware的搭建
  • 【Vue2】VantUI项目入门教程
  • 痛苦与反思:想提升自己,却不知道该如何做
  • C++和QML混合编程_C++端后台多线程处理
  • (十五)java多线程之并发集合ArrayBlockingQueue
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • 《微软的软件测试之道》成书始末、出版宣告、补充致谢名单及相关信息
  • 【407天】跃迁之路——程序员高效学习方法论探索系列(实验阶段164-2018.03.19)...
  • Android Volley源码解析
  • Java编程基础24——递归练习
  • nodejs调试方法
  • vue和cordova项目整合打包,并实现vue调用android的相机的demo
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 蓝海存储开关机注意事项总结
  • 模型微调
  • 嵌入式文件系统
  • 线性表及其算法(java实现)
  • 如何用纯 CSS 创作一个货车 loader
  • ​​快速排序(四)——挖坑法,前后指针法与非递归
  • ###STL(标准模板库)
  • #vue3 实现前端下载excel文件模板功能
  • #设计模式#4.6 Flyweight(享元) 对象结构型模式
  • $redis-setphp_redis Set命令,php操作Redis Set函数介绍
  • (1/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (20)目标检测算法之YOLOv5计算预选框、详解anchor计算
  • (3)nginx 配置(nginx.conf)
  • (二)springcloud实战之config配置中心
  • (附源码)springboot课程在线考试系统 毕业设计 655127
  • (附源码)ssm失物招领系统 毕业设计 182317
  • (转)从零实现3D图像引擎:(8)参数化直线与3D平面函数库
  • (转)微软牛津计划介绍——屌爆了的自然数据处理解决方案(人脸/语音识别,计算机视觉与语言理解)...
  • (转载)虚函数剖析
  • .bat批处理(三):变量声明、设置、拼接、截取
  • .NET Core WebAPI中使用swagger版本控制,添加注释
  • .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划
  • .Net 中的反射(动态创建类型实例) - Part.4(转自http://www.tracefact.net/CLR-and-Framework/Reflection-Part4.aspx)...
  • .NET 中使用 TaskCompletionSource 作为线程同步互斥或异步操作的事件
  • .net/c# memcached 获取所有缓存键(keys)
  • .netcore 如何获取系统中所有session_ASP.NET Core如何解决分布式Session一致性问题
  • .NET和.COM和.CN域名区别
  • .secret勒索病毒数据恢复|金蝶、用友、管家婆、OA、速达、ERP等软件数据库恢复
  • @GetMapping和@RequestMapping的区别
  • @RequestParam详解
  • @软考考生,这份软考高分攻略你须知道