sharding jdbc初探

2018年12月01日 随笔杂谈 评论 11 条
摘要:

sharding jdbc初探

官方网址:http://shardingsphere.io

与其他中间件对比

Sharding-JDBC的整体架构图


SQL支持详细列表

http://shardingsphere.io/document/legacy/2.x/cn/01-start/sql-supported/

JDBC未支持列表

http://shardingsphere.io/document/legacy/2.x/cn/01-start/limitations/

简单分表实例:
maven 引用

<dependency>
    <groupId>io.shardingjdbc</groupId>
    <artifactId>sharding-jdbc-core</artifactId>
    <version>2.0.0.M3</version>
</dependency>
<dependency>
    <groupId>io.shardingjdbc</groupId>
    <artifactId>sharding-jdbc-spring-namespace</artifactId>
<version>2.0.0.M3</version>

分库分表见:
http://shardingsphere.io/document/legacy/2.x/cn/02-guide/sharding/
实现了按某个字段所带的日期进行分表,供参考,后台的表半年一个,例如XXX_2018_1_6,XXX_2018_7_12

public final class PreciseModuloTableShardingAlgorithm implements PreciseShardingAlgorithm<String> {
    @Override
    public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<String> shardingValue) {
        int year, month;
        if (null != shardingValue && null != shardingValue.getValue()) {
            String value = shardingValue.getValue();
            year = Integer.valueOf(value.substring(0, 4));
            month = Integer.valueOf(value.substring(4, 6));
        } else {
            LocalDate today = LocalDate.now();
            year = today.getYear();
            month = today.getMonthValue();
        }
        for (String each : availableTargetNames) {
            //获取后缀
            String[] split1 = each.split("_");
            if (Integer.valueOf(split1[split1.length - 3]).equals(year)) {
                if (Integer.valueOf(split1[split1.length - 2]) <= month && month <= Integer.valueOf(split1[split1.length - 1])) {
                    return each;
                }
            }
        }
        throw new UnsupportedOperationException();
    }
}

源码分析参考:

11 条留言  访客:11 条  博主:0 条

  1. It抯 arduous to search out knowledgeable people on this matter, however you sound like you realize what you抮e talking about! Thanks

  2. I抦 impressed, I must say. Really not often do I encounter a blog that抯 each educative and entertaining, and let me tell you, you could have hit the nail on the head. Your idea is outstanding; the difficulty is one thing that not sufficient individuals are talking intelligently about. I am very happy that I stumbled across this in my seek for one thing relating to this.

  3. There are actually loads of details like that to take into consideration. That may be a nice level to bring up. I offer the thoughts above as basic inspiration but clearly there are questions just like the one you deliver up the place the most important thing shall be working in sincere good faith. I don?t know if best practices have emerged round issues like that, however I am certain that your job is clearly recognized as a good game. Each girls and boys feel the influence of only a second抯 pleasure, for the rest of their lives.

  4. Spot on with this write-up, I actually assume this web site wants way more consideration. I抣l probably be again to read far more, thanks for that info.

  5. There are definitely loads of details like that to take into consideration. That is a great point to deliver up. I supply the thoughts above as normal inspiration however clearly there are questions just like the one you carry up where the most important factor will probably be working in trustworthy good faith. I don?t know if greatest practices have emerged round issues like that, but I’m certain that your job is clearly identified as a good game. Each boys and girls really feel the impression of only a second抯 pleasure, for the remainder of their lives.

  6. It抯 arduous to search out educated individuals on this topic, however you sound like you understand what you抮e speaking about! Thanks

  7. Thanks for finally talking about > sharding jdbc初探 | 知乐思维 < Loved it!

  8. Everything said was actually very logical. However, what about this?
    what if you typed a catchier post title? I am not suggesting your information is not solid, but suppose you added a headline to maybe grab people’s attention? I mean sharding jdbc初探 | 知乐思维 is a little boring.
    You could look at Yahoo’s front page and note how
    they create news titles to get people to click. You might add a related video or a related picture
    or two to grab people interested about everything’ve written. In my opinion, it would make your website a little bit more interesting.

  9. Thanks for finally talking about > sharding jdbc初探 | 知乐思维 < Loved it!

  10. I think what you posted was very reasonable. However,
    what about this? suppose you composed a catchier title? I ain’t
    saying your information is not good., but what if you added a headline that makes people desire more?
    I mean sharding jdbc初探 | 知乐思维 is kinda vanilla.
    You ought to look at Yahoo’s home page and see how
    they create post titles to get viewers interested.

    You might try adding a video or a pic or two to grab readers
    interested about everything’ve got to say. Just my opinion, it could make
    your posts a little bit more interesting.

  11. I think what you said was actually very logical. But,
    what about this? suppose you composed a catchier title?
    I mean, I don’t wish to tell you how to run your website, however suppose
    you added a title that grabbed people’s attention? I mean sharding jdbc初探 | 知乐思维 is a little plain. You could look at Yahoo’s front page and note how
    they write news headlines to get people interested.

    You might add a related video or a related pic or two to
    grab readers excited about what you’ve got to say. Just my opinion, it might make
    your posts a little bit more interesting.

给我留言

Copyright © 知乐思维 保留所有权利.   Ality主题 粤ICP备14062485

用户登录

分享到: