zoukankan      html  css  js  c++  java
  • sharding-jdbc

    版本4.0.0-4.1.1

    // 配置表规则
    TableRuleConfiguration tableRuleConfiguration = new TableRuleConfiguration("table_name","databasename.table_name_${0..3}");

    //设置分片策略,这里简单起见直接取模,也可以使用自定义算法来实现分片规则
    tableRuleConfiguration.setTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("applicationId", "table_name_${applicationId % 4}"));
    //tableRuleConfiguration.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "id"));
    // 配置分片规则
    ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
    shardingRuleConfiguration.getTableRuleConfigs().add(tableRuleConfiguration);
    shardingRuleConfiguration.getBindingTableGroups().add("table_name");
    // 配置默认分表策略
    shardingRuleConfiguration.setDefaultTableShardingStrategyConfig(
    new InlineShardingStrategyConfiguration("applicationId", "sale_bill_detail_${applicationId % 4}")
    );
    // 配置默认分库策略
    DataSource datasource = BeanUtil.getDuidDataSource(driverClass,url,user,password);

    Properties props=new Properties();
    //props.put("sql.show", "true");
    Map<String, DataSource> dataSourceMap = new HashMap<>();
    dataSourceMap.put("databasename", datasource);
    return ShardingDataSourceFactory.createDataSource(dataSourceMap,
    shardingRuleConfiguration, props);

    版本:3.0.0

    <!--sharding-jdbc-->
    <dependency>
    <groupId>io.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-namespace</artifactId>
    <version>3.0.0</version>
    </dependency>

    TableRuleConfiguration tableRuleConfiguration = new TableRuleConfiguration();
    tableRuleConfiguration.setLogicTable("sale_bill_detail");
    tableRuleConfiguration.setActualDataNodes("mydatabase_name.sale_bill_detail_${0..3}");
    ///设置分片策略,这里简单起见直接取模,也可以使用自定义算法来实现分片规则
    tableRuleConfiguration.setTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("applicationId", "table_name_${applicationId % 4}"));
    //tableRuleConfiguration.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "id"));
    // 配置分片规则
    ShardingRuleConfiguration shardingRuleConfiguration = new ShardingRuleConfiguration();
    shardingRuleConfiguration.getTableRuleConfigs().add(tableRuleConfiguration);
    shardingRuleConfiguration.getBindingTableGroups().add("table_name");
    // 配置默认分表策略
    shardingRuleConfiguration.setDefaultTableShardingStrategyConfig(
    new InlineShardingStrategyConfiguration("applicationId", "sale_bill_detail_${applicationId % 4}")
    );
    // 配置默认分库策略
    DataSource datasource = BeanUtil.getDuidDataSource(driverClass,url,user,password);


    Properties props=new Properties();
    //props.put("sql.show", "true");
    Map<String, DataSource> dataSourceMap = new HashMap<>();
    dataSourceMap.put("mydatabase_name", datasource);
    return ShardingDataSourceFactory.createDataSource(dataSourceMap,
    shardingRuleConfiguration, null, props);

  • 相关阅读:
    配置phpmyadmin使登录时可填写IP管理多台MySQL 连接多个数据库 自动登录
    PHP: 深入pack/unpack 字节序
    QQWry.dat 数据写入
    apache 配置order allow deny讲解
    Linux运行与控制后台进程的方法:nohup, setsid, &, disown, screen
    jQuery事件之on()方法绑定多个选择器,多个事件
    centos安装zendstudio centos系统
    apache常见错误汇总
    apache配置文件
    Linux中如何让命令在后台运行
  • 原文地址:https://www.cnblogs.com/andydao/p/14004754.html
Copyright © 2011-2022 走看看