///<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.SqlMap.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(selectStatement, keys, target, mapping.SetAccessor);
                mapping.SetAccessor.Set(target, values);
            }
            else
            {
                if (mapping.SetAccessor.MemberType == typeof(IList))
                {
                    postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForIList;
                }
                else
                {
                    postSelect.Method = PostBindind.ExecuteMethod.ExecuteQueryForStrongTypedIList;
                }
                request.QueueSelect.Enqueue(postSelect);
            }
        }
        /// <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;
            }
        }
        /// <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 =((IDataRecord)reader).GetFieldType(columnIndex);

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

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

            return dataBaseValue;
        }
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/> 
        /// when no resultClass or resultMap attribute are specified.
        /// </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;

            if (reader.FieldCount == 1)
            {
                ResultProperty property = new ResultProperty();
                property.PropertyName = "value";
                property.ColumnIndex = 0;
                property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(0));
                outObject = property.GetDataBaseValue(reader);
            }
            else if (reader.FieldCount > 1)
            {
                object[] newOutObject = new object[reader.FieldCount];
                int count = reader.FieldCount;
                for (int i = 0; i < count; i++)
                {
                    ResultProperty property = new ResultProperty();
                    property.PropertyName = "value";
                    property.ColumnIndex = i;
                    property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i));
                    newOutObject[i] = property.GetDataBaseValue(reader);
                }

                outObject = newOutObject;
            }
            else
            {
                // do nothing if 0 fields
            }

            return outObject;
        }
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/> 
        /// when a 'resultClass' attribute is specified on the statement and
        /// the 'resultClass' attribute is a <see cref="IDictionary"/>.
        /// </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 = resultMap.CreateInstanceOfResultClass();
            }

            int count = reader.FieldCount;
            IDictionary dictionary = (IDictionary) outObject;
            for (int i = 0; i < count; i++)
            {
                ResultProperty property = new ResultProperty();
                property.PropertyName = "value";
                property.ColumnIndex = i;
                property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i));
                dictionary.Add(
                    reader.GetName(i),
                    property.GetDataBaseValue(reader));
            }

            return outObject;
        }
        /// <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 = request.CurrentResultMap as AutoResultMap;

            if (outObject == null)
            {
                outObject = resultMap.CreateInstanceOfResultClass();
            }

            if (!resultMap.IsInitalized)
            {
                lock(resultMap)
                {
                    if (!resultMap.IsInitalized)
                    {
                        // Create a ResultProperty
                        ResultProperty property = new ResultProperty();
                        property.PropertyName = "value";
                        property.ColumnIndex = 0;
                        property.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(outObject.GetType());
                        property.PropertyStrategy = PropertyStrategyFactory.Get(property);

                        resultMap.Properties.Add(property);
                        resultMap.DataExchange = request.DataExchangeFactory.GetDataExchangeForClass(typeof(int));// set the PrimitiveDataExchange
                        resultMap.IsInitalized = true;
                    }
                }
            }

            resultMap.Properties[0].PropertyStrategy.Set(request, resultMap, resultMap.Properties[0], ref outObject, reader, null);

            return outObject;
        }
        /// <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.SqlMap.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.DataSource.DbProvider);
            return selectStatement.ExecuteQueryForObject(request.Session, keys);
        }
 /// <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) == true)
     {
         return DBNull.Value;
     }
     else
     {
         return new UInt64?(Convert.ToUInt64(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) == true)
     {
         return DBNull.Value;
     }
     else
     {
         return new DateTime?(dataReader.GetDateTime(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) == true)
     {
         return System.DBNull.Value;
     }
     else
     {
         return dataReader.GetValue(mapping.ColumnIndex);
     }
 }
Beispiel #11
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) == true)
     {
         return DBNull.Value;
     }
     else
     {
         return Enum.Parse(mapping.MemberType, dataReader.GetValue(mapping.ColumnIndex).ToString());
     }
 }
 /// <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;
     }
     else
     {
         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) == true)
     {
         return DBNull.Value;
     }
     else
     {
         // Don't used dataReader.GetInt32 to fix oracle who alwray return decimal type
         return Convert.ToUInt16(dataReader.GetValue(mapping.ColumnIndex));
     }
 }
        /// <summary>
        /// Deserialize a ResultProperty object
        /// </summary>
        /// <param name="node"></param>
        /// <param name="configScope"></param>
        /// <returns></returns>
        public static ResultProperty Deserialize(XmlNode node, ConfigurationScope configScope)
        {
            ResultProperty resultProperty = new ResultProperty();

            NameValueCollection prop = NodeUtils.ParseAttributes(node, configScope.Properties);
            resultProperty.CLRType = NodeUtils.GetStringAttribute(prop, "type");
            resultProperty.CallBackName = NodeUtils.GetStringAttribute(prop, "typeHandler");
            resultProperty.ColumnIndex = NodeUtils.GetIntAttribute( prop, "columnIndex", ResultProperty.UNKNOWN_COLUMN_INDEX  );
            resultProperty.ColumnName = NodeUtils.GetStringAttribute(prop, "column");
            resultProperty.DbType = NodeUtils.GetStringAttribute(prop, "dbType");
            resultProperty.IsLazyLoad = NodeUtils.GetBooleanAttribute( prop, "lazyLoad", false);
            resultProperty.NestedResultMapName = NodeUtils.GetStringAttribute(prop, "resultMapping");
            resultProperty.NullValue = prop["nullValue"];
            resultProperty.PropertyName = NodeUtils.GetStringAttribute(prop, "property");
            resultProperty.Select = NodeUtils.GetStringAttribute(prop, "select");

            return resultProperty;
        }
        /// <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.SqlMap.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.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;
        }
        ///<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.SqlMap.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.QueueSelect.Enqueue(postSelect);
        }
        /// <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.SqlMap.GetMappedStatement(mapping.Select);

            if (mapping.MemberType == typeof(IList))
            {
                reader = DataReaderTransformer.Transform(reader, request.Session.DataSource.DbProvider);
                return selectStatement.ExecuteQueryForList(request.Session, keys);
            }
            else // Strongly typed List
            {
                reader = DataReaderTransformer.Transform(reader, request.Session.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;
            }
        }
 /// <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;
     }
     else if (mapping.NestedResultMap != null) // 'resultMap' attribute
     {
         if (mapping.NestedResultMap.GroupByPropertyNames.Count>0)
         {
             return _groupByStrategy;
         }
         else
         {
             if (mapping.MemberType.IsGenericType &&
                 typeof(IList<>).IsAssignableFrom(mapping.MemberType.GetGenericTypeDefinition()))
             {
                 return _groupByStrategy;
             }
             else
                 if (typeof(IList).IsAssignableFrom(mapping.MemberType))
                 {
                     return _groupByStrategy;
                 }
                 else
                 {
                     return _resultMapStrategy;
                 }
         }
     }
     else //'select' ResultProperty
     {
         return new SelectStrategy(mapping,
             _selectArrayStrategy,
             _selectGenericListStrategy,
             _selectListStrategy,
             _selectObjectStrategy);
     }
 }
        /// <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.ArgumentStrategy.GetValue(request, resultProperty, 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 (this.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.SqlMap.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.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(SqlMapSession), typeof(object) };

            MethodInfo[] mis = mappedStatementType.GetMethods(BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance);
            MethodInfo mi = null;
            foreach (MethodInfo m in mis)
            {
                if (m.IsGenericMethod &&
                    m.Name == "ExecuteQueryForList" &&
                    m.GetParameters().Length == 2)
                {
                    mi = m;
                    break;
                }
            }

            MethodInfo miConstructed = mi.MakeGenericMethod(elementType);

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

            return values;
        }
 /// <summary>
 /// Indicate if a ResultProperty is in the collection
 /// </summary>
 /// <param name="value">A ResultProperty</param>
 /// <returns>True fi is in</returns>
 public bool Contains(ResultProperty value)
 {
     return Contains(value.PropertyName);
 }
        /// <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) == true)
            {
                return DBNull.Value;
            }
            else
            {
                // Don't used dataReader.GetInt32 to fix oracle who alwray return decimal type
                return new Int16?(Convert.ToInt16(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) || dataReader.GetBytes(index, 0, null, 0, 0) == 0)
            {
                return DBNull.Value;
            }
            else
            {
                return GetValueByIndex(index, dataReader);
            }
        }
Beispiel #24
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 Exception("The method or operation is not implemented.");
 }
 /// <summary>
 /// Sets the value to the result property.
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="target"></param>
 /// <param name="dataBaseValue"></param>
 public abstract void SetData(ref object target, ResultProperty mapping, object dataBaseValue);
        /// <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) == true)
            {
                return DBNull.Value;
            }
            else
            {
                return new UInt16?(Convert.ToUInt16(dataReader.GetValue(index)));
            }
        }
 /// <summary>
 /// Remove a ResultProperty of the collection.
 /// </summary>
 public void Remove(ResultProperty value)
 {
     for(int i = 0; i < _count; i++)
     {
         if(_innerList[i].PropertyName==value.PropertyName)
         {
             RemoveAt(i);
             return;
         }
     }
 }
Beispiel #28
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);
 }
 /// <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)
 {
     ObjectProbe.SetMemberValue(target, mapping.PropertyName, dataBaseValue,
         this.DataExchangeFactory.ObjectFactory,
         this.DataExchangeFactory.AccessorFactory);
 }
        /// <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) == true)
            {
                return System.DBNull.Value;
            }
            else
            {
                return dataReader.GetValue(index);
            }
        }
        /// <summary>
        /// Insert a ResultProperty in the collection.
        /// </summary>
        /// <param name="index">Index where to insert.</param>
        /// <param name="value">A ResultProperty</param>
        public void Insert(int index, ResultProperty value)
        {
            if (index < 0 || index > _count)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            Resize(_count + 1);
            Array.Copy(_innerList, index, _innerList, index + 1, _count - index);
            _innerList[index] = value;
            _count++;
        }
Beispiel #32
0
        /// <summary>
        /// Get the result properties and the subMap properties.
        /// </summary>
        /// <param name="configScope"></param>
        private void GetChildNode(ConfigurationScope configScope)
        {
            ResultProperty mapping = null;
            SubMap         subMap  = null;

            #region Load the parameters constructor
            XmlNodeList nodeList = configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_CONSTRUCTOR_ARGUMENT), configScope.XmlNamespaceManager);
            if (nodeList.Count > 0)
            {
                Type[]   parametersType = new Type[nodeList.Count];
                string[] parametersName = new string[nodeList.Count];
                for (int i = 0; i < nodeList.Count; i++)
                {
                    ArgumentProperty argumentMapping = ArgumentPropertyDeSerializer.Deserialize(nodeList[i], configScope);
                    _parameters.Add(argumentMapping);
                    parametersName[i] = argumentMapping.ArgumentName;
                }
                ConstructorInfo constructorInfo = this.GetConstructor(_class, parametersName);
                for (int i = 0; i < _parameters.Count; i++)
                {
                    ArgumentProperty argumentMapping = (ArgumentProperty)_parameters[i];

                    configScope.ErrorContext.MoreInfo = "initialize argument property : " + argumentMapping.ArgumentName;
                    argumentMapping.Initialize(configScope, constructorInfo);
                    parametersType[i] = argumentMapping.MemberType;
                }
                // Init the object factory
                _objectFactory = configScope.SqlMapper.ObjectFactory.CreateFactory(_class, parametersType);
            }
            else
            {
                if (Type.GetTypeCode(_class) == TypeCode.Object)
                {
                    _objectFactory = configScope.SqlMapper.ObjectFactory.CreateFactory(_class, Type.EmptyTypes);
                }
            }

            #endregion

            #region Load the Result Properties

            foreach (XmlNode resultNode in configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_RESULT), configScope.XmlNamespaceManager))
            {
                mapping = ResultPropertyDeSerializer.Deserialize(resultNode, configScope);

                configScope.ErrorContext.MoreInfo = "initialize result property: " + mapping.PropertyName;

                mapping.Initialize(configScope, _class);

                _properties.Add(mapping);
            }
            #endregion

            #region Load the Discriminator Property

            XmlNode discriminatorNode = configScope.NodeContext.SelectSingleNode(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_DISCRIMNATOR), configScope.XmlNamespaceManager);
            if (discriminatorNode != null)
            {
                configScope.ErrorContext.MoreInfo = "initialize discriminator";

                this.Discriminator = DiscriminatorDeSerializer.Deserialize(discriminatorNode, configScope);
                this.Discriminator.SetMapping(configScope, _class);
            }
            #endregion

            #region Load the SubMap Properties

            if (configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_SUBMAP), configScope.XmlNamespaceManager).Count > 0 && this.Discriminator == null)
            {
                throw new ConfigurationException("The discriminator is null, but somehow a subMap was reached.  This is a bug.");
            }
            foreach (XmlNode resultNode in configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_SUBMAP), configScope.XmlNamespaceManager))
            {
                configScope.ErrorContext.MoreInfo = "initialize subMap";
                subMap = SubMapDeSerializer.Deserialize(resultNode, configScope);

                this.Discriminator.Add(subMap);
            }
            #endregion
        }
 /// <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);
 }
 /// <summary>
 /// Indicate if a ResultProperty is in the collection
 /// </summary>
 /// <param name="value">A ResultProperty</param>
 /// <returns>True fi is in</returns>
 public bool Contains(ResultProperty value)
 {
     return(Contains(value.PropertyName));
 }