Esempio n. 1
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);
                }
            }
        }
        /// <summary>
        /// Parse dynamic tags
        /// </summary>
        /// <param name="commandTextNode"></param>
        /// <param name="dynamic"></param>
        /// <param name="sqlBuffer"></param>
        /// <param name="isDynamic"></param>
        /// <param name="postParseRequired"></param>
        /// <param name="statement"></param>
        /// <returns></returns>
        private bool ParseDynamicTags( XmlNode commandTextNode, IDynamicParent dynamic, 
			StringBuilder sqlBuffer, bool isDynamic, bool postParseRequired, IStatement statement)
        {
            XmlNodeList children = commandTextNode.ChildNodes;
            int count = children.Count;
            for (int i = 0; i < count; i++)
            {
                XmlNode child = children[i];
                if ( (child.NodeType == XmlNodeType.CDATA) || (child.NodeType == XmlNodeType.Text) )
                {
                    string data = child.InnerText.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' '); //??

                    data = NodeUtils.ParsePropertyTokens(data, _configScope.Properties);

                    SqlText sqlText;
                    if (postParseRequired)
                    {
                        sqlText = new SqlText();
                        sqlText.Text = data.ToString();
                    }
                    else
                    {
                        sqlText = _paramParser.ParseInlineParameterMap(_configScope, null, data );
                    }

                    dynamic.AddChild(sqlText);
                    sqlBuffer.Append(data);
                }
                else if (child.Name == "include")
                {
                    NameValueCollection prop = NodeUtils.ParseAttributes(child, _configScope.Properties);
                    string refid = NodeUtils.GetStringAttribute(prop, "refid");
                    XmlNode includeNode = (XmlNode)_configScope.SqlIncludes[refid];

                    if (includeNode == null)
                    {
                        String nsrefid = _configScope.ApplyNamespace(refid);
                        includeNode = (XmlNode)_configScope.SqlIncludes[nsrefid];
                        if (includeNode == null)
                        {
                            throw new ConfigurationException("Could not find SQL tag to include with refid '" + refid + "'");
                        }
                    }
                    isDynamic = ParseDynamicTags(includeNode, dynamic, sqlBuffer, isDynamic, false, statement);
                }
                else
                {
                    string nodeName = child.Name;
                    IDeSerializer serializer = _deSerializerFactory.GetDeSerializer(nodeName);

                    if (serializer != null)
                    {
                        isDynamic = true;
                        SqlTag tag;

                        tag = serializer.Deserialize(child);

                        dynamic.AddChild(tag);

                        if (child.HasChildNodes)
                        {
                            isDynamic = ParseDynamicTags( child, tag, sqlBuffer, isDynamic, tag.Handler.IsPostParseRequired, statement );
                        }
                    }
                }
            }

            return isDynamic;
        }
        /// <summary>
        /// Parse Inline ParameterMap
        /// </summary>
        /// <param name="statement"></param>
        /// <param name="sqlStatement"></param>
        /// <returns>A new sql command text.</returns>
        /// <param name="scope"></param>
        public SqlText ParseInlineParameterMap(IScope scope, IStatement statement, string sqlStatement)
        {
            string newSql = sqlStatement;
            ArrayList mappingList = new ArrayList();
            Type parameterClassType = null;

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

            StringTokenizer parser = new StringTokenizer(sqlStatement, PARAMETER_TOKEN, true);
            StringBuilder newSqlBuffer = new StringBuilder();

            string token = null;
            string lastToken = null;

            IEnumerator enumerator = parser.GetEnumerator();

            while (enumerator.MoveNext())
            {
                token = (string)enumerator.Current;

                if (PARAMETER_TOKEN.Equals(lastToken))
                {
                    if (PARAMETER_TOKEN.Equals(token))
                    {
                        newSqlBuffer.Append(PARAMETER_TOKEN);
                        token = null;
                    }
                    else
                    {
                        ParameterProperty mapping = null;
                        if (token.IndexOf(PARAM_DELIM) > -1)
                        {
                            mapping =  OldParseMapping(token, parameterClassType, scope);
                        }
                        else
                        {
                            mapping = NewParseMapping(token, parameterClassType, scope);
                        }

                        mappingList.Add(mapping);
                        newSqlBuffer.Append("? ");

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

                lastToken = token;
            }

            newSql = newSqlBuffer.ToString();

            ParameterProperty[] mappingArray = (ParameterProperty[]) mappingList.ToArray(typeof(ParameterProperty));

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

            return sqlText;
        }
Esempio n. 4
0
 private void ProcessBodyChildren(RequestScope request, SqlTagContext ctx, object parameterObject, IEnumerator localChildren, StringBuilder buffer)
 {
     while (localChildren.MoveNext())
     {
         ISqlChild current = (ISqlChild)localChildren.Current;
         if (current is SqlText)
         {
             SqlText text = (SqlText)current;
             string  str  = text.Text;
             if (text.IsWhiteSpace)
             {
                 buffer.Append(str);
             }
             else
             {
                 buffer.Append(" ");
                 buffer.Append(str);
                 ParameterProperty[] parameters = text.Parameters;
                 if (parameters != null)
                 {
                     int length = parameters.Length;
                     for (int i = 0; i < length; i++)
                     {
                         ctx.AddParameterMapping(parameters[i]);
                     }
                 }
             }
         }
         else if (current is SqlTag)
         {
             SqlTag         tag     = (SqlTag)current;
             ISqlTagHandler handler = tag.Handler;
             int            num3    = 1;
             do
             {
                 StringBuilder builder = new StringBuilder();
                 num3 = handler.DoStartFragment(ctx, tag, parameterObject);
                 if (num3 != 0)
                 {
                     if ((ctx.IsOverridePrepend && (ctx.FirstNonDynamicTagWithPrepend == null)) && (tag.IsPrependAvailable && !(tag.Handler is DynamicTagHandler)))
                     {
                         ctx.FirstNonDynamicTagWithPrepend = tag;
                     }
                     this.ProcessBodyChildren(request, ctx, parameterObject, tag.GetChildrenEnumerator(), builder);
                     num3 = handler.DoEndFragment(ctx, tag, parameterObject, builder);
                     handler.DoPrepend(ctx, tag, parameterObject, builder);
                     if ((num3 != 0) && (builder.Length > 0))
                     {
                         if (handler.IsPostParseRequired)
                         {
                             SqlText text2 = this._paramParser.ParseInlineParameterMap(request, null, builder.ToString());
                             buffer.Append(text2.Text);
                             ParameterProperty[] propertyArray2 = text2.Parameters;
                             if (propertyArray2 != null)
                             {
                                 int num4 = propertyArray2.Length;
                                 for (int j = 0; j < num4; j++)
                                 {
                                     ctx.AddParameterMapping(propertyArray2[j]);
                                 }
                             }
                         }
                         else
                         {
                             buffer.Append(" ");
                             buffer.Append(builder.ToString());
                         }
                         if (tag.IsPrependAvailable && (tag == ctx.FirstNonDynamicTagWithPrepend))
                         {
                             ctx.IsOverridePrepend = false;
                         }
                     }
                 }
             }while (num3 == 2);
         }
     }
 }