Пример #1
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;
			} 
			else 
			{
				string propertyName = ((BaseTag)tag).Property;
				object value = null;
				if (propertyName != null && propertyName.Length>0) 
				{
					value = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
				} 
				else 
				{
					value = parameterObject;
				}
				if (value is ICollection) 
				{
					return ((value == null) || (((ICollection) value).Count< 1));
				} 
				else if (value != null && typeof(Array).IsAssignableFrom(value.GetType())) //value.GetType().IsArray
				{
					return ((Array) value).GetLength(0) == 0;
				}
				else 
				{
					return ((value == null) || (System.Convert.ToString(value).Equals("")));
				}
			}
		}
Пример #2
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 (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;
			}
		}
Пример #3
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) 
		{
			ctx.FirstNonDynamicTagWithPrepend = null ;
			if (tag.IsPrependAvailable) 
			{
				ctx.IsOverridePrepend = true;
			}
			return BaseTagHandler.INCLUDE_BODY;
		}
Пример #4
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) 
		{
			if (IsCondition(ctx, tag, parameterObject)) 
			{
				return BaseTagHandler.INCLUDE_BODY;
			} 
			else 
			{
				return BaseTagHandler.SKIP_BODY;
			}
		}
        /// <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 false;
			} 
			else 
			{
				return ObjectProbe.HasReadableProperty(parameterObject, ((BaseTag)tag).Property);
			}		
		}
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="parameterObject"></param>
        /// <param name="bodyContent"></param>
        /// <returns></returns>
        public override int DoEndFragment(SqlTagContext ctx, SqlTag tag,
                                          object parameterObject, StringBuilder bodyContent)
        {
            IterateContext iterate = (IterateContext)ctx.GetAttribute(tag);

            if (iterate.MoveNext())
            {
                string propertyName = ((BaseTag)tag).Property;
                if (propertyName == null)
                {
                    propertyName = "";
                }

                string find    = propertyName + "[]";
                string replace = propertyName + "[" + iterate.Index + "]";                //Parameter-index-Dynamic
                Replace(bodyContent, find, replace);

                if (iterate.IsFirst)
                {
                    string open = ((Iterate)tag).Open;
                    if (open != null)
                    {
                        bodyContent.Insert(0, open);
                        bodyContent.Insert(0, ' ');
                    }
                }
                if (!iterate.IsLast)
                {
                    string conjunction = ((Iterate)tag).Conjunction;
                    if (conjunction != null)
                    {
                        bodyContent.Append(conjunction);
                        bodyContent.Append(' ');
                    }
                }
                if (iterate.IsLast)
                {
                    string close = ((Iterate)tag).Close;
                    if (close != null)
                    {
                        bodyContent.Append(close);
                    }
                }

                return(BaseTagHandler.REPEAT_BODY);
            }
            else
            {
                return(BaseTagHandler.INCLUDE_BODY);
            }
        }
        /// <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)
        {
            Conditional tag                 = (Conditional)sqlTag;
            string      propertyName        = tag.Property;
            string      comparePropertyName = tag.CompareProperty;
            string      compareValue        = tag.CompareValue;

            object value1 = null;
            Type   type   = null;

            if (propertyName != null && propertyName.Length > 0)
            {
                value1 = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
                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, this.AccessorFactory);
                return(CompareValues(type, value1, value2));
            }
            else if (compareValue != null && compareValue != "")
            {
                return(CompareValues(type, value1, compareValue));
            }
            else
            {
                throw new DataMapperException("Error comparing in conditional fragment.  Uknown 'compare to' values.");
            }
        }
Пример #8
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);
     }
     else
     {
         string propertyName = ((BaseTag)tag).Property;
         object value;
         if (propertyName != null && propertyName.Length > 0)
         {
             value = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
         }
         else
         {
             value = parameterObject;
         }
         return(value == null);
     }
 }
Пример #9
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;
			} 
			else 
			{
				string propertyName = ((BaseTag)tag).Property;
				object value;
				if (propertyName != null && propertyName.Length>0 ) 
				{
					value = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
				} 
				else 
				{
					value = parameterObject;
				}
				return (value == null);
			}		
		}
Пример #10
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)
		{
			return (this.Compare(ctx, tag, parameterObject) == 0);
		}
Пример #11
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)
 {
     return(this.Compare(ctx, tag, parameterObject) == 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)
 {
     return(!base.IsCondition(ctx, tag, parameterObject));
 }
Пример #13
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)
        {
            long x = this.Compare(ctx, tag, parameterObject);

            return((x <= 0) && (x != ConditionalTagHandler.NOT_COMPARABLE));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="tag"></param>
 /// <param name="parameterObject"></param>
 /// <returns></returns>
 public abstract bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject);
 /// <summary>
 ///
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="tag"></param>
 /// <param name="parameterObject"></param>
 /// <param name="bodyContent"></param>
 /// <returns></returns>
 public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject, StringBuilder bodyContent)
 {
     return(BaseTagHandler.INCLUDE_BODY);
 }
Пример #16
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)
		{
			return !base.IsCondition(ctx, tag, parameterObject);
		}
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="tag"></param>
 /// <param name="parameterObject"></param>
 /// <returns></returns>
 public virtual int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject)
 {
     return(BaseTagHandler.INCLUDE_BODY);
 }
Пример #18
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <param name="bodyContent"></param>
		/// <returns></returns>
		public virtual int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) 
		{
			return BaseTagHandler.INCLUDE_BODY;
		}
Пример #19
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="request"></param>
		/// <param name="ctx"></param>
		/// <param name="parameterObject"></param>
		/// <param name="localChildren"></param>
		private void ProcessBodyChildren(RequestScope request, SqlTagContext ctx, 
			object parameterObject, IList localChildren) 
		{
			StringBuilder buffer = ctx.GetWriter();
			ProcessBodyChildren(request, ctx, parameterObject, localChildren.GetEnumerator(), buffer);
		}
Пример #20
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <param name="bodyContent"></param>
		public virtual void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) 
		{
			if (tag.IsPrependAvailable) 
			{
				if (bodyContent.ToString().Trim().Length > 0) 
				{
					if (ctx.IsOverridePrepend && tag == ctx.FirstNonDynamicTagWithPrepend) 
					{
						ctx.IsOverridePrepend = false;
					} 
					else 
					{
						bodyContent.Insert(0, tag.Prepend);
					}
				} 
				else 
				{
					if (ctx.FirstNonDynamicTagWithPrepend != null) 
					{
						ctx.FirstNonDynamicTagWithPrepend = null;
						ctx.IsOverridePrepend =true;
					}
				}
			}
		}
Пример #21
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <param name="bodyContent"></param>
		/// <returns></returns>
		public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, 
			object parameterObject, StringBuilder bodyContent) 
		{
			IterateContext iterate = (IterateContext) ctx.GetAttribute(tag);

			if (iterate.MoveNext()) 
			{
				string propertyName = ((BaseTag)tag).Property;
				if (propertyName == null) 
				{
					propertyName = "";
				}

				string find = propertyName + "[]";
				string replace = propertyName + "[" + iterate.Index + "]";//Parameter-index-Dynamic
				Replace(bodyContent, find, replace);

				if (iterate.IsFirst) 
				{
					string open = ((Iterate)tag).Open;
					if (open != null) 
					{
						bodyContent.Insert(0,open);
						bodyContent.Insert(0,' ');
					}
				}
				if (!iterate.IsLast) 
				{
					string conjunction = ((Iterate)tag).Conjunction;
					if (conjunction != null) 
					{
						bodyContent.Append(conjunction);
						bodyContent.Append(' ');
					}
				}
				if (iterate.IsLast) 
				{
					string close = ((Iterate)tag).Close;
					if (close != null) 
					{
						bodyContent.Append(close);
					}
				}

				return BaseTagHandler.REPEAT_BODY;
			} 
			else 
			{
				return BaseTagHandler.INCLUDE_BODY;
			}
		}
Пример #22
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public abstract bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject);
Пример #23
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="request"></param>
		/// <param name="ctx"></param>
		/// <param name="parameterObject"></param>
		/// <param name="localChildren"></param>
		/// <param name="buffer"></param>
		private void ProcessBodyChildren(RequestScope request, SqlTagContext ctx, 
			object parameterObject, IEnumerator localChildren, StringBuilder buffer) 
		{
			while (localChildren.MoveNext()) 
			{
				ISqlChild child = (ISqlChild) localChildren.Current;

				if (child is SqlText) 
				{
					SqlText sqlText = (SqlText) child;
					string sqlStatement = sqlText.Text;
					if (sqlText.IsWhiteSpace) 
					{
						buffer.Append(sqlStatement);
					} 
					else 
					{
//						if (SimpleDynamicSql.IsSimpleDynamicSql(sqlStatement)) 
//						{
//							sqlStatement = new SimpleDynamicSql(sqlStatement, _statement).GetSql(parameterObject);
//							SqlText newSqlText = _paramParser.ParseInlineParameterMap( null, sqlStatement );
//							sqlStatement = newSqlText.Text;
//							ParameterProperty[] mappings = newSqlText.Parameters;
//							if (mappings != null) 
//							{
//								for (int i = 0; i < mappings.Length; i++) 
//								{
//									ctx.AddParameterMapping(mappings[i]);
//								}
//							}
//						}
						// BODY OUT
						buffer.Append(" ");
						buffer.Append(sqlStatement);

						ParameterProperty[] parameters = sqlText.Parameters;
						if (parameters != null) 
						{
							int length = parameters.Length;
							for (int i = 0; i< length; i++) 
							{
								ctx.AddParameterMapping(parameters[i]);
							}
						}
					}
				} 
				else if (child is SqlTag) 
				{
					SqlTag tag = (SqlTag) child;
					ISqlTagHandler handler = tag.Handler;
					int response = BaseTagHandler.INCLUDE_BODY;

					do 
					{
						StringBuilder body = new StringBuilder();

						response = handler.DoStartFragment(ctx, tag, parameterObject);
						if (response != BaseTagHandler.SKIP_BODY) 
						{
							if (ctx.IsOverridePrepend
								&& ctx.FirstNonDynamicTagWithPrepend == null
								&& tag.IsPrependAvailable
								&& !(tag.Handler is DynamicTagHandler)) 
							{
								ctx.FirstNonDynamicTagWithPrepend = tag;
							}

							ProcessBodyChildren(request, ctx, parameterObject, tag.GetChildrenEnumerator(), body);
            
							response = handler.DoEndFragment(ctx, tag, parameterObject, body);
							handler.DoPrepend(ctx, tag, parameterObject, body);
							if (response != BaseTagHandler.SKIP_BODY) 
							{
								if (body.Length > 0) 
								{
									// BODY OUT

									if (handler.IsPostParseRequired) 
									{
										SqlText sqlText = _paramParser.ParseInlineParameterMap(request, null, body.ToString() );
										buffer.Append(sqlText.Text);
										ParameterProperty[] mappings = sqlText.Parameters;
										if (mappings != null) 
										{
											int length = mappings.Length;
											for (int i = 0; i< length; i++) 
											{
												ctx.AddParameterMapping(mappings[i]);
											}
										}
									} 
									else 
									{
										buffer.Append(" ");
										buffer.Append(body.ToString());
									}
									if (tag.IsPrependAvailable && tag == ctx.FirstNonDynamicTagWithPrepend) 
									{
										ctx.IsOverridePrepend = false;
									}
								}
							}
						}
					} 
					while (response == BaseTagHandler.REPEAT_BODY);
				}
			}
		}
Пример #24
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)
		{
			Conditional tag = (Conditional)sqlTag;
			string propertyName = tag.Property;
			string comparePropertyName = tag.CompareProperty;
			string compareValue = tag.CompareValue;

			object value1 = null;
			Type type = null;
			if (propertyName != null && propertyName.Length > 0) 
			{
				value1 = ObjectProbe.GetMemberValue(parameterObject, propertyName, this.AccessorFactory);
				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, this.AccessorFactory);
				return CompareValues(type, value1, value2);
			} 
			else if (compareValue != null && compareValue != "") 
			{
				return CompareValues(type, value1, compareValue);
			} 
			else 
			{
				throw new DataMapperException("Error comparing in conditional fragment.  Uknown 'compare to' values.");
			}
		}
Пример #25
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <param name="bodyContent"></param>
		public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) 
		{
			IterateContext iterate = (IterateContext) ctx.GetAttribute(tag);
			if (iterate.IsFirst) 
			{
				base.DoPrepend(ctx, tag, parameterObject, bodyContent);
			}
		}
Пример #26
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)
 {
     return(parameterObject != null);
 }
Пример #27
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ctx"></param>
		/// <param name="tag"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		public virtual int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject) 
		{
			return BaseTagHandler.INCLUDE_BODY;
		}
		/// <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)
		{
			return (parameterObject != null);
		}
		/// <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)
		{
			long x = this.Compare(ctx, tag, parameterObject);
			return ((x >= 0) && (x != ConditionalTagHandler.NOT_COMPARABLE));
		}
Пример #30
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="request"></param>
		/// <param name="parameterObject"></param>
		/// <returns></returns>
		private string Process(RequestScope request, object parameterObject) 
		{
			SqlTagContext ctx = new SqlTagContext();
			IList localChildren = _children;

			ProcessBodyChildren(request, ctx, parameterObject, localChildren);

			// Builds a 'dynamic' ParameterMap
            ParameterMap parameterMap = new ParameterMap(
                _statement.Id + "-InlineParameterMap",
                _statement.ParameterClass.FullName,
                string.Empty,
                _statement.ParameterClass,
                request.DataExchangeFactory.GetDataExchangeForClass(_statement.ParameterClass),
                _usePositionalParameters);

            //parameterMap.Id = _statement.Id + "-InlineParameterMap";
            //parameterMap.Initialize(_usePositionalParameters, request);
            //parameterMap.Class = _statement.ParameterClass;

			// Adds 'dynamic' ParameterProperty
			IList parameters = ctx.GetParameterMappings();
			int count = parameters.Count;
			for(int i=0;i<count;i++)
			{
                parameterMap.AddParameterProperty((ParameterProperty)parameters[i]);
			}
            request.ParameterMap = parameterMap;

			string dynSql = ctx.BodyText;

			// Processes $substitutions$ after DynamicSql
			if ( SimpleDynamicSql.IsSimpleDynamicSql(dynSql) ) 
			{
				dynSql = new SimpleDynamicSql(request, dynSql, _statement).GetSql(parameterObject);
			}
			return dynSql;
		}