/// <summary> /// Sharding路由 /// </summary> /// <param name="domainModel">领域模型</param> /// <param name="instance">数据</param> /// <param name="shardingKeyValue">ShardingValue</param> /// <returns>路由</returns> public Dictionary <string, ShardingTarget> Route(DomainModel.Spi.DomainModel domainModel, DomainModel.Spi.DomainObject domainObject, object instance, ShardingValue shardingKeyValue = null) { var targets = new Dictionary <string, ShardingTarget>(); if (shardingKeyValue == null) { shardingKeyValue = CreateShardingValue(domainModel, domainObject, instance); } if (shardingKeyValue.ShardingValueType != ShardingValueType.SINGLE) { throw new Exception("Object Sharding route error: " + shardingKeyValue.ShardingValueType); } var tars = ShardingRuleService.GetInstance().Parse(domainObject.DataObject, shardingKeyValue); targets.Add(domainObject.DataObject.ID, tars[0]); return(targets); }
/// <summary> /// Sharding路由 /// </summary> /// <param name="domainModel">领域模型</param> /// <param name="dataID">数据标识</param> /// <param name="shardingKeyValue">ShardingValue</param> /// <returns>路由</returns> public Dictionary <string, ShardingTarget> RouteByDataID(DomainModel.Spi.DomainModel domainModel, string dataID, ShardingValue shardingKeyValue = null) { var targets = new Dictionary <string, ShardingTarget>(); if (shardingKeyValue == null) { shardingKeyValue = CreateShardingValueByDataID(domainModel, domainModel.RootDomainObject, dataID); } //不分库分表 if (shardingKeyValue == null) { foreach (var domainObject in domainModel.DomainObjects) { targets.Add(domainObject.DataObject.ID, new ShardingTarget() { DataSource = domainObject.DataObject.DataSourceName, TableName = domainObject.DataObject.ActualTableNames }); } } else { if (shardingKeyValue.ShardingValueType != ShardingValueType.SINGLE) { throw new Exception("Object Sharding route error: " + shardingKeyValue.ShardingValueType); } foreach (var domainObject in domainModel.DomainObjects) { var tars = ShardingRuleService.GetInstance().Parse(domainObject.DataObject, shardingKeyValue); targets.Add(domainObject.DataObject.ID, tars[0]); } } return(targets); }