示例#1
0
        public void ShardingStrategyCRUDTest()
        {
            var strategy = new ShardingStrategy()
            {
                ID                = "AreaTableSharding",
                DisplayName       = "地区分表策略",
                PostFixListConfig = "sd,hb,gd,bj,sz,tj,sx,nm,hb,hn,sh",
                ShardingType      = ShardingType.Enum
            };

            try
            {
                ShardingStrategyService.GetInstance().DeleteShardingStrategy(strategy.ID);
                ShardingStrategyService.GetInstance().SaveShardingStrategy(strategy);
                var queryStrategy = ShardingStrategyService.GetInstance().GetShardingStrategy(strategy.ID);

                Assert.IsNotNull(queryStrategy);
                Assert.AreEqual(queryStrategy.DisplayName, strategy.DisplayName);
                Assert.AreEqual(queryStrategy.PostFixListConfig, strategy.PostFixListConfig);
                Assert.AreEqual(queryStrategy.ShardingType, strategy.ShardingType);

                TableShardingStrategy table = new TableShardingStrategy(queryStrategy);
                Assert.IsNotNull(table);
                Assert.AreEqual(queryStrategy.DisplayName, table.DisplayName);
                Assert.AreEqual(queryStrategy.PostFixListConfig, table.PostFixListConfig);
                Assert.AreEqual(queryStrategy.ShardingType, table.ShardingType);
            }
            finally
            {
                ShardingStrategyService.GetInstance().DeleteShardingStrategy(strategy.ID);
            }
        }
        private DataObject GetDataObjectDetail(string dataObjectID)
        {
            var dataobject = new DataObjectManager().GetDataObject(dataObjectID);

            if (dataobject.DataSource == null)
            {
                var dataSource = DataSourceService.GetInstance().GetDataSource(dataobject.DataSourceName);
                if (dataSource != null)
                {
                    dataobject.DataSource = dataSource;
                }
            }
            if (!string.IsNullOrWhiteSpace(dataobject.TableShardingStrategyID))
            {
                var strategy = ShardingStrategyService.GetInstance().GetTableShardingStrategy(dataobject.TableShardingStrategyID);
                if (strategy != null)
                {
                    dataobject.TableShardingStrategy = strategy;
                    if (string.IsNullOrWhiteSpace(dataobject.ActualTableNames))
                    {
                        var tableNames = ShardingStrategyService.GetInstance().GetShardingTableNames(strategy, dataobject.LogicTableName);
                        if (tableNames != null && tableNames.Count > 0)
                        {
                            dataobject.ActualTableNames = string.Join(",", tableNames);
                        }
                    }
                }
            }

            return(dataobject);
        }