Example #1
0
        /// <summary>
        /// 获取领域模型的结果集映射
        /// </summary>
        /// <param name="model">领域模型</param>
        /// <returns>结果集映射</returns>
        public ResultMapping CreateOrGetResultMapping(NSharding.DomainModel.Spi.DomainModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("ResultMappingFactory.CreateOrGetResultMapping.model");
            }

            var           key     = string.Format("{0}_{1}", model.ID, model.Version);
            ResultMapping mapping = null;

            if (!resultMappingDic.ContainsKey(key))
            {
                lock (syncObj)
                {
                    if (!resultMappingDic.ContainsKey(key))
                    {
                        mapping = CreateResultMapping(model);
                        if (mapping == null)
                        {
                            throw new Exception(key + " ResultMapping is null!");
                        }

                        resultMappingDic.TryAdd(key, mapping);
                    }
                    else
                    {
                        mapping = resultMappingDic[key];
                    }
                }
            }
            else
            {
                mapping = resultMappingDic[key];
            }

            if (mapping == null)
            {
                throw new Exception(key + " ResultMapping is null!");
            }

            return(mapping);
        }
Example #2
0
        public override void Init()
        {
            this.ItemErrorStrings = new List <string>();
            string str3 = null;

            foreach (OperationResult result in this.OperationErrors)
            {
                string format = ErrorFormatForOperation(result);
                if (format == null)
                {
                    format = ResultMapping.LocalizedResultString((ResultCode)result.ResultCode);
                }
                else
                {
                    str3 = ResultMapping.LocalizedResultString((ResultCode)result.ResultCode);
                }
                string item = string.Format(CultureInfo.CurrentUICulture, format, new object[] { result.Details, str3 });
                this.ItemErrorStrings.Add(item);
            }
        }
        public override void SetContext(StepEditContext context)
        {
            base.SetContext(context);

            cbConnectionType.SelectedItem = Step.ConnectionType;
            txtConnectionString.Text      = Step.ConnectionString;
            cbCommandType.SelectedItem    = Step.CommandType;
            commandEditor.SetContext(StepEditContext.StateVariables, Step.Command, Step.TrimVariableValueWhitespace);

            m_InputParameterMapping = Step.InputParameterMapping.Select(pm => pm.Clone()).ToList();
            zRefreshInputParameters();

            m_OutputParameterMapping = Step.OutputParameterMapping.Select(pm => pm.Clone()).ToList();
            zRefreshOutputParameters();

            m_ResultMapping = Step.ResultMapping;
            if (m_ResultMapping != null)
            {
                cbResultType.SelectedValue = m_ResultMapping.GetType();
            }
        }
        /// <summary>
        /// 创建领域对象结果集映射
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="domainObject">领域对象</param>
        /// <returns>结果集映射</returns>
        private ResultMapping CreateDomainObjectMapping(string name, DomainObject domainObject)
        {
            var mapping = new ResultMapping()
            {
                DomainObject = name,
                ClassType    = domainObject.ClazzReflectType
            };

            foreach (var element in domainObject.Elements)
            {
                switch (element.ElementType)
                {
                case ElementType.Normal:
                    var item = CreateCommonMappingItem(domainObject, element);
                    mapping.MappingItems.Add(item);
                    break;

                case ElementType.Virtual:
                    var virtualItem = CreateVirtualMappingItem(domainObject, element);
                    mapping.MappingItems.Add(virtualItem);
                    break;

                case ElementType.Enum:
                    var enumItem = CreateEnumMappingItem(domainObject, element);
                    mapping.MappingItems.Add(enumItem);
                    break;

                //case ElementType.Association:
                //    var assoItem = CreateAssoMappingItem(domainObject, element);
                //    mapping.MappingItems.Add(assoItem);
                //    break;
                default:
                    break;
                }
            }

            return(mapping);
        }
Example #5
0
        /// <summary>
        /// 创建领域对象结果集映射
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="domainObject">领域对象</param>
        /// <returns>结果集映射</returns>
        private ResultMapping CreateDomainObjectMapping(string name, NSharding.DomainModel.Spi.DomainModel model, DomainObject domainObject)
        {
            var mapping = new ResultMapping()
            {
                DomainObject = name,
                ClassType    = domainObject.ClazzReflectType
            };

            //遍历对象自身的元素
            foreach (var element in domainObject.Elements)
            {
                switch (element.ElementType)
                {
                case ElementType.Normal:
                    var item = CreateCommonMappingItem(domainObject, element);
                    mapping.MappingItems.Add(item);
                    break;

                case ElementType.Virtual:
                    var virtualItem = CreateVirtualMappingItem(domainObject, element);
                    mapping.MappingItems.Add(virtualItem);
                    break;

                case ElementType.Enum:
                    var enumItem = CreateEnumMappingItem(domainObject, element);
                    mapping.MappingItems.Add(enumItem);
                    break;

                default:
                    break;
                }
            }

            //主子关联
            var childObjects = model.DomainObjects.Where(i => i.ParentObjectID == domainObject.ID);

            if (childObjects.Count() > 0)
            {
                foreach (var child in childObjects)
                {
                    var asso     = child.Associations.FirstOrDefault(i => i.AssociateType == AssociateType.InnerJoin && i.AssoDomainObjectID == domainObject.ID);
                    var assoItem = CreateInnerAssoMapping(model, child, asso);
                    mapping.MappingItems.Add(assoItem);
                }
            }

            //外键关联 TODO
            var leftAssociations = domainObject.Associations.Where(i => i.AssociateType == AssociateType.OuterLeftJoin && i.AssoDomainObjectID == domainObject.ID);

            foreach (var asso in leftAssociations)
            {
                var assoMapping = CreateAssociationMapping(asso);
                mapping.MappingItems.Add(new ResultMappingItem()
                {
                    Property      = asso.PropertyName,
                    LazyLoad      = asso.IsLazyLoad,
                    ResultMapping = assoMapping,
                    ItemType      = ResultMappingItemType.ForeignResultMapping
                });
            }

            return(mapping);
        }
Example #6
0
        /// <summary>
        /// 循环构造结果集映射
        /// </summary>
        /// <param name="parentObject">父对象</param>
        /// <param name="mapping">已有结果集映射</param>
        /// <param name="currentObject">当前对象</param>
        private void LoopCreateResultMapping(NSharding.DomainModel.Spi.DomainModel model, DomainObject parentObject, ResultMapping mapping, DomainObject currentObject)
        {
            var subMapping     = CreateDomainObjectMapping(currentObject.Name, model, currentObject);
            var subMappingItem = new ResultMappingItem()
            {
                //Property = currentObject.PropertyName,
                LazyLoad      = currentObject.IsLazyLoad,
                ResultMapping = subMapping,
                ItemType      = ResultMappingItemType.SubResultMapping
            };
            var innerAsso = parentObject.Associations.FirstOrDefault(
                i => i.AssociateType == AssociateType.InnerJoin && i.AssoDomainObjectID == currentObject.ID);

            if (innerAsso != null)
            {
                var parentElementID = innerAsso.Items.FirstOrDefault().SourceElementID;
                subMappingItem.Property      = innerAsso.PropertyName;
                subMappingItem.GroupbyColumn = parentObject.DataObject.Columns.FirstOrDefault(c =>
                                                                                              c.ID == parentObject.Elements.FirstOrDefault(i => i.ID == parentElementID).DataColumnID).ColumnName;
            }
            mapping.MappingItems.Add(subMappingItem);

            //外键关联
            var leftAssociations = parentObject.Associations.Where(i => i.AssociateType == AssociateType.OuterLeftJoin);

            foreach (var asso in leftAssociations)
            {
                var assoMapping = CreateAssociationMapping(asso);
                mapping.MappingItems.Add(new ResultMappingItem()
                {
                    Property      = asso.PropertyName,
                    LazyLoad      = asso.IsLazyLoad,
                    ResultMapping = assoMapping,
                    ItemType      = ResultMappingItemType.ForeignResultMapping
                });
            }

            if (currentObject.ChildDomainObjects.Count > 0)
            {
                foreach (var obj in currentObject.ChildDomainObjects)
                {
                    LoopCreateResultMapping(model, currentObject, subMapping, obj);
                }
            }
        }