当前位置: 首页>>代码示例>>Java>>正文


Java ShardingRule类代码示例

本文整理汇总了Java中com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule的典型用法代码示例。如果您正苦于以下问题:Java ShardingRule类的具体用法?Java ShardingRule怎么用?Java ShardingRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShardingRule类属于com.dangdang.ddframe.rdb.sharding.api.rule包,在下文中一共展示了ShardingRule类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getShardingDataSource

import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule; //导入依赖的package包/类
private static ShardingDataSource getShardingDataSource() {
    DataSourceRule dataSourceRule = new DataSourceRule(createDataSourceMap());
    TableRule orderTableRule = TableRule.builder("t_order").actualTables(Arrays.asList(
            "db0.t_order_0", "db0.t_order_1",
            "db1.t_order_0", "db1.t_order_1"
    )).dataSourceRule(dataSourceRule).build();
    TableRule orderItemTableRule = TableRule.builder("t_order_item").actualTables(Arrays.asList(
            "db0.t_order_item_0", "db0.t_order_item_1",
            "db1.t_order_item_0", "db1.t_order_item_1"
    )).dataSourceRule(dataSourceRule).build();
    ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Arrays.asList(orderTableRule, orderItemTableRule))
            .bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule))))
            .databaseShardingStrategy(new DatabaseShardingStrategy("user_id", new ModuloDatabaseShardingAlgorithm()))
            .tableShardingStrategy(new TableShardingStrategy("order_id", new ModuloTableShardingAlgorithm())).build();
    return new ShardingDataSource(shardingRule);
}
 
开发者ID:rpgmakervx,项目名称:slardar,代码行数:17,代码来源:ShardingTest.java

示例2: ShardingDataSource

import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule; //导入依赖的package包/类
@Bean(name = "shardingDataSource")
@Primary
public DataSource ShardingDataSource() {
	log.info("-------------------- ShardingDataSource init ---------------------");
	// 表规则可以指定每张表在数据源中的分布情况
	TableRule orderTableRule = TableRule.builder("t_order").actualTables(Arrays.asList("t_order_0", "t_order_1"))
			.dataSourceRule(dataSourceRule()).build();
	TableRule orderItemTableRule = TableRule.builder("t_order_item")
			.actualTables(Arrays.asList("t_order_item_0", "t_order_item_1")).dataSourceRule(dataSourceRule())
			.build();
	ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule())
			.tableRules(Arrays.asList(orderTableRule, orderItemTableRule))
			// 绑定表代表一组表,这组表的逻辑表与实际表之间的映射关系是相同的。比如t_order与t_order_item就是这样一组绑定表关系,它们的分库与分表策略是完全相同的,那么可以使用它们的表规则将它们配置成绑定表
			.bindingTableRules(Collections
					.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule))))
			.databaseShardingStrategy(
					new DatabaseShardingStrategy("user_id", new ModuloDatabaseShardingAlgorithm()))
			.tableShardingStrategy(new TableShardingStrategy("order_id", new ModuloTableShardingAlgorithm()))
			// 多分片键值
			// .tableShardingStrategy(new TableShardingStrategy(Arrays.asList("order_id","user_id"), new
			// MultipleKeysModuloTableShardingAlgorithm()))
			.build();
	return new ShardingDataSource(shardingRule);
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:25,代码来源:DataSourceConfiguration.java

示例3: getShardingDataSource

import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule; //导入依赖的package包/类
public static ShardingDataSource getShardingDataSource(DataSourceRule dataSourceRule) {
		// 表规则可以指定每张表在数据源中的分布情况
		TableRule orderTableRule = TableRule.builder("t_order").actualTables(Arrays.asList("t_order_0", "t_order_1"))
				.dataSourceRule(dataSourceRule).build();
		TableRule orderItemTableRule = TableRule.builder("t_order_item")
				.actualTables(Arrays.asList("t_order_item_0", "t_order_item_1")).dataSourceRule(dataSourceRule).build();
		ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule)
				.tableRules(Arrays.asList(orderTableRule, orderItemTableRule))
				// 绑定表代表一组表,这组表的逻辑表与实际表之间的映射关系是相同的。比如t_order与t_order_item就是这样一组绑定表关系,它们的分库与分表策略是完全相同的,那么可以使用它们的表规则将它们配置成绑定表
				.bindingTableRules(Collections
						.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule))))
				.databaseShardingStrategy(
						new DatabaseShardingStrategy("user_id", new ModuloDatabaseShardingAlgorithm()))
				.tableShardingStrategy(new TableShardingStrategy("order_id", new ModuloTableShardingAlgorithm()))
				//多分片键值
//				.tableShardingStrategy(new TableShardingStrategy(Arrays.asList("order_id","user_id"), new MultipleKeysModuloTableShardingAlgorithm()))
				.build();
		return new ShardingDataSource(shardingRule);
	}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:20,代码来源:CommonUtil.java

示例4: shardingDataSource

import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule; //导入依赖的package包/类
@Bean
@Primary
public DataSource shardingDataSource() throws Exception {
	// masterSlaveDataSource Map
	Map<String,DataSource> dataSourceMap = getMasterSlaveDataSourceMap();
	// dataSourceRule
	DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
       
       //tableRuleList
       List<TableRule> tableRuleList = new ArrayList<TableRule>(tableRuleBuilderList.size());
       //shardingRule
       //shardingRuleBuilder由业务系统自行构建分库分表规则
       tableRuleBuilderList.forEach(tableRuleBuilder -> {
       		tableRuleList.add(tableRuleBuilder.dataSourceRule(dataSourceRule).build());
       });
       
     //shardingRule
       ShardingRule shardingRule = ShardingRule.builder()
       			.dataSourceRule(dataSourceRule)
			.tableRules(tableRuleList)
			.databaseShardingStrategy(databaseShardingStrategy)
			.tableShardingStrategy(tableShardingStrategy).build();
	
       return new ShardingDataSource(shardingRule);
}
 
开发者ID:benyzhous,项目名称:springboot-quick-build,代码行数:26,代码来源:ShardingDataSourceAutoConfiguration.java


注:本文中的com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。