Code Monkey home page Code Monkey logo

shardingjdbc-date-algorithm's Introduction

shardingsphere-jdbc-date-algorithm

code style springboot-2.5.2 mybatis-plus-3.5.1

项目介绍

基于springboot+shardingsphere-jdbc+mybatisplus实现按日期 年/月/日 策略进行动态分表兼容配置多数据源,读写分离,主从等

使用说明

根目录有postman文件测试案例

具体可参照案例进行实现即可

新增操作

插入的数据中请不要乱设置ID的值,主键必须人为代码中设置ID为ShardingDateAlgorithmSnowFlake.getId(dateAlgorithmType,date)
插入的数据中该时间字段的值若非为时间区间的表所存储对应的时间数据,就会落在原始表(record)中,符合规则的落入对应表中

查询操作

如果不包含查询条件,就会去查询所有的库中对应该业务表的真实表
如果只带了主键条件,因为主键的值ShardingDateAlgorithmSnowFlake.getId(dateAlgorithmType,date)是带有时间意义的,那么可以直接定位到具体的库和具体的表
如果只带了时间,根据时间范围去多个库中查,拿取对应范围的表。
如果两个都带,就直接定位主键条件即可

更新操作

不能更新复合分片的值(主键的值和时间值),这样会打乱分片策略,定位不到数据位置

注意事项

1. 各库的数据表结构、数据初始化时需保持一致(数据保持一致是对于不进行分片的表而言,分片的表数据是不同的,因为按照分片策略来进行存入)
2. 规定采用该规则分片的表生成的ID必须为varchar类型且采用ShardingDateAlgorithmSnowFlake.getId(dateAlgorithmType,date)进行生成
3. 必须采用@ShardingTransactionType(TransactionType.XA)和@Transactional(rollbackFor = Exception.class)进行搭配
4. 本项目只演示了基本的demo,实际业务上会存在很多sharding不支持的sql问题,具体可访问查看具体sql注意点 https://blog.51cto.com/u_14355948/2708929

shardingjdbc-date-algorithm's People

Contributors

henyi-c avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

shardingjdbc-date-algorithm's Issues

关于生成id的问题

请教一下,为什么配置文件中已约定雪花算法生成id,但是在RecordRecordServiceImpl中的saveRecord赋值id任然生效了,是因为不同版本的mybatis-plus的id生成规则不一样么?
1677466402411
1677466437153

关于自动建表类的问题

按时间分表时,自动建表类,会去扫描数据库中表,初始表名:tb_allianceorder,由于我数据库中另一张表tb_allianceorder_old,引发了错误。也就是说前缀一样的表,是会起冲突的,这个问题有没有优化的办法呢,求助各位大佬。
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.