public static string GetReflectedFullName(SqlTagContext ctx, BaseTag tag, string propertyName) { if (ctx == null) throw new ArgumentNullException("ctx"); if (tag == null) throw new ArgumentNullException("tag"); if (propertyName == null) throw new ArgumentNullException("propertyName"); var currentIteratorContext = ctx.GetAttribute(tag) as IterateContext; // is current tag an iterate? if (currentIteratorContext != null) { propertyName = String.Format("{0}[{1}]", propertyName, currentIteratorContext.Index); } var parentIteratorTag = FindParentIteratorTag(ctx, tag); // is current node a child of another iterate node? if (parentIteratorTag != null) return BuildReflectedFullName(ctx, parentIteratorTag, propertyName); return propertyName; }
public static string GetReflectedFullName(SqlTagContext ctx, SqlText sqlText, string propertyName) { if (ctx == null) throw new ArgumentNullException("ctx"); if (sqlText == null) throw new ArgumentNullException("sqlText"); if (propertyName == null) throw new ArgumentNullException("propertyName"); if (sqlText.Parent == null) return propertyName; if (sqlText.Parent is Iterate) return BuildReflectedFullName(ctx, (Iterate)sqlText.Parent, propertyName); if (sqlText.Parent is BaseTag) { var parentIteratorTag = FindParentIteratorTag(ctx, (BaseTag)sqlText.Parent); // is current node a child of another iterate node? if (parentIteratorTag != null) return BuildReflectedFullName(ctx, parentIteratorTag, propertyName); } return propertyName; }
public static bool ReplacePropertyIndexerWithFullName(SqlTagContext ctx, BaseTag tag, StringBuilder bodyContent) { if (ctx == null) throw new ArgumentNullException("ctx"); if (tag == null) throw new ArgumentNullException("tag"); if (bodyContent == null) throw new ArgumentNullException("bodyContent"); string propertyName = tag.Property; if (propertyName == null) propertyName = String.Empty; if (propertyName.StartsWith(THIS_ENUMERATOR_PLACEHOLDER)) { var builtPropertyName = GetReflectedFullName(ctx, tag, propertyName); var suffix = String.Empty; // if the property name is just the current item reference, then do not suffix the property name with a "." if (propertyName != THIS_ENUMERATOR_PLACEHOLDER) suffix = "."; StringHandler.Replace(bodyContent, THIS_ENUMERATOR_PLACEHOLDER, builtPropertyName + suffix); return true; } return false; }
/// <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 bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) { if (parameterObject == null) { return true; } var baseTag = ((BaseTag)tag); object value; if (!string.IsNullOrEmpty(baseTag.BindName)) { if (!string.IsNullOrEmpty(baseTag.Property)) throw new DataMapperException("Error comparing in conditional fragment. Please specify a \"bindName\" or \"property\", not both."); value = GetBindValue(ctx, baseTag.BindName, parameterObject); } else if (!string.IsNullOrEmpty(baseTag.Property)) { // changed to enable references to current iterate items to also be catered for. value = GetMemberPropertyValue(ctx, baseTag, parameterObject); } else { value = parameterObject; } return (value == 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) { if (parameterObject == null) { return false; } return ObjectProbe.HasReadableProperty(parameterObject, ((BaseTag)tag).Property); }
/// <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 INCLUDE_BODY; } return SKIP_BODY; }
/// <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 INCLUDE_BODY; }
public object GetMemberPropertyValue(SqlTagContext ctx, BaseTag tag, object parameterObject) { if (ctx == null) throw new ArgumentNullException("ctx"); if (tag == null) throw new ArgumentNullException("tag"); return GetMemberValue(ctx, tag, tag.Property, parameterObject); }
/// <summary> /// /// </summary> /// <param name="ctx"></param> /// <param name="tag"></param> /// <param name="parameterObject"></param> /// <param name="bodyContent"></param> /// <returns></returns> /// <remarks> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Enables property iterate item paths to be replaced with full property paths, which will later be reflected. /// </remarks> public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.IsCompleted) return INCLUDE_BODY; var iterateTag = ((Iterate)tag); var propertyName = iterateTag.Property; if (propertyName == null) propertyName = String.Empty; // build full reflection path if (!ReflectionMapper.ReplacePropertyIndexerWithFullName(ctx, iterateTag, bodyContent)) { string find = propertyName + ReflectionMapper.ENUMERATOR_PLACEHOLDER; string replace = propertyName + "[" + iterate.Index + "]"; //Parameter-index-Dynamic StringHandler.Replace(bodyContent, find, replace); } if (iterate.IsFirst) { if (iterateTag.Open != null) { bodyContent.Insert(0, ctx.ReplaceBindingVariables(iterateTag.Open)); bodyContent.Insert(0, ' '); } } if (iterate.IsLast) { if (iterateTag.Close != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Close)); } } else { if (iterateTag.Conjunction != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Conjunction)); bodyContent.Append(' '); } } if (iterate.HasNext) return REPEAT_BODY; iterate.IsCompleted = true; return INCLUDE_BODY; }
private IterateContext FindParentIteratorContext(SqlTagContext ctx, BaseTag tag) { if (tag.Parent is Iterate) return ctx.GetAttribute(tag.Parent) as IterateContext; var parentBaseTag = tag.Parent as BaseTag; if (tag.Parent == null || parentBaseTag == null) return null; return FindParentIteratorContext(ctx, parentBaseTag); }
/// <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)); }
/// <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); }
public DynamicSqlTextTokenHandler(SqlTagContext ctx, SqlText sqlText) { if (ctx == null) throw new ArgumentNullException("ctx"); if (sqlText == null) throw new ArgumentNullException("sqlText"); _ctx = ctx; _sqlText = sqlText; KeepSurroundingToken = true; }
/// <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(REPEAT_BODY); } return(INCLUDE_BODY); }
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)); }
/// <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 bindName = tag.BindName; string propertyName = tag.Property; string comparePropertyName = tag.CompareProperty; string compareValue = tag.CompareValue; object value1 = null; Type type = null; if (!string.IsNullOrEmpty(bindName)) { if (!string.IsNullOrEmpty(propertyName)) { throw new DataMapperException("Error comparing in conditional fragment. Please specify a \"bindName\" or \"property\", not both."); } value1 = GetBindValue(ctx, bindName, parameterObject); type = value1.GetType(); } else if (!string.IsNullOrEmpty(propertyName)) { value1 = GetMemberPropertyValue(ctx, tag, parameterObject); type = value1.GetType(); } else { value1 = parameterObject; if (value1 != null) { type = parameterObject.GetType(); } else { type = typeof(object); } } if (!string.IsNullOrEmpty(comparePropertyName)) { object value2 = GetMemberComparePropertyValue(ctx, tag, parameterObject); return(CompareValues(type, value1, value2)); } if (!string.IsNullOrEmpty(compareValue)) { return(CompareValues(type, value1, compareValue)); } throw new DataMapperException("Error comparing in conditional fragment. Unknown 'compare to' values."); }
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); }
/// <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> /// /// </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> /// /// </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); } var baseTag = ((BaseTag)tag); string bindName = baseTag.BindName; string propertyName = baseTag.Property; object value = null; if (!string.IsNullOrEmpty(bindName)) { if (!string.IsNullOrEmpty(propertyName)) { throw new DataMapperException("Error comparing in conditional fragment. Please specify a \"bindName\" or \"property\", not both."); } value = GetBindValue(ctx, bindName, parameterObject); } else if (!string.IsNullOrEmpty(propertyName)) { value = GetMemberPropertyValue(ctx, baseTag, parameterObject); //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> /// This class is responsible for getting the current iterate item object within an iteration. i.e. The property name starts with "[]." /// We do this by navigating up through the parent nodes to determine which of them are iterate elements. /// Once found we get the current iteration context item. /// If "[]." is not specified, the original approach is used of reflecting the parameterObject to the reflection path specified in the property /// </summary> /// <param name="ctx"></param> /// <param name="baseTag"></param> /// <param name="parameterObject"></param> /// <returns></returns> /// <remarks> /// Created By: Richard Beacroft /// Created Date: 11\10\2013 /// </remarks> protected object GetMemberPropertyValue(SqlTagContext ctx, BaseTag baseTag, object parameterObject) { if (String.IsNullOrEmpty(baseTag.Property)) { return(parameterObject); } var bindingReplacement = ctx.BuildPropertyBindingReplacements(baseTag).FirstOrDefault(); if (bindingReplacement != null) { if (String.IsNullOrEmpty(bindingReplacement.FullPropertyName)) { return(bindingReplacement.Value); } return(_tagPropertyProbe.GetMemberValue(ctx, baseTag, bindingReplacement.FullPropertyName, parameterObject)); } return(_tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject)); }
/// <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; } var baseTag = ((BaseTag)tag); string bindName = baseTag.BindName; string propertyName = baseTag.Property; object value = null; if (!string.IsNullOrEmpty(bindName)) { if (!string.IsNullOrEmpty(propertyName)) throw new DataMapperException("Error comparing in conditional fragment. Please specify a \"bindName\" or \"property\", not both."); value = GetBindValue(ctx, bindName, parameterObject); } else if (!string.IsNullOrEmpty(propertyName)) { value = GetMemberPropertyValue(ctx, baseTag, parameterObject); //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="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 (!string.IsNullOrEmpty(propertyName)) { value1 = ObjectProbe.GetMemberValue(parameterObject, propertyName, AccessorFactory); type = value1.GetType(); } else { value1 = parameterObject; if (value1 != null) { type = parameterObject.GetType(); } else { type = typeof(object); } } if (!string.IsNullOrEmpty(comparePropertyName)) { object value2 = ObjectProbe.GetMemberValue(parameterObject, comparePropertyName, AccessorFactory); return(CompareValues(type, value1, value2)); } if (!string.IsNullOrEmpty(compareValue)) { return(CompareValues(type, value1, compareValue)); } throw new DataMapperException("Error comparing in conditional fragment. Uknown 'compare to' values."); }
/// <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; }
/// <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 = Compare(ctx, tag, parameterObject); return ((x >= 0) && (x != NOT_COMPARABLE)); }
private static string BuildReflectedFullName(SqlTagContext ctx, Iterate parentIteratorTag, string propertyName) { if (parentIteratorTag != null) { var parentIteratorContext = ctx.GetAttribute(parentIteratorTag) as IterateContext; var indexOfIndexer = propertyName.IndexOf(THIS_ENUMERATOR_PLACEHOLDER); if (parentIteratorContext == null) return propertyName; if (indexOfIndexer == 0) { // the property name is a reflection name relative to the iterate. propertyName = propertyName.Substring(indexOfIndexer + THIS_ENUMERATOR_PLACEHOLDER.Length); propertyName = String.Format("{0}[{1}].{2}", parentIteratorTag.Property, parentIteratorContext.Index, propertyName); var parentOrParentIteratorTag = FindParentIteratorTag(ctx, parentIteratorTag); if (parentOrParentIteratorTag != null) return BuildReflectedFullName(ctx, parentOrParentIteratorTag, propertyName); } else if (propertyName.IndexOf(ENUMERATOR_PLACEHOLDER) > -1) { return propertyName + "[" + parentIteratorContext.Index + "]"; //Parameter-Index-Dynamic } } return propertyName; }
private static Iterate FindParentIteratorTag(SqlTagContext ctx, BaseTag tag) { if (tag.Parent is Iterate) return tag.Parent as Iterate; var parentBaseTag = tag.Parent as BaseTag; if (tag.Parent == null || parentBaseTag == null) return null; return FindParentIteratorTag(ctx, parentBaseTag); }
/// <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> /// Processes the body children. /// 最终的处理的语句结果在buffer中,也即ctx中的StringBuilder,处理的参数结果在ctx中的ArrayList中 /// </summary> /// <param name="request">The request.</param> /// <param name="ctx">The CTX.</param> /// <param name="parameterObject">The parameter object.</param> /// <param name="childEnumerator">The child enumerator.</param> /// <param name="buffer">The buffer.</param> private void ProcessBodyChildren( RequestScope request, SqlTagContext ctx, object parameterObject, IEnumerator<ISqlChild> childEnumerator, StringBuilder buffer) { while (childEnumerator.MoveNext()) { ISqlChild child = childEnumerator.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);//添加当前的SQL语句 //处理参数列表 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;//此处是DynamicTagHandler处理类 int response = BaseTagHandler.INCLUDE_BODY; do { StringBuilder body = new StringBuilder(); //返回INCLUDE_BODY,即1 此处为处理开头的情况准备 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; } //递归调用,当前SqlTag中处理后的SQL语句保存到了临时的body中 后面再加入到buffer中 ProcessBodyChildren(request, ctx, parameterObject, tag.GetChildrenEnumerator(), body); //处理结尾的片段部分 返回INCLUDE_BODY,1 response = handler.DoEndFragment(ctx, tag, parameterObject, body); //处理prepend属性节点的问题 handler.DoPrepend(ctx, tag, parameterObject, body); if (response != BaseTagHandler.SKIP_BODY) { if (body.Length > 0) { // BODY OUT if (handler.IsPostParseRequired) { //将body中的SQL语句分析参数和SQL语句到SqlText中 SqlText sqlText = InlineParameterMapParser.ParseInlineParameterMap(dataExchangeFactory, statement.Id, 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()); } //此处是判断SQL语句查询条件时的关键字开头问题 if (tag.IsPrependAvailable && tag == ctx.FirstNonDynamicTagWithPrepend) { ctx.IsOverridePrepend = false; } } } } } while (response == BaseTagHandler.REPEAT_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(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) { long x = Compare(ctx, tag, parameterObject); return((x < 0) && (x != NOT_COMPARABLE)); }
/// <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); }
/// <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 INCLUDE_BODY; }
/// <summary> /// 完成动态SQL语句中子语句的拼接 和 参数信息的取出 /// </summary> /// <param name="request"></param> /// <param name="parameterObject"></param> /// <returns></returns> private string Process(RequestScope request, object parameterObject) { SqlTagContext ctx = new SqlTagContext(); IList<ISqlChild> localChildren = children; ProcessBodyChildren(request, ctx, parameterObject, localChildren); #region 所有参数对应的属性类的集合信息放入到ParameterMap中 // Builds a 'dynamic' ParameterMap ParameterMap parameterMap = new ParameterMap( statement.Id + "-InlineParameterMap", statement.ParameterClass.FullName, string.Empty, statement.ParameterClass, dataExchangeFactory.GetDataExchangeForClass(null), usePositionalParameters); // 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; #endregion #region 完整的SQL语句 string dynSql = ctx.BodyText; if (statement is Procedure) { dynSql = dynSql.Replace(MARK_TOKEN, string.Empty).Replace(COMMA_TOKEN, string.Empty).Trim(); } // Processes $substitutions$ after DynamicSql if (SimpleDynamicSql.IsSimpleDynamicSql(dynSql)) { dynSql = new SimpleDynamicSql( dataExchangeFactory, dbHelperParameterCache, dynSql, statement).GetSql(parameterObject); } #endregion return dynSql; }
/// <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> /// <remarks> /// Updated By: Richard Beacroft /// Updated Date: 11\10\2013 /// Description: Enables property iterate item paths to be replaced with full property paths, which will later be reflected. /// </remarks> public override int DoEndFragment(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent) { IterateContext iterate = (IterateContext)ctx.GetAttribute(tag); if (iterate.IsCompleted) { return(INCLUDE_BODY); } var iterateTag = ((Iterate)tag); var propertyName = iterateTag.Property; if (propertyName == null) { propertyName = String.Empty; } // build full reflection path if (!ReflectionMapper.ReplacePropertyIndexerWithFullName(ctx, iterateTag, bodyContent)) { string find = propertyName + ReflectionMapper.ENUMERATOR_PLACEHOLDER; string replace = propertyName + "[" + iterate.Index + "]"; //Parameter-index-Dynamic StringHandler.Replace(bodyContent, find, replace); } if (iterate.IsFirst) { if (iterateTag.Open != null) { bodyContent.Insert(0, ctx.ReplaceBindingVariables(iterateTag.Open)); bodyContent.Insert(0, ' '); } } if (iterate.IsLast) { if (iterateTag.Close != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Close)); } } else { if (iterateTag.Conjunction != null) { bodyContent.Append(ctx.ReplaceBindingVariables(iterateTag.Conjunction)); bodyContent.Append(' '); } } if (iterate.HasNext) { return(REPEAT_BODY); } iterate.IsCompleted = true; return(INCLUDE_BODY); }
/// <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<ISqlChild> localChildren) { StringBuilder buffer = ctx.GetWriter(); ProcessBodyChildren(request, ctx, parameterObject, localChildren.GetEnumerator(), buffer); }
/// <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) { return(INCLUDE_BODY); }
/// <summary> /// This class is responsible for getting the current iterate item object within an iteration. i.e. The property name starts with "[]." /// We do this by navigating up through the parent nodes to determine which of them are iterate elements. /// Once found we get the current iteration context item. /// If "[]." is not specified, the original approach is used of reflecting the parameterObject to the reflection path specified in the property /// </summary> /// <param name="ctx"></param> /// <param name="baseTag"></param> /// <param name="parameterObject"></param> /// <returns></returns> /// <remarks> /// Created By: Richard Beacroft /// Created Date: 11\10\2013 /// </remarks> protected object GetMemberPropertyValue(SqlTagContext ctx, BaseTag baseTag, object parameterObject) { if (String.IsNullOrEmpty(baseTag.Property)) return parameterObject; var bindingReplacement = ctx.BuildPropertyBindingReplacements(baseTag).FirstOrDefault(); if (bindingReplacement != null) { if (String.IsNullOrEmpty(bindingReplacement.FullPropertyName)) return bindingReplacement.Value; return _tagPropertyProbe.GetMemberValue(ctx, baseTag, bindingReplacement.FullPropertyName, parameterObject); } return _tagPropertyProbe.GetMemberPropertyValue(ctx, baseTag, parameterObject); }
/// <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 (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)); }
/// <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(INCLUDE_BODY); }
/// <summary> /// 判断是否要向StringBuilder中添加prenpend属性值 /// </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; } } } }
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); }
/// <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 INCLUDE_BODY; }
/// <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(INCLUDE_BODY); }