public string Process(TextTokenHandlerBase behaviour)
        {
            if (behaviour == null)
                throw new ArgumentNullException("behaviour");

            // define which character is separating fields

            var parser = new StringTokenizer(_sqlStatement, ELEMENT_TOKEN, true);

            var newSql = new StringBuilder();
            var keepSurroundingToken = behaviour.KeepSurroundingToken;
            string lastToken = null;

            IEnumerator enumerator = parser.GetEnumerator();

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

                if (ELEMENT_TOKEN.Equals(lastToken))
                {
                    if (ELEMENT_TOKEN.Equals(token))
                    {
                        newSql.Append(ELEMENT_TOKEN);
                        token = null;
                    }
                    else
                    {
                        var value = behaviour.ProcessToken(token);

                        if (value != null)
                        {
                            if (keepSurroundingToken)
                                newSql.Append(ELEMENT_TOKEN + value + ELEMENT_TOKEN);
                            else
                                newSql.Append(value);
                        }

                        enumerator.MoveNext();

                        token = ((string)enumerator.Current);

                        if (!ELEMENT_TOKEN.Equals(token))
                        {
                            throw new DataMapperException("Unterminated dynamic element in sql (" + _sqlStatement + ").");
                        }
                        token = null;
                    }
                }
                else
                {
                    if (!ELEMENT_TOKEN.Equals(token))
                    {
                        newSql.Append(token);
                    }
                }

                lastToken = token;
            }

            return behaviour.PostProcessing(newSql.ToString());
        }
Beispiel #2
0
        public string Process(TextTokenHandlerBase behaviour)
        {
            if (behaviour == null)
            {
                throw new ArgumentNullException("behaviour");
            }

            // define which character is separating fields

            var parser = new StringTokenizer(_sqlStatement, ELEMENT_TOKEN, true);

            var    newSql = new StringBuilder();
            var    keepSurroundingToken = behaviour.KeepSurroundingToken;
            string lastToken            = null;

            IEnumerator enumerator = parser.GetEnumerator();

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

                if (ELEMENT_TOKEN.Equals(lastToken))
                {
                    if (ELEMENT_TOKEN.Equals(token))
                    {
                        newSql.Append(ELEMENT_TOKEN);
                        token = null;
                    }
                    else
                    {
                        var value = behaviour.ProcessToken(token);

                        if (value != null)
                        {
                            if (keepSurroundingToken)
                            {
                                newSql.Append(ELEMENT_TOKEN + value + ELEMENT_TOKEN);
                            }
                            else
                            {
                                newSql.Append(value);
                            }
                        }

                        enumerator.MoveNext();

                        token = ((string)enumerator.Current);

                        if (!ELEMENT_TOKEN.Equals(token))
                        {
                            throw new DataMapperException("Unterminated dynamic element in sql (" + _sqlStatement + ").");
                        }
                        token = null;
                    }
                }
                else
                {
                    if (!ELEMENT_TOKEN.Equals(token))
                    {
                        newSql.Append(token);
                    }
                }

                lastToken = token;
            }

            return(behaviour.PostProcessing(newSql.ToString()));
        }