/// <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; }
/// <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]; //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 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; }