Ejemplo n.º 1
0
        public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader)
        {
            IList  list = null;
            object obj2 = ObjectProbe.GetMemberValue(target, mapping.PropertyName, request.DataExchangeFactory.AccessorFactory);

            if (obj2 == null)
            {
                obj2 = mapping.ListFactory.CreateInstance(null);
                mapping.SetAccessor.Set(target, obj2);
            }
            list = (IList)obj2;
            object     sKIP = null;
            IResultMap map  = mapping.NestedResultMap.ResolveSubMap(reader);

            if (map.GroupByProperties.Count > 0)
            {
                string      key        = base.GetUniqueKey(map, request, reader);
                IDictionary uniqueKeys = request.GetUniqueKeys(map);
                if ((uniqueKeys != null) && uniqueKeys.Contains(key))
                {
                    sKIP = uniqueKeys[key];
                    if (sKIP != null)
                    {
                        for (int i = 0; i < map.Properties.Count; i++)
                        {
                            ResultProperty property = map.Properties[i];
                            if (property.PropertyStrategy is GroupByStrategy)
                            {
                                property.PropertyStrategy.Set(request, map, property, ref sKIP, reader, null);
                            }
                        }
                    }
                    sKIP = BaseStrategy.SKIP;
                }
                else if (((key == null) || (uniqueKeys == null)) || !uniqueKeys.Contains(key))
                {
                    sKIP = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
                    if (uniqueKeys == null)
                    {
                        uniqueKeys = new Hashtable();
                        request.SetUniqueKeys(map, uniqueKeys);
                    }
                    uniqueKeys[key] = sKIP;
                }
            }
            else
            {
                sKIP = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
            }
            if ((sKIP != null) && (sKIP != BaseStrategy.SKIP))
            {
                list.Add(sKIP);
            }
            return(sKIP);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the value of the specified <see cref="ResultProperty"/> that must be set on the target object.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="resultMap">The result map.</param>
        /// <param name="mapping">The mapping.</param>
        /// <param name="target">The target.</param>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader)
        {
            object result = null;

            IResultMap propertyRresultMap = mapping.NestedResultMap.ResolveSubMap(reader);

            string circularKey = GetCircularKey(propertyRresultMap, reader);
            // Gets the [key, result object] already build
            IDictionary <string, object> buildObjects = request.GetCirularKeys(propertyRresultMap);

            if (buildObjects != null && buildObjects.ContainsKey(circularKey))
            {
                // circular key is already known, so get the existing result object
                result = buildObjects[circularKey];
            }
            else if (circularKey == null || buildObjects == null || !buildObjects.ContainsKey(circularKey))
            {
                // circular key is NOT known, so create a new result object.
                result = resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);

                if (buildObjects == null)
                {
                    buildObjects = new Dictionary <string, object>();
                    request.SetCirularKeys(propertyRresultMap, buildObjects);
                }
                buildObjects[circularKey] = result;
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the value of the specified <see cref="ResultProperty"/> that must be set on the target object.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="resultMap">The result map.</param>
        /// <param name="mapping">The mapping.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="target">The target object</param>
        public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader)
        {
            // The property is a IList
            IList list = null;

            // Get the IList property 获取target类属性mapping.PropertyName的值
            object property = ObjectProbe.GetMemberValue(target, mapping.PropertyName,
                                                         request.DataExchangeFactory.AccessorFactory);

            if (property == null)// Create the list if need
            {
                property = mapping.ListFactory.CreateInstance(null);
                mapping.Set(target, property);
            }
            list = (IList)property;

            object result = null;
            //返回的结果中包含其他类对象的情况
            IResultMap propertyRresultMap = mapping.NestedResultMap.ResolveSubMap(reader);

            if (propertyRresultMap.GroupByProperties.Count > 0)
            {
                string uniqueKey = GetUniqueKey(propertyRresultMap, reader);

                // Gets the [key, result object] already build
                IDictionary <string, object> buildObjects = request.GetUniqueKeys(propertyRresultMap);

                if (buildObjects != null && buildObjects.ContainsKey(uniqueKey))
                {
                    // Unique key is already known, so get the existing result object and process additional results.
                    result = buildObjects[uniqueKey];

                    //In some cases (nested groupings) our object may be null, so there is
                    //no point in going on
                    if (result != null)
                    {
                        // process resulMapping attribute which point to a groupBy attribute
                        for (int index = 0; index < propertyRresultMap.Properties.Count; index++)
                        {
                            ResultProperty resultProperty = propertyRresultMap.Properties[index];
                            if (resultProperty.PropertyStrategy is GroupByStrategy)
                            {
                                // 跳到PropertyStrategy中的类
                                resultProperty.PropertyStrategy.Set(request, propertyRresultMap, resultProperty, ref result, reader, null);
                            }
                        }
                    }
                    result = SKIP;
                }
                else if (uniqueKey == null || buildObjects == null || !buildObjects.ContainsKey(uniqueKey))
                {
                    // Unique key is NOT known, so create a new result object and then process additional results.
                    //在ResultMapStrategy类中实现对target类mapping属性的赋值
                    result = resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);

                    if (buildObjects == null)
                    {
                        buildObjects = new Dictionary <string, object>();
                        request.SetUniqueKeys(propertyRresultMap, buildObjects);
                    }
                    buildObjects[uniqueKey] = result;
                }
            }
            else // Last resultMap have no groupBy attribute
            {
                if (propertyRresultMap.KeyPropertyNames.Count > 0)
                {
                    result = circularResultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
                }
                else
                {
                    //在ResultMapStrategy类中实现对target类mapping属性的赋值
                    result = resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
                }
            }


            if ((result != null) && (result != SKIP))
            {
                list.Add(result);
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the value of the specified <see cref="ResultProperty"/> that must be set on the target object.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="resultMap">The result map.</param>
        /// <param name="mapping">The mapping.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="target">The target object</param>
        public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader)
        {
            // The property is a IList
            IList list = null;

            // Get the IList property
            object property = ObjectProbe.GetMemberValue(target, mapping.PropertyName,
                                                         request.DataExchangeFactory.AccessorFactory);

            if (property == null)// Create the list if need
            {
                property = mapping.ListFactory.CreateInstance(null);
                mapping.SetAccessor.Set(target, property);
            }
            list = (IList)property;

            object     result             = null;
            IResultMap propertyRresultMap = mapping.NestedResultMap.ResolveSubMap(reader);

            if (propertyRresultMap.GroupByProperties.Count > 0)
            {
                string uniqueKey = GetUniqueKey(propertyRresultMap, request, reader);

                // Gets the [key, result object] already build
                IDictionary buildObjects = request.GetUniqueKeys(propertyRresultMap);

                if (buildObjects != null && buildObjects.Contains(uniqueKey))
                {
                    // Unique key is already known, so get the existing result object and process additional results.
                    result = buildObjects[uniqueKey];
                    // process resulMapping attribute which point to a groupBy attribute
                    for (int index = 0; index < propertyRresultMap.Properties.Count; index++)
                    {
                        ResultProperty resultProperty = propertyRresultMap.Properties[index];
                        if (resultProperty.PropertyStrategy is PropertStrategy.GroupByStrategy)
                        {
                            resultProperty.PropertyStrategy.Set(request, propertyRresultMap, resultProperty, ref result, reader, null);
                        }
                    }
                    result = SKIP;
                }
                else if (uniqueKey == null || buildObjects == null || !buildObjects.Contains(uniqueKey))
                {
                    // Unique key is NOT known, so create a new result object and then process additional results.
                    result = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);

                    if (buildObjects == null)
                    {
                        buildObjects = new Hashtable();
                        request.SetUniqueKeys(propertyRresultMap, buildObjects);
                    }
                    buildObjects[uniqueKey] = result;
                }
            }
            else // Last resultMap have no groupBy attribute
            {
                result = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
            }


            if ((result != null) && (result != SKIP))
            {
                list.Add(result);
            }

            return(result);
        }