Commit 4543e4a7 authored by liya.cookie's avatar liya.cookie
Browse files

complete broadcast table fro rawjdbc

parent 1b8e8fd7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class DataSourceUtil {
    
    private static final String USER_NAME = "root";
    
    private static final String PASSWORD = "liya76133951";
    private static final String PASSWORD = "";
    
    public static DataSource createDataSource(final String dataSourceName) {
        HikariDataSource result = new HikariDataSource();
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

package io.shardingsphere.example.sharding.data.jdbc;

import io.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl;
import io.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl;
import io.shardingsphere.example.common.jdbc.repository.RangeOrderRepositoryImpl;
import io.shardingsphere.example.common.jdbc.service.CommonServiceImpl;
@@ -47,6 +48,6 @@ public class JavaRangeConfigurationExample {
    }
    
    private static CommonService getCommonService(final DataSource dataSource) {
        return new CommonServiceImpl(new RangeOrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource));
        return new CommonServiceImpl(new RangeOrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource),new CountryRepositroyImpl(dataSource));
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

package io.shardingsphere.example.sharding.data.jdbc;

import io.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl;
import io.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl;
import io.shardingsphere.example.common.jdbc.repository.OrderRepositoryImpl;
import io.shardingsphere.example.common.jdbc.service.CommonServiceImpl;
@@ -48,6 +49,6 @@ public class YamlConfigurationExample {
    }
    
    private static CommonService getCommonService(final DataSource dataSource) {
        return new CommonServiceImpl(new OrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource));
        return new CommonServiceImpl(new OrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource),new CountryRepositroyImpl(dataSource));
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

package io.shardingsphere.example.sharding.data.jdbc;

import io.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl;
import io.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl;
import io.shardingsphere.example.common.jdbc.repository.RangeOrderRepositoryImpl;
import io.shardingsphere.example.common.jdbc.service.CommonServiceImpl;
@@ -48,6 +49,6 @@ public class YamlRangeConfigurationExample {
    }
    
    private static CommonService getCommonService(final DataSource dataSource) {
        return new CommonServiceImpl(new RangeOrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource));
        return new CommonServiceImpl(new RangeOrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource),new CountryRepositroyImpl(dataSource));
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public final class ShardingDatabasesAndTablesConfigurationPrecise implements Exa
        shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
        shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
        shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
        shardingRuleConfig.getBroadcastTables().add("t_country");
        shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new InlineShardingStrategyConfiguration("user_id", "demo_ds_${user_id % 2}"));
        shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseModuloShardingTableAlgorithm()));
        return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new Properties());
@@ -48,12 +49,14 @@ public final class ShardingDatabasesAndTablesConfigurationPrecise implements Exa
    
    private static TableRuleConfiguration getOrderTableRuleConfiguration() {
        TableRuleConfiguration result = new TableRuleConfiguration("t_order", "demo_ds_${0..1}.t_order_${[0, 1]}");
        result.setKeyGeneratorConfig(getKeyGeneratorConfiguration());
        result.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "order_id", new Properties()));
        return result;
    }
    
    private static TableRuleConfiguration getOrderItemTableRuleConfiguration() {
        return new TableRuleConfiguration("t_order_item", "demo_ds_${0..1}.t_order_item_${[0, 1]}");
        TableRuleConfiguration result = new TableRuleConfiguration("t_order_item", "demo_ds_${0..1}.t_order_item_${[0, 1]}");
        result.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "order_item_id", new Properties()));
        return result;
    }
    
    private static Map<String, DataSource> createDataSourceMap() {
@@ -62,8 +65,4 @@ public final class ShardingDatabasesAndTablesConfigurationPrecise implements Exa
        result.put("demo_ds_1", DataSourceUtil.createDataSource("demo_ds_1"));
        return result;
    }
    
    private static KeyGeneratorConfiguration getKeyGeneratorConfiguration() {
        return new KeyGeneratorConfiguration("SNOWFLAKE", "order_id", new Properties());
    }
}
Loading