Example #1
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 = ((IDataRecord)reader).GetFieldType(columnIndex);

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

            object dataBaseValue = mapping.GetDataBaseValue(reader);

            request.IsRowDataFound = request.IsRowDataFound || (dataBaseValue != null);

            return(dataBaseValue);
        }
Example #2
0
        /// <summary>
        /// Calculte a unique key which identify the resukt object build by this <see cref="IResultMap"/>
        /// </summary>
        /// <param name="resultMap"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected static string GetUniqueKey(IResultMap resultMap, IDataReader reader)
        {
            if (resultMap.GroupByProperties.Count > 0)
            {
                StringBuilder keyBuffer = new StringBuilder();

                for (int i = 0; i < resultMap.GroupByProperties.Count; i++)
                {
                    ResultProperty resultProperty = resultMap.GroupByProperties[i];
                    keyBuffer.Append(resultProperty.GetDataBaseValue(reader));
                    keyBuffer.Append('-');
                }

                if (keyBuffer.Length < 1)
                {
                    // we should never go here
                    return(null);
                }
                // separator value not likely to appear in a database
                keyBuffer.Append(KEY_SEPARATOR);
                return(keyBuffer.ToString());
            }
            // we should never go here
            return(null);
        }
Example #3
0
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/>
        /// a an auto result map is used.
        /// </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 (outObject == null)
            {
                outObject = request.CurrentResultMap.CreateInstanceOfResult(null);
            }

            AutoResultMap resultMap = InitializeAutoResultMap(request, reader, ref outObject);

            // En configuration initialiser des AutoResultMap (IResultMap) avec uniquement leur class name et class et les mettres
            // ds Statement.ResultsMap puis ds AutoMapStrategy faire comme AutoResultMap ds Java
            // tester si la request.CurrentResultMap [AutoResultMap (IResultMap)] est initialisée
            // [if (allowRemapping || getResultMappings() == null) {initialize(rs);] java
            // si ( request.Statement.AllowRemapping || (request.CurrentResultMap as AutoResultMap).IsInitalized) ....

            for (int index = 0; index < resultMap.Properties.Count; index++)
            {
                ResultProperty property = resultMap.Properties[index];
                resultMap.SetValueOfProperty(ref outObject, property,
                                             property.GetDataBaseValue(reader));
            }

            return(outObject);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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);
        }
Example #6
0
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object obj2 = resultObject;

            if (reader.FieldCount == 1)
            {
                ResultProperty property = new ResultProperty {
                    PropertyName = "value",
                    ColumnIndex  = 0,
                    TypeHandler  = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(0))
                };
                return(property.GetDataBaseValue(reader));
            }
            if (reader.FieldCount <= 1)
            {
                return(obj2);
            }
            object[] objArray   = new object[reader.FieldCount];
            int      fieldCount = reader.FieldCount;

            for (int i = 0; i < fieldCount; i++)
            {
                objArray[i] = new ResultProperty {
                    PropertyName = "value", ColumnIndex = i, TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i))
                }.GetDataBaseValue(reader);
            }
            return(objArray);
        }
Example #7
0
        public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader)
        {
            if ((mapping.TypeHandler == null) || (mapping.TypeHandler is UnknownTypeHandler))
            {
                lock (mapping)
                {
                    if ((mapping.TypeHandler == null) || (mapping.TypeHandler is UnknownTypeHandler))
                    {
                        int i = 0;
                        if (mapping.ColumnIndex == -999999)
                        {
                            i = reader.GetOrdinal(mapping.ColumnName);
                        }
                        else
                        {
                            i = mapping.ColumnIndex;
                        }
                        Type fieldType = reader.GetFieldType(i);
                        mapping.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(fieldType);
                    }
                }
            }
            object dataBaseValue = mapping.GetDataBaseValue(reader);

            request.IsRowDataFound = request.IsRowDataFound || (dataBaseValue != null);
            return(dataBaseValue);
        }
Example #8
0
        /// <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 = request.CurrentResultMap.CreateInstanceOfResult(null);
            }
            //将reader当前行中的所有字段加入到IDictionary对象中
            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));

                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,
                    typeof(IDictionary),
                    request.DataExchangeFactory,
                    typeHandler);

                dictionary.Add(
                    reader.GetName(i),
                    property.GetDataBaseValue(reader));
            }

            return(outObject);
        }
Example #9
0
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object obj2 = resultObject;

            if (obj2 == null)
            {
                obj2 = (request.CurrentResultMap as AutoResultMap).CreateInstanceOfResultClass();
            }
            AutoResultMap map = this.InitializeAutoResultMap(request, ref reader, ref obj2);

            for (int i = 0; i < map.Properties.Count; i++)
            {
                ResultProperty property = map.Properties[i];
                map.SetValueOfProperty(ref obj2, property, property.GetDataBaseValue(reader));
            }
            return(obj2);
        }
Example #10
0
        protected string GetUniqueKey(IResultMap resultMap, RequestScope request, IDataReader reader)
        {
            if (resultMap.GroupByProperties.Count <= 0)
            {
                return(null);
            }
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < resultMap.GroupByProperties.Count; i++)
            {
                ResultProperty property = resultMap.GroupByProperties[i];
                builder.Append(property.GetDataBaseValue(reader));
                builder.Append('-');
            }
            if (builder.Length < 1)
            {
                return(null);
            }
            builder.Append("\002");
            return(builder.ToString());
        }
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object        obj2             = resultObject;
            AutoResultMap currentResultMap = request.CurrentResultMap as AutoResultMap;

            if (obj2 == null)
            {
                obj2 = currentResultMap.CreateInstanceOfResultClass();
            }
            int fieldCount = reader.FieldCount;

            for (int i = 0; i < fieldCount; i++)
            {
                ResultProperty property = new ResultProperty {
                    PropertyName = "value",
                    ColumnIndex  = i,
                    TypeHandler  = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(i))
                };
                ((IList)obj2).Add(property.GetDataBaseValue(reader));
            }
            return(obj2);
        }
Example #12
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);
            }

            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);
        }
Example #13
0
        /// <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>
        /// <returns></returns>
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object outObject = resultObject;

            if (reader.FieldCount == 1)
            {
                const string propertyName = "value";
                const int    columnIndex  = 0;
                ITypeHandler typeHandler  = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(0));

                ResultProperty property = new ResultProperty(
                    propertyName,
                    string.Empty,
                    columnIndex,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    false,
                    string.Empty,
                    null,
                    string.Empty,
                    null,
                    request.DataExchangeFactory,
                    typeHandler);

                //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++)
                {
                    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,
                        request.DataExchangeFactory,
                        typeHandler);

                    //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);
        }
Example #14
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></returns>
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader);
            DataRow    dataRow   = (DataRow)resultObject;
            DataTable  dataTable = dataRow.Table;

            if (dataTable.Columns.Count == 0)
            {
                // Builds and adss the columns
                dataTable.TableName = resultMap.Id;
                if (resultMap is AutoResultMap)
                {
                    for (int index = 0; index < reader.FieldCount; index++)
                    {
                        string columnName = reader.GetName(index);
                        Type   type       = reader.GetFieldType(index);

                        DataColumn column = new DataColumn();
                        column.DataType   = type;
                        column.ColumnName = columnName;
                        dataTable.Columns.Add(column);
                    }
                }
                else
                {
                    for (int index = 0; index < resultMap.Properties.Count; index++)
                    {
                        ResultProperty property = resultMap.Properties[index];
                        DataColumn     column   = new DataColumn();
                        if (property.CLRType.Length > 0)
                        {
                            column.DataType = request.DataExchangeFactory.TypeHandlerFactory.GetType(property.CLRType);
                        }
                        else
                        {
                            object value = property.GetDataBaseValue(reader);
                            if (value == null)
                            {
                                int columnIndex = reader.GetOrdinal(property.ColumnName);
                                column.DataType = reader.GetFieldType(columnIndex);
                            }
                            else
                            {
                                column.DataType = value.GetType();
                            }
                        }
                        column.ColumnName = property.PropertyName;

                        dataTable.Columns.Add(column);
                    }
                }
            }


            if (resultMap is AutoResultMap)
            {
                for (int index = 0; index < reader.FieldCount; index++)
                {
                    string       propertyName = reader.GetName(index);
                    int          columnIndex  = index;
                    ITypeHandler typeHandler  = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(reader.GetFieldType(index));

                    ResultProperty property = new ResultProperty(
                        propertyName,
                        string.Empty,
                        columnIndex,
                        string.Empty,
                        string.Empty,
                        string.Empty,
                        false,
                        string.Empty,
                        null,
                        string.Empty,
                        typeof(DataRow),
                        request.DataExchangeFactory,
                        typeHandler);

                    object value = property.GetDataBaseValue(reader);
                    if (value == null)
                    {
                        value = DBNull.Value;
                    }
                    dataRow[property.PropertyName] = value;
                }
            }
            else
            {
                for (int index = 0; index < resultMap.Properties.Count; index++)
                {
                    ResultProperty property = resultMap.Properties[index];
                    object         value    = property.GetDataBaseValue(reader);
                    if (value == null)
                    {
                        value = DBNull.Value;
                    }
                    dataRow[property.PropertyName] = value;
                }
            }

            return(null);
        }