示例#1
0
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/>.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="resultObject">The result object.</param>
        /// <returns>The result object</returns>
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object outObject = resultObject;
            //实现对当前CurrentResultMap类中的discrimitor子节点类的设置
            IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader);

            //获取resultMap分组名对应的值
            string uniqueKey = GetUniqueKey(resultMap, reader);
            // Gets the [key, result object] already build
            //根据IResultMap获取对应的IDictionary
            IDictionary <string, object> buildObjects = request.GetUniqueKeys(resultMap);

            if (buildObjects != null && buildObjects.ContainsKey(uniqueKey))
            {
                // Unique key is already known, so get the existing result object and process additional results.
                outObject = buildObjects[uniqueKey];
                // process resulMapping attribute which point to a groupBy attribute
                //遍历resultMap.Properties属性中为GroupByStrategy的属性
                for (int index = 0; index < resultMap.Properties.Count; index++)
                {
                    ResultProperty resultProperty = resultMap.Properties[index];
                    if (resultProperty.PropertyStrategy is PropertStrategy.GroupByStrategy)
                    {
                        //.................??? 跳到PropertyStrategy中的GroupByStrategy类
                        resultProperty.PropertyStrategy.Set(request, resultMap, resultProperty, ref outObject, reader, null);
                    }
                }
                outObject = SKIP;
            }
            else if (uniqueKey == null || buildObjects == null || !buildObjects.ContainsKey(uniqueKey))
            {
                // Unique key is NOT known, so create a new result object and process additional results.

                // Fix IBATISNET-241
                if (outObject == null)
                {
                    // temp ?, we don't support constructor tag with groupBy attribute
                    outObject = resultMap.CreateInstanceOfResult(null);//创建返回类的对象
                }

                for (int index = 0; index < resultMap.Properties.Count; index++)
                {
                    ResultProperty resultProperty = resultMap.Properties[index];
                    //为当前的resultProperty属性设置其从数据库中读到的值到outObject类中
                    resultProperty.PropertyStrategy.Set(request, resultMap, resultProperty, ref outObject, reader, null);
                }

                if (buildObjects == null)
                {
                    buildObjects = new Dictionary <string, object>();
                    request.SetUniqueKeys(resultMap, buildObjects);
                }
                buildObjects[uniqueKey] = outObject;
            }

            return(outObject);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/>.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="resultObject">The result object.</param>
        /// <returns>The result object</returns>
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object outObject = resultObject;

            IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader);

            string uniqueKey = GetUniqueKey(resultMap, request, reader);
            // Gets the [key, result object] already build
            IDictionary buildObjects = request.GetUniqueKeys(resultMap);

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

                // Fix IBATISNET-241
                if (outObject == null)
                {
                    // temp ?, we don't support constructor tag with groupBy attribute
                    outObject = resultMap.CreateInstanceOfResult(null);
                }

                for (int index = 0; index < resultMap.Properties.Count; index++)
                {
                    ResultProperty resultProperty = resultMap.Properties[index];
                    resultProperty.PropertyStrategy.Set(request, resultMap, resultProperty, ref outObject, reader, null);
                }

                if (buildObjects == null)
                {
                    buildObjects = new Hashtable();
                    request.SetUniqueKeys(resultMap, buildObjects);
                }
                buildObjects[uniqueKey] = outObject;
            }

            return(outObject);
        }
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object      target     = resultObject;
            IResultMap  resultMap  = request.CurrentResultMap.ResolveSubMap(reader);
            string      key        = base.GetUniqueKey(resultMap, request, reader);
            IDictionary uniqueKeys = request.GetUniqueKeys(resultMap);

            if ((uniqueKeys != null) && uniqueKeys.Contains(key))
            {
                target = uniqueKeys[key];
                for (int i = 0; i < resultMap.Properties.Count; i++)
                {
                    ResultProperty mapping = resultMap.Properties[i];
                    if (mapping.PropertyStrategy is IBatisNet.DataMapper.MappedStatements.PropertStrategy.GroupByStrategy)
                    {
                        mapping.PropertyStrategy.Set(request, resultMap, mapping, ref target, reader, null);
                    }
                }
                return(BaseStrategy.SKIP);
            }
            if (((key == null) || (uniqueKeys == null)) || !uniqueKeys.Contains(key))
            {
                if (target == null)
                {
                    target = resultMap.CreateInstanceOfResult(null);
                }
                for (int j = 0; j < resultMap.Properties.Count; j++)
                {
                    ResultProperty property2 = resultMap.Properties[j];
                    property2.PropertyStrategy.Set(request, resultMap, property2, ref target, reader, null);
                }
                if (uniqueKeys == null)
                {
                    uniqueKeys = new Hashtable();
                    request.SetUniqueKeys(resultMap, uniqueKeys);
                }
                uniqueKeys[key] = target;
            }
            return(target);
        }
示例#5
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);
        }
示例#6
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);
        }