Ejemplo n.º 1
0
        public TableRule(TableRuleConfiguration tableRuleConfig, ShardingDataSourceNames shardingDataSourceNames,
                         string defaultGenerateKeyColumn)
        {
            LogicTable = tableRuleConfig.LogicTable.ToLower();
            List <string> dataNodes = tableRuleConfig.ActualDataNodes ?? new List <string>(0);

            // List<string> dataNodes = new InlineExpressionParser(tableRuleConfig.GetActualDataNodes()).splitAndEvaluate();
            // dataNodeIndexMap = new HashMap<>(dataNodes.size(), 1);
            dataNodeIndexMap = new Dictionary <DataNode, int>(dataNodes.Count);
            ActualDataNodes  = IsEmptyDataNodes(dataNodes)
                ? GenerateDataNodes(tableRuleConfig.LogicTable, shardingDataSourceNames.DataSourceNames) : GenerateDataNodes(dataNodes, shardingDataSourceNames.DataSourceNames);
            //ActualDataNodes = GenerateDataNodes(tableRuleConfig.LogicTable, shardingDataSourceNames.DataSourceNames);
            actualTables             = GetActualTables();
            DatabaseShardingStrategy = null == tableRuleConfig.DatabaseShardingStrategyConfig
                ? null
                : ShardingStrategyFactory.NewInstance(tableRuleConfig.DatabaseShardingStrategyConfig);
            TableShardingStrategy = null == tableRuleConfig.TableShardingStrategyConfig
                ? null
                : ShardingStrategyFactory.NewInstance(tableRuleConfig.TableShardingStrategyConfig);
            KeyGeneratorConfiguration keyGeneratorConfiguration = tableRuleConfig.KeyGeneratorConfig;

            generateKeyColumn =
                null != keyGeneratorConfiguration && !string.IsNullOrWhiteSpace(keyGeneratorConfiguration.Column)
                    ? keyGeneratorConfiguration.Column
                    : defaultGenerateKeyColumn;
            ShardingKeyGenerator = ContainsKeyGeneratorConfiguration(tableRuleConfig)
                ? new ShardingKeyGeneratorServiceLoader().NewService(tableRuleConfig.KeyGeneratorConfig.Type,
                                                                     tableRuleConfig.KeyGeneratorConfig.Properties)
                : null;
            // CheckRule(dataNodes);
        }
Ejemplo n.º 2
0
 private IShardingStrategy CreateDefaultShardingStrategy(IShardingStrategyConfiguration shardingStrategyConfiguration)
 {
     if (shardingStrategyConfiguration != null)
     {
         return(ShardingStrategyFactory.NewInstance(shardingStrategyConfiguration) ?? new NoneShardingStrategy());
     }
     return(new NoneShardingStrategy());
 }