Ejemplo n.º 1
0
        public void ExtractParameter(Context.Infrastructure.AdoExecutorContext context)
        {
            var parameters = (IDictionary <string, object>)context.Parameters;

            foreach (var parameter in parameters)
            {
                if (string.IsNullOrEmpty(parameter.Key))
                {
                    throw new AdoExecutorException("Dictionary item key cannot be null or empty.");
                }

                if (parameter.Value == null)
                {
                    throw new AdoExecutorException("Dictionary item value cannot be null.");
                }

                var parameterType = parameter.Value.GetType();

                if (!_sqlPrimitiveDataTypes.IsSqlPrimitiveType(parameterType))
                {
                    throw new AdoExecutorException("Array item must be sql primitive type.");
                }

                IDbDataParameter dataParameter = context.Configuration.DataObjectFactory.CreateDataParameter();
                dataParameter.ParameterName = parameter.Key;
                dataParameter.Value         = parameter.Value;

                context.Command.Parameters.Add(dataParameter);
            }
        }
Ejemplo n.º 2
0
        public void ExtractParameter(Context.Infrastructure.AdoExecutorContext context)
        {
            var parameters = (IEnumerable)context.Parameters;
            int counter    = 0;

            foreach (object parameter in parameters)
            {
                if (parameter == null)
                {
                    throw new AdoExecutorException("Array item cannot be null.");
                }

                var parameterType = parameter.GetType();

                if (!_sqlPrimitiveDataTypes.IsSqlPrimitiveType(parameterType))
                {
                    throw new AdoExecutorException("Array item must be sql primitive type.");
                }

                IDbDataParameter dataParameter = context.Configuration.DataObjectFactory.CreateDataParameter();
                dataParameter.ParameterName = counter++.ToString();
                dataParameter.Value         = parameter;

                context.Command.Parameters.Add(dataParameter);
            }
        }
Ejemplo n.º 3
0
        public void ExtractParameter(Context.Infrastructure.AdoExecutorContext context)
        {
            PropertyInfo[] parametersPublicProperies =
                context.ParametersType.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (PropertyInfo propertyInfo in parametersPublicProperies)
            {
                if (!_sqlPrimitiveDataTypes.IsSqlPrimitiveType(propertyInfo.PropertyType))
                {
                    throw new AdoExecutorException("Object property must be sql primitive type.");
                }

                var sqlNameAttribute = Attribute.GetCustomAttribute(propertyInfo, typeof(SqlNameAttribute)) as SqlNameAttribute;

                IDbDataParameter dataParameter = context.Configuration.DataObjectFactory.CreateDataParameter();
                dataParameter.ParameterName = sqlNameAttribute != null ? sqlNameAttribute.Name : propertyInfo.Name;
                dataParameter.Value         = propertyInfo.GetValue(context.Parameters, null) ?? DBNull.Value;

                if (_sqlPrimitiveDataTypes.IsNull(dataParameter.Value))
                {
                    dataParameter.DbType = _sqlPrimitiveDataTypes.ConvertTypeToDbType(propertyInfo.PropertyType);
                }

                context.Command.Parameters.Add(dataParameter);
            }
        }
Ejemplo n.º 4
0
        public bool CanProcess(Context.Infrastructure.AdoExecutorContext context)
        {
            if (_sqlPrimitiveDataTypes.IsSqlPrimitiveType(context.ParametersType))
            {
                return(false);
            }

            return(context.Parameters is IEnumerable);
        }
Ejemplo n.º 5
0
 public void OnEntry(Context.Infrastructure.AdoExecutorContext context)
 {
     foreach (IInterceptor interceptor in _configuration.Interceptors)
     {
         try
         {
             interceptor.OnEntry(context);
         }
         catch
         {
             //Interceptors shoud do not affect to query execution flow
         }
     }
 }
Ejemplo n.º 6
0
        public bool CanProcess(Context.Infrastructure.AdoExecutorContext context)
        {
            if (context.Parameters is SpecifiedParameter)
            {
                return(true);
            }

            if (context.Parameters is IEnumerable <SpecifiedParameter> )
            {
                return(true);
            }

            return(false);
        }
        public void ExtractParameter(Context.Infrastructure.AdoExecutorContext context)
        {
            var parameters = (DataTable)context.Parameters;

            if (parameters.Rows.Count != 1)
            {
                throw new AdoExecutorException("Table should has exacly one row.");
            }

            foreach (DataColumn column in parameters.Columns)
            {
                IDbDataParameter dataParameter = context.Configuration.DataObjectFactory.CreateDataParameter();
                dataParameter.ParameterName = column.ColumnName;
                dataParameter.Value         = parameters.Rows[0][column] ?? DBNull.Value;

                context.Command.Parameters.Add(dataParameter);
            }
        }
        public void ExtractParameter(Context.Infrastructure.AdoExecutorContext context)
        {
            if (context.Parameters == null)
            {
                return;
            }

            foreach (IParameterExtractor parameterExtractor in _configuration.ParameterExtractors)
            {
                if (parameterExtractor.CanProcess(context))
                {
                    parameterExtractor.ExtractParameter(context);
                    return;
                }
            }

            throw new AdoExecutorException(string.Format("Not found parameter extractor for type: {0}", context.ParametersType));
        }
Ejemplo n.º 9
0
        public void ExtractParameter(Context.Infrastructure.AdoExecutorContext context)
        {
            var specifiedParameters = context.Parameters as IEnumerable <SpecifiedParameter>;

            if (specifiedParameters != null)
            {
                var parameters = specifiedParameters;

                foreach (SpecifiedParameter specifiedParameter in parameters)
                {
                    AddParameter(context, specifiedParameter);
                }
            }
            else
            {
                var specifiedParameter = (SpecifiedParameter)context.Parameters;
                AddParameter(context, specifiedParameter);
            }
        }
Ejemplo n.º 10
0
        private void AddParameter(Context.Infrastructure.AdoExecutorContext context, SpecifiedParameter parameter)
        {
            IDbDataParameter dataParameter = context.Configuration.DataObjectFactory.CreateDataParameter();

            dataParameter.ParameterName = parameter.ParameterName;
            dataParameter.Value         = parameter.Value ?? DBNull.Value;

            if (parameter.DbType.HasValue)
            {
                dataParameter.DbType = parameter.DbType.Value;
            }

            if (parameter.Direction.HasValue)
            {
                dataParameter.Direction = parameter.Direction.Value;
            }

            if (parameter.Precision.HasValue)
            {
                dataParameter.Precision = parameter.Precision.Value;
            }

            if (parameter.Scale.HasValue)
            {
                dataParameter.Scale = parameter.Scale.Value;
            }

            if (parameter.Size.HasValue)
            {
                dataParameter.Size = parameter.Size.Value;
            }

            parameter.SetParameter(dataParameter);

            context.Command.Parameters.Add(dataParameter);
        }
 public bool CanProcess(Context.Infrastructure.AdoExecutorContext context)
 {
     return(context.ParametersType == typeof(DataTable));
 }
Ejemplo n.º 12
0
 public bool CanProcess(Context.Infrastructure.AdoExecutorContext context)
 {
     return(context.Parameters is IDictionary <string, object>);
 }