Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
         }
     }
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
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++;
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get the parameter properties child for the xmlNode parameter.
        /// </summary>
        /// <param name="configScope"></param>
        public void BuildProperties(ConfigurationScope configScope)
        {
            ParameterProperty property = null;

            foreach (XmlNode parameterNode in configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_PARAMATER), configScope.XmlNamespaceManager))
            {
                property = ParameterPropertyDeSerializer.Deserialize(parameterNode, configScope);

                property.Initialize(configScope, _parameterClass);

                AddParameterProperty(property);
            }
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
 }