Пример #1
0
        ///<summary>
        /// Sets value of the specified <see cref="ResultProperty"/> on the target object
        /// when a 'select' attribute exists and fills an <see cref="IList"/> property
        /// on the <see cref="ResultProperty"/> are empties.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="resultMap">The result map.</param>
        /// <param name="mapping">The ResultProperty.</param>
        /// <param name="target">The target.</param>
        /// <param name="reader">The current <see cref="IDataReader"/></param>
        /// <param name="keys">The keys</param>
        public void Set(RequestScope request, IResultMap resultMap,
            ResultProperty mapping, ref object target, IDataReader reader, object keys)
        {
            // Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

            PostBindind postSelect = new PostBindind();
            postSelect.Statement = selectStatement;
            postSelect.Keys = keys;
            postSelect.Target = target;
            postSelect.ResultProperty = mapping;

            if (mapping.IsLazyLoad)
            {
                object values = mapping.LazyFactory.CreateProxy(request.MappedStatement.ModelStore.DataMapper, selectStatement, keys, target, mapping.SetAccessor);
                //为target类的mapping属性设置值为values
                mapping.Set(target, values);
            }
            else
            {
                if (mapping.SetAccessor.MemberType.GetGenericTypeDefinition() == typeof(IList<>))
                {
                    postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForGenericIList;
                }
                //将postSelect类对象添加到队列中
                request.DelayedLoad.Enqueue(postSelect);
            }

        }
Пример #2
0
        /// <summary>
        /// Gets the value of an argument constructor.
        /// </summary>
        /// <param name="request">The current <see cref="RequestScope"/>.</param>
        /// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
        /// <param name="reader">The current <see cref="IDataReader"/>.</param>
        /// <param name="keys">The keys</param>
        /// <returns>The paremeter value.</returns>
		public object GetValue(RequestScope request, ResultProperty mapping, 
		                       ref IDataReader reader, object keys)
		{
			if (mapping.TypeHandler == null || 
				mapping.TypeHandler is UnknownTypeHandler) // Find the TypeHandler
			{
				lock(mapping) 
				{
					if (mapping.TypeHandler == null || mapping.TypeHandler is UnknownTypeHandler)
					{
						int columnIndex = 0;
						if (mapping.ColumnIndex == ResultProperty.UNKNOWN_COLUMN_INDEX) 
						{
							columnIndex = reader.GetOrdinal(mapping.ColumnName);
						} 
						else 
						{
							columnIndex = mapping.ColumnIndex;
						}
						Type systemType =reader.GetFieldType(columnIndex);

						mapping.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(systemType);
					}
				}					
			}

			object dataBaseValue = mapping.GetDataBaseValue( reader );
			request.IsRowDataFound = request.IsRowDataFound || (dataBaseValue != null);

			return dataBaseValue;
		}
Пример #3
0
		///<summary>
		/// Sets value of the specified <see cref="ResultProperty"/> on the target object
		/// when a 'select' attribute exists and fills an object property.
		/// on the <see cref="ResultProperty"/> are empties.
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="resultMap">The result map.</param>
		/// <param name="mapping">The ResultProperty.</param>
		/// <param name="target">The target.</param>
		/// <param name="reader">The current <see cref="IDataReader"/></param>
		/// <param name="keys">The keys</param>
		public void Set(RequestScope request, IResultMap resultMap, 
			ResultProperty mapping, ref object target, IDataReader reader, object keys)
		{
			// Get the select statement
			IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

			PostBindind postSelect = new PostBindind();
			postSelect.Statement = selectStatement;
			postSelect.Keys = keys;
			postSelect.Target = target;
			postSelect.ResultProperty = mapping;

			if (mapping.IsLazyLoad)
			{
				object values = mapping.LazyFactory.CreateProxy(
                    request.MappedStatement.ModelStore.DataMapper,
                    selectStatement, keys, target, mapping.SetAccessor);
				mapping.Set(target, values);
			}
			else
			{
				postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForObject;
				request.DelayedLoad.Enqueue(postSelect);
			}
		}
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectStrategy"/> class.
        /// </summary>
        /// <param name="mapping">The mapping.</param>
        /// <param name="selectArrayStrategy">The select array strategy.</param>
        /// <param name="selectGenericListStrategy">The select generic list strategy.</param>
        /// <param name="selectListStrategy">The select list strategy.</param>
        /// <param name="selectObjectStrategy">The select object strategy.</param>
		public SelectStrategy(ResultProperty mapping,
            IArgumentStrategy selectArrayStrategy,
            IArgumentStrategy selectGenericListStrategy,
            IArgumentStrategy selectListStrategy,
            IArgumentStrategy selectObjectStrategy)
		{
			// Collection object or .NET object			
			if (mapping.MemberType.BaseType == typeof(Array))
			{
                _selectStrategy = selectArrayStrategy;
			}
            else if (mapping.MemberType.IsGenericType &&
                 typeof(IList<>).IsAssignableFrom(mapping.MemberType.GetGenericTypeDefinition())) 
            {
                _selectStrategy = selectGenericListStrategy;
            }
            // Check if the object to Map implement 'IList' or is IList type
			// If yes the ResultProperty is map to a IList object
			else if ( typeof(IList).IsAssignableFrom(mapping.MemberType) )
			{
                _selectStrategy = selectListStrategy;
			}

			else // The ResultProperty is map to a .Net object
			{
                _selectStrategy = selectObjectStrategy;
			}
		}
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectStrategy"/> class.
        /// </summary>
        /// <param name="mapping">The mapping.</param>
        /// <param name="selectArrayStrategy">The select array strategy.</param>
        /// <param name="selectGenericListStrategy">The select generic list strategy.</param>
        /// <param name="selectListStrategy">The select list strategy.</param>
        /// <param name="selectObjectStrategy">The select object strategy.</param>
		public SelectStrategy(ResultProperty mapping,
            IPropertyStrategy selectArrayStrategy,
            IPropertyStrategy selectGenericListStrategy,
            IPropertyStrategy selectListStrategy,
            IPropertyStrategy selectObjectStrategy)
		{
            Contract.Require.That(selectArrayStrategy, Is.Not.Null).When("retrieving argument selectArrayStrategy in SelectStrategy constructor");
            Contract.Require.That(selectGenericListStrategy, Is.Not.Null).When("retrieving argument selectGenericListStrategy in SelectStrategy constructor");
            Contract.Require.That(selectListStrategy, Is.Not.Null).When("retrieving argument selectListStrategy in SelectStrategy constructor");
            Contract.Require.That(selectObjectStrategy, Is.Not.Null).When("retrieving argument selectObjectStrategy in SelectStrategy constructor");

			// Collection object or .NET object		
			if (mapping.SetAccessor.MemberType.BaseType == typeof(Array))
			{
                selectStrategy = selectArrayStrategy;
			}
            else if (mapping.SetAccessor.MemberType.IsGenericType &&
                 typeof(IList<>).IsAssignableFrom(mapping.SetAccessor.MemberType.GetGenericTypeDefinition()) )
            {
                selectStrategy = selectGenericListStrategy;
            }
            // Check if the object to Map implement 'IList' or is IList type
			// If yes the ResultProperty is map to a IList object
            else if (typeof(IList).IsAssignableFrom(mapping.SetAccessor.MemberType))
			{
                selectStrategy = selectListStrategy;
			}

			else // The ResultProperty is map to a .Net object
			{
                selectStrategy = selectObjectStrategy;
			}
		}
Пример #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="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;
        }
Пример #7
0
		/// <summary>
		/// Sets value of the specified <see cref="ResultProperty"/> on the target object
		/// when a 'resultMapping' attribute exists
		/// on the <see cref="ResultProperty"/>.
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="resultMap">The result map.</param>
		/// <param name="mapping">The ResultProperty.</param>
		/// <param name="target">The target.</param>
		/// <param name="reader">The reader.</param>
		/// <param name="keys">The keys</param>
		public void Set(RequestScope request, IResultMap resultMap, 
			ResultProperty mapping, ref object target, IDataReader reader, object keys)
		{
            object obj = Get(request, resultMap, mapping, ref target, reader);
			// Sets created object on the property
			resultMap.SetValueOfProperty( ref target, mapping, obj );		
		}
Пример #8
0
        /// <summary>
        /// Gets a column value by the index
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
		public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
        {
            if (dataReader.IsDBNull(mapping.ColumnIndex))
			{
				return DBNull.Value;
			}
            return Enum.Parse(mapping.MemberType, dataReader.GetValue(mapping.ColumnIndex).ToString());
        }
Пример #9
0
        /// <summary>
        /// Gets a column value by the index
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
		public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
        {
            if (dataReader.IsDBNull(mapping.ColumnIndex))
			{
				return DBNull.Value;
			}
            return dataReader.GetFloat(mapping.ColumnIndex);
        }
Пример #10
0
        /// <summary>
        /// Gets a column value by the index
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
		public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
        {
            if (dataReader.IsDBNull(mapping.ColumnIndex) || dataReader.GetBytes(mapping.ColumnIndex, 0, null, 0, 0) == 0)
            {
                return DBNull.Value;
            }
            return GetValueByIndex(mapping.ColumnIndex, dataReader);
        }
 /// <summary>
 /// Gets a column value by the index
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="dataReader"></param>
 /// <returns></returns>
 public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
 {
     if (dataReader.IsDBNull(mapping.ColumnIndex))
     {
         return DBNull.Value;
     }
     return new byte?( Convert.ToByte(dataReader.GetValue(mapping.ColumnIndex)) );
 }
 /// <summary>
 /// Gets a column value by the index
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="dataReader"></param>
 /// <returns></returns>
 public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
 {
     if (dataReader.IsDBNull(mapping.ColumnIndex))
     {
         return DBNull.Value;
     }
     return new char?( dataReader.GetString(mapping.ColumnIndex)[0] );
 }
Пример #13
0
		///<summary>
		/// Sets value of the specified <see cref="ResultProperty"/> on the target object
		/// when the 'select' and 'resultMap' attributes 
		/// on the <see cref="ResultProperty"/> are empties.
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="resultMap">The result map.</param>
		/// <param name="mapping">The ResultProperty.</param>
		/// <param name="target">The target.</param>
		/// <param name="reader">The reader.</param>
		/// <param name="keys">The keys</param>
		public void Set(RequestScope request, IResultMap resultMap, 
			ResultProperty mapping, ref object target, IDataReader reader, object keys)
		{
            //获取属性mapping的值
            object obj = Get(request, resultMap, mapping, ref target, reader);
            //将mapping的值放到类中对应的属性里
            resultMap.SetValueOfProperty(ref target, mapping, obj);
		}
Пример #14
0
        /// <summary>
        /// Gets a column value by the index
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
		public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader) 
		{
			if (dataReader.IsDBNull(mapping.ColumnIndex))
			{
				return DBNull.Value;
			}
            // Don't used dataReader.GetInt32 to fix oracle who alwray return decimal type
            return Convert.ToInt32(dataReader.GetValue(mapping.ColumnIndex));
		}
Пример #15
0
		/// <summary>
		/// Gets the value of an argument constructor.
		/// </summary>
		/// <param name="request">The current <see cref="RequestScope"/>.</param>
		/// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
		/// <param name="reader">The current <see cref="IDataReader"/>.</param>
		/// <param name="keys">The keys</param>
		/// <returns>The paremeter value.</returns>
		public object GetValue(RequestScope request, ResultProperty mapping, 
		                       ref IDataReader reader, object keys)
		{
			// Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);
			return selectStatement.ExecuteQueryForObject(request.Session, keys, null);
		}
Пример #16
0
        /// <summary>
        /// Gets a column value by the name
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
		public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
		{
            int index = dataReader.GetOrdinal(mapping.ColumnName);

            if (dataReader.IsDBNull(index) || dataReader.GetBytes(index, 0, null, 0, 0) == 0)
            {
                return DBNull.Value;
            }
            return GetValueByIndex(index, dataReader);
		}
Пример #17
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="mapping"></param>
		/// <param name="dataReader"></param>
		/// <returns></returns>
		public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
		{
			int index = dataReader.GetOrdinal(mapping.ColumnName);

			if (dataReader.IsDBNull(index))
			{
				return DBNull.Value;
			}
		    return Enum.Parse(mapping.MemberType, dataReader.GetValue(index).ToString());
		}
Пример #18
0
        /// <summary>
        /// Gets a column value by the name
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
		public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
		{
			int index = dataReader.GetOrdinal(mapping.ColumnName);

			if (dataReader.IsDBNull(index))
			{
				return DBNull.Value;
			}
            return dataReader.GetFloat(index);
		}
        /// <summary>
        /// Gets a column value by the name
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
        public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
        {
            int index = dataReader.GetOrdinal(mapping.ColumnName);

            if (dataReader.IsDBNull(index))
            {
                return DBNull.Value;
            }
            return new byte?( Convert.ToByte(dataReader.GetValue(index)) );
        }
        /// <summary>
        /// Gets a column value by the name
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
        public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
        {
            int index = dataReader.GetOrdinal(mapping.ColumnName);

            if (dataReader.IsDBNull(index))
            {
                return DBNull.Value;
            }
            // Don't used dataReader.GetInt32 to fix oracle who alwray return decimal type
            return new Int16?(Convert.ToInt16(dataReader.GetValue(index)));
        }
Пример #21
0
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/> 
        /// when a ResultClass is specified on the statement and
        /// the ResultClass is a SimpleType.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="resultObject">The result object.</param>
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object outObject = resultObject;
            AutoResultMap resultMap = (AutoResultMap)request.CurrentResultMap;
            
            if (outObject == null) 
            {
                outObject = resultMap.CreateInstanceOfResult(null);
            }

            if (!resultMap.IsInitalized)
            { 
                lock(resultMap)
                {
                    if (!resultMap.IsInitalized)
                    {
                        // Create a ResultProperty
                        const string propertyName = "value";
                        const int columnIndex = 0;
                        ITypeHandler typeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(outObject.GetType());

                        ResultProperty property = new ResultProperty(
                            propertyName,
                            string.Empty,
                            columnIndex,
                            string.Empty,
                            string.Empty,
                            string.Empty,
                            false,
                            string.Empty,
                            null,
                            string.Empty,
                            null,
                            null,
                            typeHandler);
                        //property.PropertyStrategy = PropertyStrategyFactory.Get(property);

                        resultMap.Properties.Add(property);
                        resultMap.DataExchange = request.DataExchangeFactory.GetDataExchangeForClass(typeof(int));// set the PrimitiveDataExchange
                        resultMap.IsInitalized = true;
                    }
                }
            }
            //为outObject类的属性property赋值
            resultMap.Properties[0].PropertyStrategy.Set(request, resultMap, resultMap.Properties[0], ref outObject, reader, null); 
      
			return outObject;
		}
Пример #22
0
		/// <summary>
		/// Gets the value of an argument constructor.
		/// </summary>
		/// <param name="request">The current <see cref="RequestScope"/>.</param>
		/// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
		/// <param name="reader">The current <see cref="IDataReader"/>.</param>
		/// <param name="keys">The keys</param>
		/// <returns>The paremeter value.</returns>
		public object GetValue(RequestScope request, ResultProperty mapping, 
		                       ref IDataReader reader, object keys)
		{
			// Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

			if (mapping.MemberType == typeof(IList))
			{
				reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);
				return selectStatement.ExecuteQueryForList(request.Session, keys); 
			}
		    reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);
		    IFactory factory = request.DataExchangeFactory.ObjectFactory.CreateFactory(mapping.MemberType, Type.EmptyTypes);
		    object values = factory.CreateInstance(null);
		    selectStatement.ExecuteQueryForList(request.Session, keys, (IList)values);
		    return values;
		}
Пример #23
0
		/// <summary>
		/// Gets the value of an argument constructor.
		/// </summary>
		/// <param name="request">The current <see cref="RequestScope"/>.</param>
		/// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
		/// <param name="reader">The current <see cref="IDataReader"/>.</param>
		/// <param name="keys">The keys</param>
		/// <returns>The paremeter value.</returns>
		public object GetValue(RequestScope request, ResultProperty mapping, 
		                       ref IDataReader reader, object keys)
		{
			// Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);
			IList values = selectStatement.ExecuteQueryForList(request.Session, keys); 

			Type elementType = mapping.MemberType.GetElementType();
			Array array = Array.CreateInstance(elementType, values.Count);
			int count = values.Count;
			for(int i=0;i<count;i++)
			{
				array.SetValue(values[i],i);
			}
			return array;
		}
Пример #24
0
        /// <summary>
        /// Gets a column value by the index
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataReader"></param>
        /// <returns></returns>
		public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader) 
		{
			if (dataReader.IsDBNull(mapping.ColumnIndex))
			{
				return DBNull.Value;
			}
            // Don't used dataReader.GetInt32 to fix oracle who alwray return decimal type
            object obj=0;
            try
            {
                obj = dataReader.GetValue(mapping.ColumnIndex);
            }
            catch(Exception e)
            {
                string m =mapping.ColumnName+ e.Message;
            }
            return Convert.ToInt32(obj);
		}
Пример #25
0
		///<summary>
		/// Sets value of the specified <see cref="ResultProperty"/> on the target object
		/// when a 'select' attribute exists and fills an Array property
		/// on the <see cref="ResultProperty"/> are empties.
		/// </summary>
		/// <param name="request">The request.</param>
		/// <param name="resultMap">The result map.</param>
		/// <param name="mapping">The ResultProperty.</param>
		/// <param name="target">The target.</param>
		/// <param name="reader">The <see cref="IDataReader"/></param>
		/// <param name="keys">The keys</param>
		public void Set(RequestScope request, IResultMap resultMap, 
			ResultProperty mapping, ref object target, IDataReader reader, object keys)
		{
			// Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

			PostBindind postSelect = new PostBindind();
			postSelect.Statement = selectStatement;
			postSelect.Keys = keys;
			postSelect.Target = target;
			postSelect.ResultProperty = mapping;
		
			if (mapping.IsLazyLoad)
			{
				throw new NotImplementedException("Lazy load no supported for System.Array property:" + mapping.SetAccessor.Name);
			}
			postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForArrayList;
			request.DelayedLoad.Enqueue(postSelect);
		}
	    /// <summary>
		/// Sets the value to the result property.
		/// </summary>
		/// <param name="mapping"></param>
		/// <param name="target"></param>
		/// <param name="dataBaseValue"></param>
		public override void SetData(ref object target, ResultProperty mapping, object dataBaseValue)
		{
		    Type targetType = target.GetType();
            if ((targetType != parameterClass)
                && !targetType.IsSubclassOf(parameterClass)
                && !parameterClass.IsAssignableFrom(targetType))
			{
                throw new ArgumentException("Could not set value in class '" + target.GetType() + "' for property '" + mapping.PropertyName + "' of type '" + mapping.MemberType + "'");
			}
			if ( mapping.IsComplexMemberName)
			{
				ObjectProbe.SetMemberValue(target, mapping.PropertyName, dataBaseValue, 
					DataExchangeFactory.ObjectFactory,
					DataExchangeFactory.AccessorFactory);
			}
			else
			{
                mapping.Set(target, dataBaseValue);
			}
		}
Пример #27
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)
        {
            object[] parameters = null;
            bool isParameterFound = false;

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

            if (resultMapping.Parameters.Count > 0)
            {
                parameters = new object[resultMapping.Parameters.Count];
                // Fill parameters array
                for (int index = 0; index < resultMapping.Parameters.Count; index++)
                {
                    ResultProperty resultProperty = resultMapping.Parameters[index];
                    parameters[index] = resultProperty.GetValue(request, ref reader, null);
                    request.IsRowDataFound = request.IsRowDataFound || (parameters[index] != null);
                    isParameterFound = isParameterFound || (parameters[index] != null);
                }
            }

            object obj = null;
            // If I have a constructor tag and all argumments values are null, the obj is null
            if (resultMapping.Parameters.Count > 0 && isParameterFound == false)
            {
                obj = null;
            }
            else
            {
                obj = resultMapping.CreateInstanceOfResult(parameters);

                // Fills properties on the new object
                if (FillObjectWithReaderAndResultMap(request, reader, resultMapping, ref obj) == false)
                {
                    obj = null;
                }
            }
	        
	        return obj;
        }
        /// <summary>
        /// Gets the value of an argument constructor.
        /// </summary>
        /// <param name="request">The current <see cref="RequestScope"/>.</param>
        /// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
        /// <param name="reader">The current <see cref="IDataReader"/>.</param>
        /// <param name="keys">The keys</param>
        /// <returns>The paremeter value.</returns>
        public object GetValue(RequestScope request, ResultProperty mapping, 
                               ref IDataReader reader, object keys)
        {
            // Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);
           
            reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);

            //Type[] typeArgs = mapping.MemberType.GetGenericArguments();
            //Type genericList = typeof(IList<>);
            //Type constructedType = genericList.MakeGenericType(typeArgs);
            Type elementType = mapping.MemberType.GetGenericArguments()[0];

            Type mappedStatementType = selectStatement.GetType();

            //Type[] typeArguments = { typeof(ISession), typeof(object) };

            MethodInfo[] mis = mappedStatementType.GetMethods(BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance);
            MethodInfo mi = null;
            for (int i = 0; i < mis.Length; i++)
            {
                if (mis[i].IsGenericMethod &&
                    mis[i].Name == "ExecuteQueryForList" &&
                    mis[i].GetParameters().Length == 2)
                {
                    mi = mis[i];
                    break;
                }
            }

            MethodInfo miConstructed = mi.MakeGenericMethod(elementType);

            // Invoke the method.
            object[] args = { request.Session, keys };
            object values = miConstructed.Invoke(selectStatement, args);

            return values;
        }
		/// <summary>
		/// Finds the <see cref="IPropertyStrategy"/>.
		/// </summary>
		/// <param name="mapping">The <see cref="ResultProperty"/>.</param>
		/// <returns>The <see cref="IPropertyStrategy"/></returns>
		public static IPropertyStrategy Get(ResultProperty mapping)
		{
		    // no 'select' or 'resultMap' attributes
			if (mapping.Select.Length == 0 && mapping.NestedResultMap == null)
			{
				// We have a 'normal' ResultMap
				return defaultStrategy;
			}
		    if (mapping.NestedResultMap != null) // 'resultMap' attribute
		    {
		        if (mapping.NestedResultMap.GroupByPropertyNames.Count>0)
		        {
		            return groupByStrategy; 
		        }
		        if (mapping.MemberType.IsGenericType &&
		            typeof(IList<>).IsAssignableFrom(mapping.MemberType.GetGenericTypeDefinition()))
		        {
		            return groupByStrategy; 
		        }
		        if (typeof(IList).IsAssignableFrom(mapping.MemberType))
		        {
		            return groupByStrategy; 
		        }
		        if (mapping.NestedResultMap.KeyPropertyNames.Count > 0)
		        {
		            return circularStrategy;
		        }
		        return resultMapStrategy;
		    }

            //'select' ResultProperty 
		    return new SelectStrategy(mapping,
		                              selectArrayStrategy,
		                              selectGenericListStrategy,
		                              selectListStrategy,
		                              selectObjectStrategy);
		}
Пример #30
0
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/> 
        /// when a ResultClass is specified on the statement and
        /// the ResultClass is <see cref="IList"/>.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="resultObject">The result object.</param>
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
			object outObject = resultObject;
            //AutoResultMap resultMap = request.CurrentResultMap as AutoResultMap;

			if (outObject == null) 
			{
                outObject = request.CurrentResultMap.CreateInstanceOfResult(null);
			}
            //将reader当前行中的所有字段加入到IList对象中
			int count = reader.FieldCount;
			for (int i = 0; i < count; i++) 
			{
				const string propertyName = "value";
                int columnIndex = i;
                ITypeHandler typeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i));
                ResultProperty property = new ResultProperty(
                    propertyName,
                    string.Empty,
                    columnIndex,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    false,
                    string.Empty,
                    null,
                    string.Empty,
                    null,
                    null,
                    typeHandler);

				((IList) outObject).Add(property.GetDataBaseValue(reader));
			}    
    
			return outObject;
		}
Пример #31
0
 /// <summary>
 /// Set the value of an object property.
 /// </summary>
 /// <param name="target">The object to set the property.</param>
 /// <param name="property">The result property to use.</param>
 /// <param name="dataBaseValue">The database value to set.</param>
 public void SetValueOfProperty(ref object target, ResultProperty property, object dataBaseValue)
 {
     throw new NotImplementedException("The method or operation is not implemented.");
 }
Пример #32
0
 /// <summary>
 /// Set the value of an object property.
 /// </summary>
 /// <param name="target">The object to set the property.</param>
 /// <param name="property">The result property to use.</param>
 /// <param name="dataBaseValue">The database value to set.</param>
 public void SetValueOfProperty(ref object target, ResultProperty property, object dataBaseValue)
 {
     dataExchange.SetData(ref target, property, dataBaseValue);
 }