private ITypeHandler ResolveTypeHandler(TypeHandlerFactory typeHandlerFactory, Type parameterClassType, string propertyName, string propertyType, string dbType)
        {
            if (parameterClassType == null)
            {
                return(typeHandlerFactory.GetUnkownTypeHandler());
            }
            if (typeof(IDictionary).IsAssignableFrom(parameterClassType))
            {
                if ((propertyType == null) || (propertyType.Length == 0))
                {
                    return(typeHandlerFactory.GetUnkownTypeHandler());
                }
                try
                {
                    Type type = TypeUtils.ResolveType(propertyType);
                    return(typeHandlerFactory.GetTypeHandler(type, dbType));
                }
                catch (Exception exception)
                {
                    throw new ConfigurationException("Error. Could not set TypeHandler.  Cause: " + exception.Message, exception);
                }
            }
            if (typeHandlerFactory.GetTypeHandler(parameterClassType, dbType) != null)
            {
                return(typeHandlerFactory.GetTypeHandler(parameterClassType, dbType));
            }
            Type memberTypeForGetter = ObjectProbe.GetMemberTypeForGetter(parameterClassType, propertyName);

            return(typeHandlerFactory.GetTypeHandler(memberTypeForGetter, dbType));
        }
Exemplo n.º 2
0
 public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
 {
     if (parameterObject != null)
     {
         string property = ((BaseTag)tag).Property;
         object obj2     = null;
         if ((property != null) && (property.Length > 0))
         {
             obj2 = ObjectProbe.GetMemberValue(parameterObject, property, base.AccessorFactory);
         }
         else
         {
             obj2 = parameterObject;
         }
         if (obj2 is ICollection)
         {
             if (obj2 != null)
             {
                 return(((ICollection)obj2).Count < 1);
             }
             return(true);
         }
         if ((obj2 != null) && typeof(Array).IsAssignableFrom(obj2.GetType()))
         {
             return(((Array)obj2).GetLength(0) == 0);
         }
         if (obj2 != null)
         {
             return(Convert.ToString(obj2).Equals(""));
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            if (parameterObject == null)
            {
                return(true);
            }
            string propertyName = ((BaseTag)tag).Property;
            object value        = null;

            if (!string.IsNullOrEmpty(propertyName))
            {
                value = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory);
            }
            else
            {
                value = parameterObject;
            }
            if (value is ICollection)
            {
                return((value == null) || (((ICollection)value).Count < 1));
            }
            if (value != null && typeof(Array).IsAssignableFrom(value.GetType()))         //value.GetType().IsArray
            {
                return(((Array)value).GetLength(0) == 0);
            }
            return((value == null) || (Convert.ToString(value).Equals("")));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            IterateContext iterate = (IterateContext)ctx.GetAttribute(tag);

            if (iterate == null)
            {
                string propertyName = ((BaseTag)tag).Property;
                object collection;
                if (propertyName != null && propertyName.Length > 0)
                {
                    collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
                }
                else
                {
                    collection = parameterObject;
                }
                iterate = new IterateContext(collection);
                ctx.AddAttribute(tag, iterate);
            }
            if (iterate != null && iterate.HasNext)
            {
                return(BaseTagHandler.INCLUDE_BODY);
            }
            else
            {
                return(BaseTagHandler.SKIP_BODY);
            }
        }
Exemplo n.º 5
0
        public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            IterateContext attribute = (IterateContext)ctx.GetAttribute(tag);

            if (attribute == null)
            {
                object obj2;
                string property = ((BaseTag)tag).Property;
                if ((property != null) && (property.Length > 0))
                {
                    obj2 = ObjectProbe.GetMemberValue(parameterObject, property, base.AccessorFactory);
                }
                else
                {
                    obj2 = parameterObject;
                }
                attribute = new IterateContext(obj2);
                ctx.AddAttribute(tag, attribute);
            }
            if ((attribute != null) && attribute.HasNext)
            {
                return(1);
            }
            return(0);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            IterateContext iterate = (IterateContext)ctx.GetAttribute(tag);

            if (iterate == null)
            {
                string propertyName = ((BaseTag)tag).Property;
                object collection;
                if (!string.IsNullOrEmpty(propertyName))
                {
                    collection = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory);
                }
                else
                {
                    collection = parameterObject;
                }
                iterate = new IterateContext(collection);
                ctx.AddAttribute(tag, iterate);
            }
            if (iterate.HasNext)
            {
                return(INCLUDE_BODY);
            }
            return(SKIP_BODY);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
        /// in the keyProperty parameter.  The value at each key will be the value of the property specified
        /// in the valueProperty parameter.  If valueProperty is null, the entire result object will be entered.
        /// </summary>
        /// <param name="request">The request scope.</param>
        /// <param name="session">The session used to execute the statement</param>
        /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
        /// <param name="keyProperty">The property of the result object to be used as the key.</param>
        /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
        /// <param name="rowDelegate">A delegate called once per row in the QueryForMapWithRowDelegate method</param>
        /// <returns>A IDictionary of object containing the rows keyed by keyProperty.</returns>
        ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
        internal IDictionary <TKey, TValue> RunQueryForDictionary <TKey, TValue>(RequestScope request,
                                                                                 ISession session,
                                                                                 object parameterObject,
                                                                                 string keyProperty,
                                                                                 string valueProperty,
                                                                                 DictionaryRowDelegate <TKey, TValue> rowDelegate)
        {
            IDictionary <TKey, TValue> map = new Dictionary <TKey, TValue>();

            using (IDbCommand command = request.IDbCommand)
            {
                IDataReader reader = command.ExecuteReader();
                try
                {
                    if (rowDelegate == null)
                    {
                        while (reader.Read())
                        {
                            object obj   = resultStrategy.Process(request, ref reader, null);
                            TKey   key   = (TKey)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
                            TValue value = default(TValue);
                            if (valueProperty != null)
                            {
                                value = (TValue)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
                            }
                            else
                            {
                                value = (TValue)obj;
                            }
                            map.Add(key, value);
                        }
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            object obj   = resultStrategy.Process(request, ref reader, null);
                            TKey   key   = (TKey)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
                            TValue value = default(TValue);
                            if (valueProperty != null)
                            {
                                value = (TValue)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
                            }
                            else
                            {
                                value = (TValue)obj;
                            }
                            rowDelegate(key, value, parameterObject, map);
                        }
                    }
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }
                ExecuteDelayedLoad(request);
            }
            return(map);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="configurationScope">The scope of the configuration</param>
        override internal void Initialize(ConfigurationScope configurationScope)
        {
            // the propertyName attribute on the selectKey node is optional
            if (PropertyName.Length > 0)
            {
                // Id is equal to the parent <select> node's "id" attribute
                IMappedStatement insert = configurationScope.SqlMapper.GetMappedStatement(Id);

                Type insertParameterClass = insert.Statement.ParameterClass;

                // make sure the PropertyName is a valid settable property of the <insert> node's parameterClass
                if (insertParameterClass != null &&
                    ObjectProbe.IsSimpleType(insertParameterClass) == false)
                {
                    configurationScope.ErrorContext.MoreInfo = String.Format("Looking for settable property named '{0}' on type '{1}' for selectKey node of statement id '{2}'.",
                                                                             PropertyName,                         // 0
                                                                             insert.Statement.ParameterClass.Name, // 1
                                                                             Id);                                  // 2

                    // we expect this to throw an exception if the property cannot be found; GetSetter is
                    // called instead of HasWriteableProperty becuase we want the same wording for
                    // property not found exceptions; GetSetter and HasWritableProperty both use the
                    // same internal cache for looking up the ProperyInfo object
                    ReflectionInfo.GetInstance(insert.Statement.ParameterClass).GetSetter(PropertyName);
                }
            }

            base.Initialize(configurationScope);
        }
 public void Initialize(IScope scope, Type parameterClass)
 {
     if (this._directionAttribute.Length > 0)
     {
         this._direction = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), this._directionAttribute, true);
     }
     if ((!typeof(IDictionary).IsAssignableFrom(parameterClass) && (parameterClass != null)) && !scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterClass))
     {
         if (!this._isComplexMemberName)
         {
             this._getAccessor = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory.CreateGetAccessor(parameterClass, this._propertyName);
         }
         else
         {
             string name                = this._propertyName.Substring(this._propertyName.LastIndexOf('.') + 1);
             string memberName          = this._propertyName.Substring(0, this._propertyName.LastIndexOf('.'));
             Type   memberTypeForGetter = ObjectProbe.GetMemberTypeForGetter(parameterClass, memberName);
             this._getAccessor = scope.DataExchangeFactory.AccessorFactory.GetAccessorFactory.CreateGetAccessor(memberTypeForGetter, name);
         }
     }
     scope.ErrorContext.MoreInfo = "Check the parameter mapping typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation).";
     if (this.CallBackName.Length > 0)
     {
         try
         {
             ITypeHandlerCallback callback = (ITypeHandlerCallback)Activator.CreateInstance(scope.DataExchangeFactory.TypeHandlerFactory.GetType(this.CallBackName));
             this._typeHandler = new CustomTypeHandler(callback);
             return;
         }
         catch (Exception exception)
         {
             throw new ConfigurationException("Error occurred during custom type handler configuration.  Cause: " + exception.Message, exception);
         }
     }
     if (this.CLRType.Length == 0)
     {
         if ((this._getAccessor != null) && scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(this._getAccessor.MemberType))
         {
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(this._getAccessor.MemberType, this._dbType);
         }
         else
         {
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler();
         }
     }
     else
     {
         Type type = TypeUtils.ResolveType(this.CLRType);
         if (scope.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(type))
         {
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, this._dbType);
         }
         else
         {
             type = ObjectProbe.GetMemberTypeForGetter(type, this.PropertyName);
             this._typeHandler = scope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, this._dbType);
         }
     }
 }
 public override object GetData(ParameterProperty mapping, object parameterObject)
 {
     if (mapping.IsComplexMemberName)
     {
         return(ObjectProbe.GetMemberValue(parameterObject, mapping.PropertyName, base.DataExchangeFactory.AccessorFactory));
     }
     return(parameterObject);
 }
Exemplo n.º 11
0
 public override object GetData(ParameterProperty mapping, object parameterObject)
 {
     if (!mapping.IsComplexMemberName && (this._parameterClass == parameterObject.GetType()))
     {
         return(mapping.GetAccessor.Get(parameterObject));
     }
     return(ObjectProbe.GetMemberValue(parameterObject, mapping.PropertyName, base.DataExchangeFactory.AccessorFactory));
 }
 public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
 {
     if (parameterObject == null)
     {
         return(false);
     }
     return(ObjectProbe.HasReadableProperty(parameterObject, ((BaseTag)tag).Property));
 }
Exemplo n.º 13
0
        public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader)
        {
            IList  list = null;
            object obj2 = ObjectProbe.GetMemberValue(target, mapping.PropertyName, request.DataExchangeFactory.AccessorFactory);

            if (obj2 == null)
            {
                obj2 = mapping.ListFactory.CreateInstance(null);
                mapping.SetAccessor.Set(target, obj2);
            }
            list = (IList)obj2;
            object     sKIP = null;
            IResultMap map  = mapping.NestedResultMap.ResolveSubMap(reader);

            if (map.GroupByProperties.Count > 0)
            {
                string      key        = base.GetUniqueKey(map, request, reader);
                IDictionary uniqueKeys = request.GetUniqueKeys(map);
                if ((uniqueKeys != null) && uniqueKeys.Contains(key))
                {
                    sKIP = uniqueKeys[key];
                    if (sKIP != null)
                    {
                        for (int i = 0; i < map.Properties.Count; i++)
                        {
                            ResultProperty property = map.Properties[i];
                            if (property.PropertyStrategy is GroupByStrategy)
                            {
                                property.PropertyStrategy.Set(request, map, property, ref sKIP, reader, null);
                            }
                        }
                    }
                    sKIP = BaseStrategy.SKIP;
                }
                else if (((key == null) || (uniqueKeys == null)) || !uniqueKeys.Contains(key))
                {
                    sKIP = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
                    if (uniqueKeys == null)
                    {
                        uniqueKeys = new Hashtable();
                        request.SetUniqueKeys(map, uniqueKeys);
                    }
                    uniqueKeys[key] = sKIP;
                }
            }
            else
            {
                sKIP = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
            }
            if ((sKIP != null) && (sKIP != BaseStrategy.SKIP))
            {
                list.Add(sKIP);
            }
            return(sKIP);
        }
Exemplo n.º 14
0
        internal IDictionary RunQueryForMap(RequestScope request, ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
        {
            IDictionary dictionary = new Hashtable();

            using (IDbCommand command = request.IDbCommand)
            {
                IDataReader reader = command.ExecuteReader();
                try
                {
                    object obj5;
                    if (rowDelegate != null)
                    {
                        goto Label_00C4;
                    }
                    while (reader.Read())
                    {
                        object obj2 = this._resultStrategy.Process(request, ref reader, null);
                        object obj3 = ObjectProbe.GetMemberValue(obj2, keyProperty, request.DataExchangeFactory.AccessorFactory);
                        object obj4 = obj2;
                        if (valueProperty != null)
                        {
                            obj4 = ObjectProbe.GetMemberValue(obj2, valueProperty, request.DataExchangeFactory.AccessorFactory);
                        }
                        dictionary.Add(obj3, obj4);
                    }
                    goto Label_00E0;
Label_0072:
                    obj5 = this._resultStrategy.Process(request, ref reader, null);
                    object key  = ObjectProbe.GetMemberValue(obj5, keyProperty, request.DataExchangeFactory.AccessorFactory);
                    object obj7 = obj5;
                    if (valueProperty != null)
                    {
                        obj7 = ObjectProbe.GetMemberValue(obj5, valueProperty, request.DataExchangeFactory.AccessorFactory);
                    }
                    rowDelegate(key, obj7, parameterObject, dictionary);
Label_00C4:
                    if (reader.Read())
                    {
                        goto Label_0072;
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }
Label_00E0:
                this.ExecutePostSelect(request);
            }
            return(dictionary);
        }
Exemplo n.º 15
0
        private void CreateParametersForTextCommand()
        {
            string str = string.Empty;
            string parameterDbTypeProperty         = this._session.DataSource.DbProvider.ParameterDbTypeProperty;
            Type   parameterDbType                 = this._session.DataSource.DbProvider.ParameterDbType;
            ParameterPropertyCollection properties = null;

            if (this._session.DataSource.DbProvider.UsePositionalParameters)
            {
                properties = this._request.ParameterMap.Properties;
            }
            else
            {
                properties = this._request.ParameterMap.PropertiesList;
            }
            this._preparedStatement.DbParameters = new IDbDataParameter[properties.Count];
            for (int i = 0; i < properties.Count; i++)
            {
                ParameterProperty key = properties[i];
                if (this._session.DataSource.DbProvider.UseParameterPrefixInParameter)
                {
                    str = this._parameterPrefix + "param" + i;
                }
                else
                {
                    str = "param" + i;
                }
                IDbDataParameter parameter = this._session.CreateDataParameter();
                if ((key.DbType != null) && (key.DbType.Length > 0))
                {
                    object memberValue = Enum.Parse(parameterDbType, key.DbType, true);
                    ObjectProbe.SetMemberValue(parameter, parameterDbTypeProperty, memberValue, this._request.DataExchangeFactory.ObjectFactory, this._request.DataExchangeFactory.AccessorFactory);
                }
                if (this._session.DataSource.DbProvider.SetDbParameterSize && (key.Size != -1))
                {
                    parameter.Size = key.Size;
                }
                if (this._session.DataSource.DbProvider.SetDbParameterPrecision)
                {
                    parameter.Precision = key.Precision;
                }
                if (this._session.DataSource.DbProvider.SetDbParameterScale)
                {
                    parameter.Scale = key.Scale;
                }
                parameter.Direction     = key.Direction;
                parameter.ParameterName = str;
                this._preparedStatement.DbParametersName.Add(key.PropertyName);
                this._preparedStatement.DbParameters[i] = parameter;
                if (!this._session.DataSource.DbProvider.UsePositionalParameters)
                {
                    this._propertyDbParameterMap.Add(key, parameter);
                }
            }
        }
Exemplo n.º 16
0
 private void RetrieveOutputParameters(RequestScope request, ISqlMapSession session, IDbCommand command, object result)
 {
     if (request.ParameterMap != null)
     {
         int count = request.ParameterMap.PropertiesList.Count;
         for (int i = 0; i < count; i++)
         {
             ParameterProperty mapping = request.ParameterMap.GetProperty(i);
             if ((mapping.Direction == ParameterDirection.Output) || (mapping.Direction == ParameterDirection.InputOutput))
             {
                 string columnName = string.Empty;
                 if (!session.DataSource.DbProvider.UseParameterPrefixInParameter)
                 {
                     columnName = mapping.ColumnName;
                 }
                 else
                 {
                     columnName = session.DataSource.DbProvider.ParameterPrefix + mapping.ColumnName;
                 }
                 if (mapping.TypeHandler == null)
                 {
                     lock (mapping)
                     {
                         if (mapping.TypeHandler == null)
                         {
                             Type memberTypeForGetter = ObjectProbe.GetMemberTypeForGetter(result, mapping.PropertyName);
                             mapping.TypeHandler = request.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(memberTypeForGetter);
                         }
                     }
                 }
                 IDataParameter parameter     = (IDataParameter)command.Parameters[columnName];
                 object         obj2          = parameter.Value;
                 object         dataBaseValue = null;
                 if (obj2 == DBNull.Value)
                 {
                     if (mapping.HasNullValue)
                     {
                         dataBaseValue = mapping.TypeHandler.ValueOf(mapping.GetAccessor.MemberType, mapping.NullValue);
                     }
                     else
                     {
                         dataBaseValue = mapping.TypeHandler.NullValue;
                     }
                 }
                 else
                 {
                     dataBaseValue = mapping.TypeHandler.GetDataBaseValue(parameter.Value, result.GetType());
                 }
                 request.IsRowDataFound = request.IsRowDataFound || (dataBaseValue != null);
                 request.ParameterMap.SetOutputParameter(ref result, mapping, dataBaseValue);
             }
         }
     }
 }
Exemplo n.º 17
0
 public override void SetData(ref object target, ParameterProperty mapping, object dataBaseValue)
 {
     if (mapping.IsComplexMemberName)
     {
         ObjectProbe.SetMemberValue(target, mapping.PropertyName, dataBaseValue, base.DataExchangeFactory.ObjectFactory, base.DataExchangeFactory.AccessorFactory);
     }
     else
     {
         base.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(this._parameterClass, mapping.PropertyName).Set(target, dataBaseValue);
     }
 }
        private string ProcessDynamicElements(object parameterObject)
        {
            StringTokenizer tokenizer  = new StringTokenizer(this._simpleSqlStatement, "$", true);
            StringBuilder   builder    = new StringBuilder();
            string          current    = null;
            string          str2       = null;
            IEnumerator     enumerator = tokenizer.GetEnumerator();

            while (enumerator.MoveNext())
            {
                current = (string)enumerator.Current;
                if ("$".Equals(str2))
                {
                    if ("$".Equals(current))
                    {
                        builder.Append("$");
                        current = null;
                    }
                    else
                    {
                        object obj2 = null;
                        if (parameterObject != null)
                        {
                            if (this._dataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterObject.GetType()))
                            {
                                obj2 = parameterObject;
                            }
                            else
                            {
                                obj2 = ObjectProbe.GetMemberValue(parameterObject, current, this._dataExchangeFactory.AccessorFactory);
                            }
                        }
                        if (obj2 != null)
                        {
                            builder.Append(obj2.ToString());
                        }
                        enumerator.MoveNext();
                        current = (string)enumerator.Current;
                        if (!"$".Equals(current))
                        {
                            throw new DataMapperException("Unterminated dynamic element in sql (" + this._simpleSqlStatement + ").");
                        }
                        current = null;
                    }
                }
                else if (!"$".Equals(current))
                {
                    builder.Append(current);
                }
                str2 = current;
            }
            return(builder.ToString());
        }
Exemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="sqlTag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        protected long Compare(SqlTagContext ctx, SqlTag sqlTag, object parameterObject)
        {
            var    tag                 = (Conditional)sqlTag;
            string propertyName        = tag.Property;
            string literal             = tag.Literal;
            string comparePropertyName = tag.CompareProperty;
            string compareValue        = tag.CompareValue;

            object value1 = null;
            Type   type   = null;

            if (propertyName != null && propertyName.Length > 0)
            {
                // check to see if we are a list
                //if (fpropertyName.StartsWith("["))
                //{

                //}

                value1 = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory);
                type   = value1.GetType();
            }
            else if (!String.IsNullOrEmpty(literal))
            {
                value1 = literal;
                type   = value1.GetType();
            }
            else
            {
                value1 = parameterObject;
                if (value1 != null)
                {
                    type = parameterObject.GetType();
                }
                else
                {
                    type = typeof(object);
                }
            }
            if (comparePropertyName != null && comparePropertyName.Length > 0)
            {
                object value2 = ObjectProbe.GetMemberValue(parameterObject, comparePropertyName, AccessorFactory);
                return(CompareValues(type, value1, value2));
            }
            else if (!String.IsNullOrEmpty(compareValue))
            {
                return(CompareValues(type, value1, compareValue));
            }
            else
            {
                throw new DataMapperException("Error comparing in conditional fragment.  Uknown 'compare to' values.");
            }
        }
Exemplo n.º 20
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)
 {
     if (parameterObject != null)
     {
         if (DataExchangeFactory.TypeHandlerFactory.IsSimpleType(parameterObject.GetType()))
         {
             return(parameterObject);
         }
         return(ObjectProbe.GetMemberValue(parameterObject, mapping.PropertyName, DataExchangeFactory.AccessorFactory));
     }
     return(null);
 }
        public ITypeHandler ResolveTypeHandler(Type clazz, string memberName, string clrType, string dbType, bool forSetter)
        {
            ITypeHandler typeHandler = null;

            if (clazz == null)
            {
                return(this.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler());
            }
            if (typeof(IDictionary).IsAssignableFrom(clazz))
            {
                if ((clrType == null) || (clrType.Length == 0))
                {
                    return(this.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler());
                }
                try
                {
                    Type type = TypeUtils.ResolveType(clrType);
                    return(this.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, dbType));
                }
                catch (Exception exception)
                {
                    throw new ConfigurationErrorsException("Error. Could not set TypeHandler.  Cause: " + exception.Message, exception);
                }
            }
            if (this.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(clazz, dbType) != null)
            {
                return(this.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(clazz, dbType));
            }
            if ((clrType == null) || (clrType.Length == 0))
            {
                Type memberTypeForSetter = null;
                if (forSetter)
                {
                    memberTypeForSetter = ObjectProbe.GetMemberTypeForSetter(clazz, memberName);
                }
                else
                {
                    memberTypeForSetter = ObjectProbe.GetMemberTypeForGetter(clazz, memberName);
                }
                return(this.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(memberTypeForSetter, dbType));
            }
            try
            {
                Type type3 = TypeUtils.ResolveType(clrType);
                typeHandler = this.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type3, dbType);
            }
            catch (Exception exception2)
            {
                throw new ConfigurationErrorsException("Error. Could not set TypeHandler.  Cause: " + exception2.Message, exception2);
            }
            return(typeHandler);
        }
        /// <summary>
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        /// <remarks>
        /// Updated By: Richard Beacroft
        /// Updated Date: 11\10\2013
        /// Description: Builds full property name and checks to see if the property is readable.
        /// Not sure why it doesn't also cater for class Fields?
        /// </remarks>
        public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            if (parameterObject == null)
            {
                return(false);
            }

            var baseTag = (BaseTag)tag;
            // build property full name from property name - specifically handles references to current iterate item, i.e. "[]."
            var propertyFullName = ctx.ReplaceIterateCurrentProperty(baseTag);

            return(ObjectProbe.HasReadableProperty(parameterObject, propertyFullName));
        }
 internal override void Initialize(ConfigurationScope configurationScope)
 {
     if (this.PropertyName.Length > 0)
     {
         IMappedStatement mappedStatement = configurationScope.SqlMapper.GetMappedStatement(base.Id);
         Type             parameterClass  = mappedStatement.Statement.ParameterClass;
         if ((parameterClass != null) && !ObjectProbe.IsSimpleType(parameterClass))
         {
             configurationScope.ErrorContext.MoreInfo = string.Format("Looking for settable property named '{0}' on type '{1}' for selectKey node of statement id '{2}'.", this.PropertyName, mappedStatement.Statement.ParameterClass.Name, base.Id);
             ReflectionInfo.GetInstance(mappedStatement.Statement.ParameterClass).GetSetter(this.PropertyName);
         }
     }
     base.Initialize(configurationScope);
 }
Exemplo n.º 24
0
        public virtual object ExecuteInsert(ISqlMapSession session, object parameterObject)
        {
            object       memberValue = null;
            SelectKey    selectKey   = null;
            RequestScope request     = this._statement.Sql.GetRequestScope(this, parameterObject, session);

            if (this._statement is Insert)
            {
                selectKey = ((Insert)this._statement).SelectKey;
            }
            if ((selectKey != null) && !selectKey.isAfter)
            {
                memberValue = this._sqlMap.GetMappedStatement(selectKey.Id).ExecuteQueryForObject(session, parameterObject);
                ObjectProbe.SetMemberValue(parameterObject, selectKey.PropertyName, memberValue, request.DataExchangeFactory.ObjectFactory, request.DataExchangeFactory.AccessorFactory);
            }
            this._preparedCommand.Create(request, session, this.Statement, parameterObject);
            using (IDbCommand command = request.IDbCommand)
            {
                if (this._statement is Insert)
                {
                    command.ExecuteNonQuery();
                }
                else if (((this._statement is Procedure) && (this._statement.ResultClass != null)) && this._sqlMap.TypeHandlerFactory.IsSimpleType(this._statement.ResultClass))
                {
                    IDataParameter parameter = command.CreateParameter();
                    parameter.Direction = ParameterDirection.ReturnValue;
                    command.Parameters.Add(parameter);
                    command.ExecuteNonQuery();
                    memberValue = parameter.Value;
                    memberValue = this._sqlMap.TypeHandlerFactory.GetTypeHandler(this._statement.ResultClass).GetDataBaseValue(memberValue, this._statement.ResultClass);
                }
                else
                {
                    memberValue = command.ExecuteScalar();
                    if ((this._statement.ResultClass != null) && this._sqlMap.TypeHandlerFactory.IsSimpleType(this._statement.ResultClass))
                    {
                        memberValue = this._sqlMap.TypeHandlerFactory.GetTypeHandler(this._statement.ResultClass).GetDataBaseValue(memberValue, this._statement.ResultClass);
                    }
                }
                if ((selectKey != null) && selectKey.isAfter)
                {
                    memberValue = this._sqlMap.GetMappedStatement(selectKey.Id).ExecuteQueryForObject(session, parameterObject);
                    ObjectProbe.SetMemberValue(parameterObject, selectKey.PropertyName, memberValue, request.DataExchangeFactory.ObjectFactory, request.DataExchangeFactory.AccessorFactory);
                }
                this.RetrieveOutputParameters(request, session, command, parameterObject);
            }
            this.RaiseExecuteEvent();
            return(memberValue);
        }
Exemplo n.º 25
0
        protected object GetBindValue(SqlTagContext ctx, string bindName, object parameterObject)
        {
            var bindingExpression = ctx.GetBindExpression(bindName);

            if (bindingExpression == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(bindingExpression.FullPropertyName))
            {
                return(bindingExpression.Value);
            }

            return(ObjectProbe.GetMemberValue(parameterObject, bindingExpression.FullPropertyName, AccessorFactory));
        }
Exemplo n.º 26
0
        public override void SetData(ref object target, ResultProperty mapping, object dataBaseValue)
        {
            Type c = target.GetType();

            if (((c != this._parameterClass) && !c.IsSubclassOf(this._parameterClass)) && !this._parameterClass.IsAssignableFrom(c))
            {
                throw new ArgumentException(string.Concat(new object[] { "Could not set value in class '", target.GetType(), "' for property '", mapping.PropertyName, "' of type '", mapping.MemberType, "'" }));
            }
            if (mapping.IsComplexMemberName)
            {
                ObjectProbe.SetMemberValue(target, mapping.PropertyName, dataBaseValue, base.DataExchangeFactory.ObjectFactory, base.DataExchangeFactory.AccessorFactory);
            }
            else
            {
                mapping.SetAccessor.Set(target, dataBaseValue);
            }
        }
Exemplo n.º 27
0
        public object GetMemberValue(SqlTagContext ctx, BaseTag tag, string propertyName, object parameterObject)
        {
            var iteratorContext = FindParentIteratorContext(ctx, tag);

            if (iteratorContext != null)
            {
                var indexOfIndexer = propertyName.IndexOf(ReflectionMapper.THIS_ENUMERATOR_PLACEHOLDER);

                if (indexOfIndexer == 0)
                {
                    parameterObject = iteratorContext.Current;
                    propertyName    = propertyName.Substring(indexOfIndexer + ReflectionMapper.THIS_ENUMERATOR_PLACEHOLDER.Length);
                }
            }

            return(ObjectProbe.GetMemberValue(parameterObject, propertyName, _accessorFactory));
        }
Exemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <returns></returns>
        public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            if (parameterObject == null)
            {
                return(true);
            }
            string propertyName = ((BaseTag)tag).Property;
            object value;

            if (!string.IsNullOrEmpty(propertyName))
            {
                value = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory);
            }
            else
            {
                value = parameterObject;
            }
            return(value == null);
        }
        /// <summary>
        /// Sets the value to the result property.
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="target"></param>
        /// <param name="dataBaseValue"></param>
        public override void SetData(ref object target, ResultProperty mapping, object dataBaseValue)
        {
            Type targetType = target.GetType();

            if ((targetType != _parameterClass) &&
                !targetType.IsSubclassOf(_parameterClass))
            {
                throw new ArgumentException("Could not set value of type '" + target.GetType() + "' in property '" + mapping.PropertyName + "' of type '" + _parameterClass + "'");
            }
            if (mapping.IsComplexMemberName)
            {
                ObjectProbe.SetMemberValue(target, mapping.PropertyName, dataBaseValue,
                                           this.DataExchangeFactory.ObjectFactory,
                                           this.DataExchangeFactory.AccessorFactory);
            }
            else
            {
                mapping.SetAccessor.Set(target, dataBaseValue);
            }
        }
        public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject)
        {
            object obj2;

            if (parameterObject == null)
            {
                return(true);
            }
            string property = ((BaseTag)tag).Property;

            if ((property != null) && (property.Length > 0))
            {
                obj2 = ObjectProbe.GetMemberValue(parameterObject, property, base.AccessorFactory);
            }
            else
            {
                obj2 = parameterObject;
            }
            return(obj2 == null);
        }