sharding-jdbc 4.0 from start to abandon

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

1.0 Because of business development, the amount of data to reach the single million level, and according to one million monthly increments, mysql single table obviously unable to meet existing business development, intends to sub-table operation, I thought sharding-jdbc, was also concerned about the development the development of Apache 4.0 now, think should meet their own needs a
relatively detailed configure their own projects, spring boot, mybatis, druid, Tell me what network introduced
to change the settings, adding maven dependence

<dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>${sharding-jdbc.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-core</artifactId>
            <version>${sharding-jdbc.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>sharding-core-parse-oracle</artifactId>
                    <groupId>org.apache.shardingsphere</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>sharding-core-parse-postgresql</artifactId>
                    <groupId>org.apache.shardingsphere</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>sharding-core-parse-sqlserver</artifactId>
                    <groupId>org.apache.shardingsphere</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-runtime</artifactId>
            <version>4.7.2</version>
        </dependency>

I do not know why not automatically rely antlr4, obviously strongly dependent on resolution, but also being given to find their own
because they only points table, regardless of the library, so sharding configuration according to the instructions of the official website, of course, also experienced a toss

spring:
 profiles: dev
 shardingsphere:
   datasource:
     name: ds
     ds:
       url: jdbc:mysql://
       username: root
       password: 123456
       filters: log4j,wall,mergeStat
       type: com.alibaba.druid.pool.DruidDataSource
       driver-class-name: com.mysql.jdbc.Driver
  sharding:
     tables:
       account_flow:
         tableStrategy:
           standard:
             shardingColumn: trade_time
             preciseAlgorithmClassName: com.elm.account.config.sharding.AccountFlowTableStrategy
             rangeAlgorithmClassName: com.elm.account.config.sharding.AccountFlowTableStrategy
     bindingTables:
       - account_flow
   props:
     sql.show: true

See the introduction of support is inline but a good little, ah, changed to the standard strategy that he realized =, in, and method, as follows

/**
 * 订单流水的分表规则
 * @author by jueyue on 19-6-15.
 */
public class AccountFlowTableStrategy implements PreciseShardingAlgorithm<String>, RangeShardingAlgorithm<String> {

    DateTimeFormatter formFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    DateTimeFormatter toFormatter   = DateTimeFormatter.ofPattern("yyyyMM");

    @Override
    public String doSharding(Collection collection, PreciseShardingValue preciseShardingValue) {
        return preciseShardingValue.getLogicTableName() + "_" + preciseShardingValue.getValue().toString().substring(0, 7).replaceAll("-", "");
    }

    @Override
    public Collection<String> doSharding(Collection collection, RangeShardingValue rangeShardingValue) {
        List<String>  list      = new ArrayList<>();
        Range<String> ranges    = rangeShardingValue.getValueRange();
        LocalDateTime startTime = LocalDateTime.parse(ranges.lowerEndpoint(), formFormatter);
        LocalDateTime endTime   = LocalDateTime.parse(ranges.upperEndpoint(), formFormatter);
        while (startTime.isBefore(endTime)) {
            list.add(rangeShardingValue.getLogicTableName() + "_" + startTime.format(toFormatter));
            startTime = startTime.plusMonths(1);
        }
        return list;
    }
}

Start, being given that the table can not be found, the original table I have been deleted, changed monthly table, by the way, jdk8 time is really easy to use, find the original database forget the comment, go the original database comment the query is successful,
then the problem comes, because account information is modified several functions with the mysql, substring, md5, concat, upper result seems to be substring can be identified, the other three are parsing failed to find various documents have not found that if resolved, could not think of a function, in this mysql sql into a function, or sql resolution failed, they began looking for information, but it looks like that is not supported, I can not think of skipping resolve this step, the implementation of the original rules, found HintStrategy strategy seems to feel that we should be, but the result still JJ

Zhaolaizhaoqu spent two days I could not find how to get to my sql smooth implementation, to mention one issue, intend to give up in favor of the partition table plus mysql migration history table to achieve, such as the official website to see again achieve more and then point it.

Guess you like

Origin blog.csdn.net/jueyue/article/details/92366688