public SqlText ParseInlineParameterMap(IScope scope, IStatement statement, string sqlStatement)
        {
            string    str  = sqlStatement;
            ArrayList list = new ArrayList();
            Type      parameterClassType = null;

            if (statement != null)
            {
                parameterClassType = statement.ParameterClass;
            }
            StringTokenizer tokenizer  = new StringTokenizer(sqlStatement, "#", true);
            StringBuilder   builder    = new StringBuilder();
            string          current    = null;
            string          str3       = null;
            IEnumerator     enumerator = tokenizer.GetEnumerator();

            while (enumerator.MoveNext())
            {
                current = (string)enumerator.Current;
                if ("#".Equals(str3))
                {
                    if ("#".Equals(current))
                    {
                        builder.Append("#");
                        current = null;
                    }
                    else
                    {
                        ParameterProperty property = null;
                        if (current.IndexOf(":") > -1)
                        {
                            property = this.OldParseMapping(current, parameterClassType, scope);
                        }
                        else
                        {
                            property = this.NewParseMapping(current, parameterClassType, scope);
                        }
                        list.Add(property);
                        builder.Append("? ");
                        enumerator.MoveNext();
                        current = (string)enumerator.Current;
                        if (!"#".Equals(current))
                        {
                            throw new DataMapperException("Unterminated inline parameter in mapped statement (" + statement.Id + ").");
                        }
                        current = null;
                    }
                }
                else if (!"#".Equals(current))
                {
                    builder.Append(current);
                }
                str3 = current;
            }
            str = builder.ToString();
            ParameterProperty[] propertyArray = (ParameterProperty[])list.ToArray(typeof(ParameterProperty));
            return(new SqlText {
                Text = str, Parameters = propertyArray
            });
        }
        public int Add(ParameterProperty value)
        {
            this.Resize(this._count + 1);
            int index = this._count++;

            this._innerList[index] = value;
            return(index);
        }
Example #3
0
        /// <summary>
        /// Add an ParameterProperty
        /// </summary>
        /// <param name="value"></param>
        /// <returns>Index</returns>
        public int Add(ParameterProperty value)
        {
            Resize(_count + 1);
            int index = _count++;

            _innerList[index] = value;

            return(index);
        }
Example #4
0
 public void AddParameterProperty(ParameterProperty property)
 {
     this._propertiesMap[property.PropertyName] = property;
     this._properties.Add(property);
     if (!this._propertiesList.Contains(property))
     {
         this._propertiesList.Add(property);
     }
 }
Example #5
0
 public void InsertParameterProperty(int index, ParameterProperty property)
 {
     this._propertiesMap[property.PropertyName] = property;
     this._properties.Insert(index, property);
     if (!this._propertiesList.Contains(property))
     {
         this._propertiesList.Insert(index, property);
     }
 }
        public override bool Equals(object obj)
        {
            if ((obj == null) || (base.GetType() != obj.GetType()))
            {
                return(false);
            }
            ParameterProperty property = (ParameterProperty)obj;

            return(this.PropertyName == property.PropertyName);
        }
 public void Insert(int index, ParameterProperty value)
 {
     if ((index < 0) || (index > this._count))
     {
         throw new ArgumentOutOfRangeException("index");
     }
     this.Resize(this._count + 1);
     Array.Copy(this._innerList, index, this._innerList, index + 1, this._count - index);
     this._innerList[index] = value;
     this._count++;
 }
Example #8
0
 /// <summary>
 /// Indicate if a ParameterProperty is in the collection
 /// </summary>
 /// <param name="value">A ParameterProperty</param>
 /// <returns>True fi is in</returns>
 public bool Contains(ParameterProperty value)
 {
     for (int i = 0; i < _count; i++)
     {
         if (_innerList[i].PropertyName == value.PropertyName)
         {
             return(true);
         }
     }
     return(false);
 }
Example #9
0
        public void BuildProperties(ConfigurationScope configScope)
        {
            ParameterProperty property = null;

            foreach (XmlNode node in configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix("parameter"), configScope.XmlNamespaceManager))
            {
                property = ParameterPropertyDeSerializer.Deserialize(node, configScope);
                property.Initialize(configScope, this._parameterClass);
                this.AddParameterProperty(property);
            }
        }
Example #10
0
        public void SetParameter(ParameterProperty mapping, IDataParameter dataParameter, object parameterValue)
        {
            object       data        = this._dataExchange.GetData(mapping, parameterValue);
            ITypeHandler typeHandler = mapping.TypeHandler;

            if (mapping.HasNullValue && typeHandler.Equals(data, mapping.NullValue))
            {
                data = null;
            }
            typeHandler.SetParameter(dataParameter, data, mapping.DbType);
        }
Example #11
0
 /// <summary>
 /// Remove a ParameterProperty of the collection.
 /// </summary>
 public void Remove(ParameterProperty value)
 {
     for (int i = 0; i < _count; i++)
     {
         if (_innerList[i].PropertyName == value.PropertyName)
         {
             RemoveAt(i);
             return;
         }
     }
 }
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"></see> is equal to the current <see cref="System.Object"></see>.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"></see> to compare with the current <see cref="System.Object"></see>.</param>
        /// <returns>
        /// true if the specified <see cref="System.Object"></see> is equal to the current <see cref="System.Object"></see>; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            //Check for null and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            ParameterProperty p = (ParameterProperty)obj;

            return(this.PropertyName == p.PropertyName);
        }
Example #13
0
        /// <summary>
        /// Insert a ParameterProperty ine the ParameterProperty list at the specified index..
        /// </summary>
        /// <param name="index">
        /// The zero-based index at which ParameterProperty should be inserted.
        /// </param>
        /// <param name="property">The ParameterProperty to insert. </param>
        public void InsertParameterProperty(int index, ParameterProperty property)
        {
            // These mappings will replace any mappings that this map
            // had for any of the keys currently in the specified map.
            _propertiesMap[property.PropertyName] = property;
            _properties.Insert(index, property);

            if (_propertiesList.Contains(property) == false)
            {
                _propertiesList.Insert(index, property);
            }
        }
 /// <summary>
 /// Gets the data to be set into a IDataParameter.
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="parameterObject"></param>
 public override object GetData(ParameterProperty mapping, object parameterObject)
 {
     if (mapping.IsComplexMemberName || _parameterClass!=parameterObject.GetType())
     {
         return ObjectProbe.GetMemberValue(parameterObject, mapping.PropertyName,
             this.DataExchangeFactory.AccessorFactory);
     }
     else
     {
         return mapping.GetAccessor.Get(parameterObject);
     }
 }
Example #15
0
        /// <summary>
        /// Insert a ParameterProperty in the collection.
        /// </summary>
        /// <param name="index">Index where to insert.</param>
        /// <param name="value">A ParameterProperty</param>
        public void Insert(int index, ParameterProperty 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++;
        }
Example #16
0
        /// <summary>
        /// Set parameter value, replace the null value if any.
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataParameter"></param>
        /// <param name="parameterValue"></param>
        public void SetParameter(ParameterProperty mapping, IDataParameter dataParameter, object parameterValue)
        {
            object value = _dataExchange.GetData(mapping, parameterValue);

            ITypeHandler typeHandler = mapping.TypeHandler;

            // Apply Null Value
            if (mapping.HasNullValue)
            {
                if (typeHandler.Equals(value, mapping.NullValue))
                {
                    value = null;
                }
            }

            typeHandler.SetParameter(dataParameter, value, mapping.DbType);
        }
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>An <see cref="ParameterProperty"/></returns>
        public ParameterProperty Clone()
        {
            ParameterProperty property = new ParameterProperty();

            property.CallBackName       = this.CallBackName;
            property.CLRType            = this.CLRType;
            property.ColumnName         = this.ColumnName;
            property.DbType             = this.DbType;
            property.DirectionAttribute = this.DirectionAttribute;
            property.NullValue          = this.NullValue;
            property.PropertyName       = this.PropertyName;
            property.Precision          = this.Precision;
            property.Scale = this.Scale;
            property.Size  = this.Size;

            return(property);
        }
 /// <summary>
 /// Gets the data to be set into a IDataParameter.
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="parameterObject"></param>
 public override object GetData(ParameterProperty mapping, object parameterObject)
 {
     if (parameterObject!=null)
     {
      			    if (this.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterObject.GetType()))
         {
             return parameterObject;
         }
         else
         {
             return ObjectProbe.GetMemberValue(parameterObject, mapping.PropertyName, this.DataExchangeFactory.AccessorFactory);
         }
     }
     else
     {
         return null;
     }
 }
        /// <summary>
        /// Deserialize a ResultMap object
        /// </summary>
        /// <param name="node"></param>
        /// <param name="configScope"></param>
        /// <returns></returns>
        public static ParameterProperty Deserialize(XmlNode node, ConfigurationScope configScope)
        {
            ParameterProperty property = new ParameterProperty();
            NameValueCollection prop = NodeUtils.ParseAttributes(node, configScope.Properties);

            configScope.ErrorContext.MoreInfo = "ParameterPropertyDeSerializer";

            property.CallBackName = NodeUtils.GetStringAttribute(prop, "typeHandler");
            property.CLRType =  NodeUtils.GetStringAttribute(prop, "type");
            property.ColumnName =  NodeUtils.GetStringAttribute(prop, "column");
            property.DbType =  NodeUtils.GetStringAttribute(prop, "dbType", null);
            property.DirectionAttribute =  NodeUtils.GetStringAttribute(prop, "direction");
            property.NullValue =  prop["nullValue"];
            property.PropertyName =  NodeUtils.GetStringAttribute(prop, "property");
            property.Precision = NodeUtils.GetByteAttribute(prop, "precision", 0);
            property.Scale = NodeUtils.GetByteAttribute(prop, "scale", 0);
            property.Size = NodeUtils.GetIntAttribute(prop, "size", -1);

            return property;
        }
 private IDbDataParameter Search(ISqlMapSession session,IDbDataParameter[] parameters, ParameterProperty property, int index)
 {
     if (property.ColumnName.Length>0)
     {
         for (int i = 0; i < parameters.Length; i++)
         {
             string parameterName = parameters[i].ParameterName;
             if (session.DataSource.DbProvider.UseParameterPrefixInParameter)
             {
                 if (parameterName.StartsWith(session.DataSource.DbProvider.ParameterPrefix))
                 {
                    int prefixLength = session.DataSource.DbProvider.ParameterPrefix.Length;
                    parameterName = parameterName.Substring(prefixLength);
                 }
             }
             if (property.ColumnName.Equals(parameterName))
             {
                 return parameters[i];
             }
         }
         throw new IndexOutOfRangeException("The parameter '" + property.ColumnName + "' does not exist in the stored procedure '" +_statement.Id+"'. Check your parameterMap.");
     }
     else
     {
         return parameters[index];
     }
 }
        /// <summary>
        /// Sets the value to the parameter property.
        /// </summary>
        /// <remarks>Use to set value on output parameter</remarks>
        /// <param name="mapping"></param>
        /// <param name="target"></param>
        /// <param name="dataBaseValue"></param>
        public override void SetData(ref object target, ParameterProperty mapping, object dataBaseValue)
        {
            if (mapping.IsComplexMemberName)
            {
                ObjectProbe.SetMemberValue(target, mapping.PropertyName, dataBaseValue,
                    this.DataExchangeFactory.ObjectFactory,
                    this.DataExchangeFactory.AccessorFactory);
            }
            else
            {
                ISetAccessorFactory setAccessorFactory = this.DataExchangeFactory.AccessorFactory.SetAccessorFactory;
                ISetAccessor _setAccessor = setAccessorFactory.CreateSetAccessor(_parameterClass, mapping.PropertyName);

                _setAccessor.Set(target, dataBaseValue);
            }
        }
Example #22
0
        /// <summary>
        /// Parse inline parameter with syntax as
        /// #propertyName:dbType:nullValue#
        /// </summary>
        /// <param name="token"></param>
        /// <param name="parameterClassType"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        private ParameterProperty OldParseMapping(string token, Type parameterClassType, IScope scope)
        {
            ParameterProperty mapping = new ParameterProperty();

            if (token.IndexOf(PARAM_DELIM) > -1)
            {
                StringTokenizer paramParser     = new StringTokenizer(token, PARAM_DELIM, true);
                IEnumerator     enumeratorParam = paramParser.GetEnumerator();

                int n1 = paramParser.TokenNumber;
                if (n1 == 3)
                {
                    enumeratorParam.MoveNext();
                    string propertyName = ((string)enumeratorParam.Current).Trim();
                    mapping.PropertyName = propertyName;

                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext();                     //ignore ":"
                    string dBType = ((string)enumeratorParam.Current).Trim();
                    mapping.DbType = dBType;

                    ITypeHandler handler = null;
                    if (parameterClassType == null)
                    {
                        handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                    else
                    {
                        handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, propertyName, null, dBType);
                    }
                    mapping.TypeHandler = handler;
                    mapping.Initialize(scope, parameterClassType);
                }
                else if (n1 >= 5)
                {
                    enumeratorParam.MoveNext();
                    string propertyName = ((string)enumeratorParam.Current).Trim();
                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext();                     //ignore ":"
                    string dBType = ((string)enumeratorParam.Current).Trim();
                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext();                     //ignore ":"
                    string nullValue = ((string)enumeratorParam.Current).Trim();
                    while (enumeratorParam.MoveNext())
                    {
                        nullValue = nullValue + ((string)enumeratorParam.Current).Trim();
                    }

                    mapping.PropertyName = propertyName;
                    mapping.DbType       = dBType;
                    mapping.NullValue    = nullValue;
                    ITypeHandler handler = null;
                    if (parameterClassType == null)
                    {
                        handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                    else
                    {
                        handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, propertyName, null, dBType);
                    }
                    mapping.TypeHandler = handler;
                    mapping.Initialize(scope, parameterClassType);
                }
                else
                {
                    throw new ConfigurationException("Incorrect inline parameter map format: " + token);
                }
            }
            else
            {
                mapping.PropertyName = token;
                ITypeHandler handler = null;
                if (parameterClassType == null)
                {
                    handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                }
                else
                {
                    handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, token, null, null);
                }
                mapping.TypeHandler = handler;
                mapping.Initialize(scope, parameterClassType);
            }
            return(mapping);
        }
        private ParameterProperty NewParseMapping(string token, Type parameterClassType, IScope scope)
        {
            ParameterProperty property   = new ParameterProperty();
            IEnumerator       enumerator = new StringTokenizer(token, "=,", false).GetEnumerator();

            enumerator.MoveNext();
            property.PropertyName = ((string)enumerator.Current).Trim();
            while (enumerator.MoveNext())
            {
                string current = (string)enumerator.Current;
                if (!enumerator.MoveNext())
                {
                    throw new DataMapperException("Incorrect inline parameter map format (missmatched name=value pairs): " + token);
                }
                string str2 = (string)enumerator.Current;
                if (!"type".Equals(current))
                {
                    if (!"dbType".Equals(current))
                    {
                        if (!"direction".Equals(current))
                        {
                            if (!"nullValue".Equals(current))
                            {
                                if (!"handler".Equals(current))
                                {
                                    throw new DataMapperException("Unrecognized parameter mapping field: '" + current + "' in " + token);
                                }
                                property.CallBackName = str2;
                            }
                            else
                            {
                                property.NullValue = str2;
                            }
                        }
                        else
                        {
                            property.DirectionAttribute = str2;
                        }
                        continue;
                    }
                    property.DbType = str2;
                }
                else
                {
                    property.CLRType = str2;
                    continue;
                }
            }
            if (property.CallBackName.Length > 0)
            {
                property.Initialize(scope, parameterClassType);
                return(property);
            }
            ITypeHandler unkownTypeHandler = null;

            if (parameterClassType == null)
            {
                unkownTypeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
            }
            else
            {
                unkownTypeHandler = this.ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, property.PropertyName, property.CLRType, property.DbType);
            }
            property.TypeHandler = unkownTypeHandler;
            property.Initialize(scope, parameterClassType);
            return(property);
        }
 /// <summary>
 /// Sets the value to the parameter property.
 /// </summary>
 /// <remarks>Use to set value on output parameter</remarks>
 /// <param name="mapping"></param>
 /// <param name="target"></param>
 /// <param name="dataBaseValue"></param>
 public override void SetData(ref object target, ParameterProperty mapping, object dataBaseValue)
 {
     target = dataBaseValue;
 }
Example #25
0
 /// <summary>
 /// Gets the data to be set into a IDataParameter.
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="parameterObject"></param>
 public abstract object GetData(ParameterProperty mapping, object parameterObject);
 /// <summary>
 /// Remove a ParameterProperty of the collection.
 /// </summary>
 public void Remove(ParameterProperty value)
 {
     for(int i = 0; i < _count; i++)
     {
         if(_innerList[i].PropertyName==value.PropertyName)
         {
             RemoveAt(i);
             return;
         }
     }
 }
        /// <summary>
        /// Insert a ParameterProperty in the collection.
        /// </summary>
        /// <param name="index">Index where to insert.</param>
        /// <param name="value">A ParameterProperty</param>
        public void Insert(int index, ParameterProperty 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++;
        }
Example #28
0
 /// <summary>
 /// Set output parameter value.
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="dataBaseValue"></param>
 /// <param name="target"></param>
 public void SetOutputParameter(ref object target, ParameterProperty mapping, object dataBaseValue)
 {
     _dataExchange.SetData(ref target, mapping, dataBaseValue);
 }
Example #29
0
 /// <summary>
 /// Gets the data to be set into a IDataParameter.
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="parameterObject"></param>
 public override object GetData(ParameterProperty mapping, object parameterObject)
 {
     return ObjectProbe.GetMemberValue(parameterObject, mapping.PropertyName,
         this.DataExchangeFactory.AccessorFactory);
 }
        /// <summary>
        /// Add an ParameterProperty
        /// </summary>
        /// <param name="value"></param>
        /// <returns>Index</returns>
        public int Add(ParameterProperty value)
        {
            Resize(_count + 1);
            int index = _count++;
            _innerList[index] = value;

            return index;
        }
Example #31
0
        /// <summary>
        /// Parse Inline ParameterMap
        /// </summary>
        /// <param name="statement"></param>
        /// <param name="sqlStatement"></param>
        /// <returns>A new sql command text.</returns>
        /// <param name="scope"></param>
        public SqlText ParseInlineParameterMap(IScope scope, IStatement statement, string sqlStatement)
        {
            string    newSql             = sqlStatement;
            ArrayList mappingList        = new ArrayList();
            Type      parameterClassType = null;

            if (statement != null)
            {
                parameterClassType = statement.ParameterClass;
            }

            StringTokenizer parser       = new StringTokenizer(sqlStatement, PARAMETER_TOKEN, true);
            StringBuilder   newSqlBuffer = new StringBuilder();

            string token     = null;
            string lastToken = null;

            IEnumerator enumerator = parser.GetEnumerator();

            while (enumerator.MoveNext())
            {
                token = (string)enumerator.Current;

                if (PARAMETER_TOKEN.Equals(lastToken))
                {
                    if (PARAMETER_TOKEN.Equals(token))
                    {
                        newSqlBuffer.Append(PARAMETER_TOKEN);
                        token = null;
                    }
                    else
                    {
                        ParameterProperty mapping = null;
                        if (token.IndexOf(PARAM_DELIM) > -1)
                        {
                            mapping = OldParseMapping(token, parameterClassType, scope);
                        }
                        else
                        {
                            mapping = NewParseMapping(token, parameterClassType, scope);
                        }

                        mappingList.Add(mapping);
                        newSqlBuffer.Append("? ");

                        enumerator.MoveNext();
                        token = (string)enumerator.Current;
                        if (!PARAMETER_TOKEN.Equals(token))
                        {
                            throw new DataMapperException("Unterminated inline parameter in mapped statement (" + statement.Id + ").");
                        }
                        token = null;
                    }
                }
                else
                {
                    if (!PARAMETER_TOKEN.Equals(token))
                    {
                        newSqlBuffer.Append(token);
                    }
                }

                lastToken = token;
            }

            newSql = newSqlBuffer.ToString();

            ParameterProperty[] mappingArray = (ParameterProperty[])mappingList.ToArray(typeof(ParameterProperty));

            SqlText sqlText = new SqlText();

            sqlText.Text       = newSql;
            sqlText.Parameters = mappingArray;

            return(sqlText);
        }
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>An <see cref="ParameterProperty"/></returns>
        public ParameterProperty Clone()
        {
            ParameterProperty property = new ParameterProperty();

            property.CallBackName = this.CallBackName;
            property.CLRType = this.CLRType;
            property.ColumnName = this.ColumnName;
            property.DbType = this.DbType;
            property.DirectionAttribute = this.DirectionAttribute;
            property.NullValue = this.NullValue;
            property.PropertyName = this.PropertyName;
            property.Precision = this.Precision;
            property.Scale = this.Scale;
            property.Size = this.Size;

            return property;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mapping"></param>
 public void AddParameterMapping(ParameterProperty mapping)
 {
     _parameterMappings.Add(mapping);
 }
Example #34
0
        /// <summary>
        /// Insert a ParameterProperty ine the ParameterProperty list at the specified index..
        /// </summary>
        /// <param name="index">
        /// The zero-based index at which ParameterProperty should be inserted. 
        /// </param>
        /// <param name="property">The ParameterProperty to insert. </param>
        public void InsertParameterProperty(int index, ParameterProperty property)
        {
            // These mappings will replace any mappings that this map
            // had for any of the keys currently in the specified map.
            _propertiesMap[property.PropertyName] = property;
            _properties.Insert( index, property );

            if (_propertiesList.Contains(property) == false)
            {
                _propertiesList.Insert( index, property );
            }
        }
Example #35
0
 /// <summary>
 /// Sets the value to the parameter property.
 /// </summary>
 /// <remarks>Use to set value on output parameter</remarks>
 /// <param name="mapping"></param>
 /// <param name="target"></param>
 /// <param name="dataBaseValue"></param>
 public abstract void SetData(ref object target, ParameterProperty mapping, object dataBaseValue);
Example #36
0
 /// <summary>
 /// Set output parameter value.
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="dataBaseValue"></param>
 /// <param name="target"></param>
 public void SetOutputParameter(ref object target, ParameterProperty mapping, object dataBaseValue )
 {
     _dataExchange.SetData(ref target, mapping, dataBaseValue);
 }
Example #37
0
        /// <summary>
        /// Set parameter value, replace the null value if any.
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="dataParameter"></param>
        /// <param name="parameterValue"></param>
        public void SetParameter(ParameterProperty mapping, IDataParameter dataParameter, object parameterValue)
        {
            object value = _dataExchange.GetData(mapping, parameterValue);

            ITypeHandler typeHandler = mapping.TypeHandler;

            // Apply Null Value
            if (mapping.HasNullValue)
            {
                if (typeHandler.Equals(value, mapping.NullValue))
                {
                    value = null;
                }
            }

            typeHandler.SetParameter(dataParameter, value, mapping.DbType);
        }
        /// <summary>
        /// Parse inline parameter with syntax as
        /// #propertyName,type=string,dbype=Varchar,direction=Input,nullValue=N/A,handler=string#
        /// </summary>
        /// <param name="token"></param>
        /// <param name="parameterClassType"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        private ParameterProperty NewParseMapping(string token, Type parameterClassType, IScope scope)
        {
            ParameterProperty mapping = new ParameterProperty();

            StringTokenizer paramParser = new StringTokenizer(token, "=,", false);
            IEnumerator enumeratorParam = paramParser.GetEnumerator();

            enumeratorParam.MoveNext();

            mapping.PropertyName = ((string)enumeratorParam.Current).Trim();

            while (enumeratorParam.MoveNext())
            {
                string field = (string)enumeratorParam.Current;
                if (enumeratorParam.MoveNext())
                {
                    string value = (string)enumeratorParam.Current;
                    if ("type".Equals(field))
                    {
                        mapping.CLRType = value;
                    }
                    else if ("dbType".Equals(field))
                    {
                        mapping.DbType = value;
                    }
                    else if ("direction".Equals(field))
                    {
                        mapping.DirectionAttribute = value;
                    }
                    else if ("nullValue".Equals(field))
                    {
                        mapping.NullValue = value;
                    }
                    else if ("handler".Equals(field))
                    {
                        mapping.CallBackName = value;
                    }
                    else
                    {
                        throw new DataMapperException("Unrecognized parameter mapping field: '" + field + "' in " + token);
                    }
                }
                else
                {
                    throw new DataMapperException("Incorrect inline parameter map format (missmatched name=value pairs): " + token);
                }
            }

            if (mapping.CallBackName.Length >0)
            {
                mapping.Initialize( scope, parameterClassType );
            }
            else
            {
                ITypeHandler handler = null;
                if (parameterClassType == null)
                {
                    handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                }
                else
                {
                    handler = ResolveTypeHandler( scope.DataExchangeFactory.TypeHandlerFactory,
                        parameterClassType, mapping.PropertyName,
                        mapping.CLRType, mapping.DbType );
                }
                mapping.TypeHandler = handler;
                mapping.Initialize(  scope, parameterClassType );
            }

            return mapping;
        }
        private ParameterProperty OldParseMapping(string token, Type parameterClassType, IScope scope)
        {
            ParameterProperty property = new ParameterProperty();

            if (token.IndexOf(":") > -1)
            {
                StringTokenizer tokenizer   = new StringTokenizer(token, ":", true);
                IEnumerator     enumerator  = tokenizer.GetEnumerator();
                int             tokenNumber = tokenizer.TokenNumber;
                if (tokenNumber == 3)
                {
                    enumerator.MoveNext();
                    string str = ((string)enumerator.Current).Trim();
                    property.PropertyName = str;
                    enumerator.MoveNext();
                    enumerator.MoveNext();
                    string str2 = ((string)enumerator.Current).Trim();
                    property.DbType = str2;
                    ITypeHandler unkownTypeHandler = null;
                    if (parameterClassType == null)
                    {
                        unkownTypeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                    else
                    {
                        unkownTypeHandler = this.ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, str, null, str2);
                    }
                    property.TypeHandler = unkownTypeHandler;
                    property.Initialize(scope, parameterClassType);
                    return(property);
                }
                if (tokenNumber < 5)
                {
                    throw new ConfigurationException("Incorrect inline parameter map format: " + token);
                }
                enumerator.MoveNext();
                string propertyName = ((string)enumerator.Current).Trim();
                enumerator.MoveNext();
                enumerator.MoveNext();
                string dbType = ((string)enumerator.Current).Trim();
                enumerator.MoveNext();
                enumerator.MoveNext();
                string str5 = ((string)enumerator.Current).Trim();
                while (enumerator.MoveNext())
                {
                    str5 = str5 + ((string)enumerator.Current).Trim();
                }
                property.PropertyName = propertyName;
                property.DbType       = dbType;
                property.NullValue    = str5;
                ITypeHandler handler2 = null;
                if (parameterClassType == null)
                {
                    handler2 = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                }
                else
                {
                    handler2 = this.ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, propertyName, null, dbType);
                }
                property.TypeHandler = handler2;
                property.Initialize(scope, parameterClassType);
                return(property);
            }
            property.PropertyName = token;
            ITypeHandler handler3 = null;

            if (parameterClassType == null)
            {
                handler3 = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
            }
            else
            {
                handler3 = this.ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, token, null, null);
            }
            property.TypeHandler = handler3;
            property.Initialize(scope, parameterClassType);
            return(property);
        }
        /// <summary>
        /// Parse inline parameter with syntax as
        /// #propertyName:dbType:nullValue#
        /// </summary>
        /// <param name="token"></param>
        /// <param name="parameterClassType"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        private ParameterProperty OldParseMapping(string token, Type parameterClassType, IScope scope)
        {
            ParameterProperty mapping = new ParameterProperty();

            if (token.IndexOf(PARAM_DELIM) > -1)
            {
                StringTokenizer paramParser = new StringTokenizer(token, PARAM_DELIM, true);
                IEnumerator enumeratorParam = paramParser.GetEnumerator();

                int n1 = paramParser.TokenNumber;
                if (n1 == 3)
                {
                    enumeratorParam.MoveNext();
                    string propertyName = ((string)enumeratorParam.Current).Trim();
                    mapping.PropertyName = propertyName;

                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext(); //ignore ":"
                    string dBType = ((string)enumeratorParam.Current).Trim();
                    mapping.DbType = dBType;

                    ITypeHandler handler = null;
                    if (parameterClassType == null)
                    {
                        handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                    else
                    {
                        handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, propertyName, null, dBType);
                    }
                    mapping.TypeHandler = handler;
                    mapping.Initialize( scope, parameterClassType );
                }
                else if (n1 >= 5)
                {
                    enumeratorParam.MoveNext();
                    string propertyName = ((string)enumeratorParam.Current).Trim();
                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext(); //ignore ":"
                    string dBType = ((string)enumeratorParam.Current).Trim();
                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext(); //ignore ":"
                    string nullValue = ((string)enumeratorParam.Current).Trim();
                    while (enumeratorParam.MoveNext())
                    {
                        nullValue = nullValue + ((string)enumeratorParam.Current).Trim();
                    }

                    mapping.PropertyName = propertyName;
                    mapping.DbType = dBType;
                    mapping.NullValue = nullValue;
                    ITypeHandler handler = null;
                    if (parameterClassType == null)
                    {
                        handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                    }
                    else
                    {
                        handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, propertyName, null, dBType);
                    }
                    mapping.TypeHandler = handler;
                    mapping.Initialize( scope, parameterClassType );
                }
                else
                {
                    throw new ConfigurationException("Incorrect inline parameter map format: " + token);
                }
            }
            else
            {
                mapping.PropertyName = token;
                ITypeHandler handler = null;
                if (parameterClassType == null)
                {
                    handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                }
                else
                {
                    handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory, parameterClassType, token, null, null);
                }
                mapping.TypeHandler = handler;
                mapping.Initialize( scope, parameterClassType );
            }
            return mapping;
        }
 /// <summary>
 /// Add a list of ParameterProperty to the collection
 /// </summary>
 /// <param name="value"></param>
 public void AddRange(ParameterProperty[] value)
 {
     for (int i = 0;   i < value.Length; i++)
     {
         Add(value[i]);
     }
 }
Example #42
0
        /// <summary>
        /// Parse inline parameter with syntax as
        /// #propertyName,type=string,dbype=Varchar,direction=Input,nullValue=N/A,handler=string#
        /// </summary>
        /// <param name="token"></param>
        /// <param name="parameterClassType"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        private ParameterProperty NewParseMapping(string token, Type parameterClassType, IScope scope)
        {
            ParameterProperty mapping = new ParameterProperty();

            StringTokenizer paramParser     = new StringTokenizer(token, "=,", false);
            IEnumerator     enumeratorParam = paramParser.GetEnumerator();

            enumeratorParam.MoveNext();

            mapping.PropertyName = ((string)enumeratorParam.Current).Trim();

            while (enumeratorParam.MoveNext())
            {
                string field = (string)enumeratorParam.Current;
                if (enumeratorParam.MoveNext())
                {
                    string value = (string)enumeratorParam.Current;
                    if ("type".Equals(field))
                    {
                        mapping.CLRType = value;
                    }
                    else if ("dbType".Equals(field))
                    {
                        mapping.DbType = value;
                    }
                    else if ("direction".Equals(field))
                    {
                        mapping.DirectionAttribute = value;
                    }
                    else if ("nullValue".Equals(field))
                    {
                        mapping.NullValue = value;
                    }
                    else if ("handler".Equals(field))
                    {
                        mapping.CallBackName = value;
                    }
                    else
                    {
                        throw new DataMapperException("Unrecognized parameter mapping field: '" + field + "' in " + token);
                    }
                }
                else
                {
                    throw new DataMapperException("Incorrect inline parameter map format (missmatched name=value pairs): " + token);
                }
            }

            if (mapping.CallBackName.Length > 0)
            {
                mapping.Initialize(scope, parameterClassType);
            }
            else
            {
                ITypeHandler handler = null;
                if (parameterClassType == null)
                {
                    handler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
                }
                else
                {
                    handler = ResolveTypeHandler(scope.DataExchangeFactory.TypeHandlerFactory,
                                                 parameterClassType, mapping.PropertyName,
                                                 mapping.CLRType, mapping.DbType);
                }
                mapping.TypeHandler = handler;
                mapping.Initialize(scope, parameterClassType);
            }

            return(mapping);
        }
Example #43
0
 /// <summary>
 /// Sets the value to the parameter property.
 /// </summary>
 /// <remarks>Use to set value on output parameter</remarks>
 /// <param name="mapping"></param>
 /// <param name="target"></param>
 /// <param name="dataBaseValue"></param>
 public override void SetData(ref object target, ParameterProperty mapping, object dataBaseValue)
 {
     ObjectProbe.SetMemberValue(target, mapping.PropertyName, dataBaseValue,
         this.DataExchangeFactory.ObjectFactory,
         this.DataExchangeFactory.AccessorFactory);
 }
 /// <summary>
 /// Indicate if a ParameterProperty is in the collection
 /// </summary>
 /// <param name="value">A ParameterProperty</param>
 /// <returns>True fi is in</returns>
 public bool Contains(ParameterProperty value)
 {
     for (int i = 0;   i < _count; i++)
     {
         if(_innerList[i].PropertyName==value.PropertyName)
         {
             return true;
         }
     }
     return false;
 }