예제 #1
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(PropertyName == p.PropertyName);
        }
예제 #2
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);
            }
        }
예제 #3
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);
        }
예제 #4
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)
        {
            if (property.Direction == ParameterDirection.Output ||
                property.Direction == ParameterDirection.InputOutput)
            {
                HasOutputParameter = true;
            }

            // 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>
        /// 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>
        /// 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      = null;
            string            propertyName = string.Empty;
            string            dbType       = string.Empty;
            string            nullValue    = string.Empty;

            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();
                    propertyName = ((string)enumeratorParam.Current).Trim();

                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext();                     //ignore ":"
                    dbType = ((string)enumeratorParam.Current).Trim();

                    //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();
                    propertyName = ((string)enumeratorParam.Current).Trim();

                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext();                     //ignore ":"
                    dbType = ((string)enumeratorParam.Current).Trim();

                    enumeratorParam.MoveNext();
                    enumeratorParam.MoveNext();                     //ignore ":"
                    nullValue = ((string)enumeratorParam.Current).Trim();

                    while (enumeratorParam.MoveNext())
                    {
                        nullValue = nullValue + ((string)enumeratorParam.Current).Trim();
                    }

                    //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
            {
                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(new ParameterProperty(
                       propertyName,
                       string.Empty,
                       string.Empty,
                       string.Empty,
                       dbType,
                       string.Empty,
                       nullValue,
                       0,
                       0,
                       -1,
                       parameterClassType,
                       scope.DataExchangeFactory));
        }
        /// <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 = null;

            string propertyName = string.Empty;
            string type         = string.Empty;
            string dbType       = string.Empty;
            string direction    = string.Empty;
            string callBack     = string.Empty;
            string nullValue    = string.Empty;

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

            enumeratorParam.MoveNext();

            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))
                    {
                        type = value;
                    }
                    else if ("dbType".Equals(field))
                    {
                        dbType = value;
                    }
                    else if ("direction".Equals(field))
                    {
                        direction = value;
                    }
                    else if ("nullValue".Equals(field))
                    {
                        nullValue = value;
                    }
                    else if ("handler".Equals(field))
                    {
                        callBack = 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(new ParameterProperty(
                       propertyName,
                       string.Empty,
                       callBack,
                       type,
                       dbType,
                       direction,
                       nullValue,
                       0,
                       0,
                       -1,
                       parameterClassType,
                       scope.DataExchangeFactory));
        }
예제 #8
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);
		}
예제 #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);
		}
예제 #10
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 );
			}
		}
예제 #11
0
 /// <summary>
 /// Set output parameter value.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="mapping">The mapping.</param>
 /// <param name="dataBaseValue">The data base value.</param>
 public void SetOutputParameter(ref object target, ParameterProperty mapping, object dataBaseValue)
 {
     dataExchange.SetData(ref target, mapping, dataBaseValue);
 }
        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];
            }

	    }
예제 #13
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="mapping"></param>
		public void AddParameterMapping(ParameterProperty mapping) 
		{
			_parameterMappings.Add(mapping);
		}
예제 #14
0
        /// <summary>
        /// Parse Inline ParameterMap
        /// </summary>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        /// <param name="statementId">The statement id.</param>
        /// <param name="statement">The statement.</param>
        /// <param name="sqlStatement">The SQL statement.</param>
        /// <returns>A new sql command text.</returns>
        public static SqlText ParseInlineParameterMap(DataExchangeFactory dataExchangeFactory, string statementId, IStatement statement, string sqlStatement)
        {
            string newSql = sqlStatement;
            List <ParameterProperty> mappingList = new List <ParameterProperty>();
            Type parameterClassType = null;

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

            if (sqlStatement.Contains(NEW_BEGIN_TOKEN))
            {
                // V3 parameter syntax
                //@{propertyName,column=string,type=string,dbype=string,direction=[Input/Output/InputOutput],nullValue=string,handler=string}

                if (newSql != null)
                {
                    string        toAnalyse    = newSql;
                    int           start        = toAnalyse.IndexOf(NEW_BEGIN_TOKEN);
                    int           end          = toAnalyse.IndexOf(NEW_END_TOKEN);
                    StringBuilder newSqlBuffer = new StringBuilder();

                    while (start > -1 && end > start)
                    {
                        string prepend = toAnalyse.Substring(0, start);
                        string append  = toAnalyse.Substring(end + NEW_END_TOKEN.Length);

                        //EmailAddress,column=string,type=string,dbType=Varchar,[email protected]
                        string            parameter = toAnalyse.Substring(start + NEW_BEGIN_TOKEN.Length, end - start - NEW_BEGIN_TOKEN.Length);
                        ParameterProperty mapping   = NewParseMapping(parameter, parameterClassType, dataExchangeFactory, statementId);
                        mappingList.Add(mapping);
                        newSqlBuffer.Append(prepend);
                        newSqlBuffer.Append(MARK_TOKEN);
                        toAnalyse = append;
                        start     = toAnalyse.IndexOf(NEW_BEGIN_TOKEN);
                        end       = toAnalyse.IndexOf(NEW_END_TOKEN);
                    }
                    newSqlBuffer.Append(toAnalyse);
                    newSql = newSqlBuffer.ToString();
                }
            }
            else
            {
                #region old syntax
                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))
                    {
                        // Double token ## = #
                        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, dataExchangeFactory);
                            }
                            else
                            {
                                mapping = NewParseMapping(token, parameterClassType, dataExchangeFactory, statementId);
                            }

                            mappingList.Add(mapping);
                            newSqlBuffer.Append(MARK_TOKEN + " ");

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

                    lastToken = token;
                }

                newSql = newSqlBuffer.ToString();

                #endregion
            }

            ParameterProperty[] mappingArray = mappingList.ToArray();

            SqlText sqlText = new SqlText();
            sqlText.Text       = newSql;
            sqlText.Parameters = mappingArray;

            return(sqlText);
        }