/// <summary>
        /// Warning: adds new parameters to the argument by side-effect, as well as mutating the query expression tree!
        /// </summary>
        protected override IQueryExpression ExpandParameters(IDictionary <string, TypedValue> namedParamsCopy)
        {
            if (namedParameterLists.Count == 0)
            {
                // Short circuit straight out
                return(QueryExpression);
            }

            // Build a map from single parameters to lists
            var map = new Dictionary <string, IList <string> >();

            foreach (var me in namedParameterLists)
            {
                var name = me.Key;
                var vals = (IEnumerable)me.Value.Value;
                var type = me.Value.Type;

                var typedValues = (from object value in vals
                                   select new TypedValue(type, value, Session.EntityMode))
                                  .ToList();

                if (typedValues.Count == 1)
                {
                    namedParamsCopy[name] = typedValues[0];
                    continue;
                }

                var aliases = new string[typedValues.Count];
                var isJpaPositionalParam = parameterMetadata.GetNamedParameterDescriptor(name).JpaStyle;
                for (var index = 0; index < typedValues.Count; index++)
                {
                    var value = typedValues[index];
                    var alias = (isJpaPositionalParam ? 'x' + name : name + StringHelper.Underscore) + index + StringHelper.Underscore;
                    namedParamsCopy[alias] = value;
                    aliases[index]         = alias;
                }

                map.Add(name, aliases);
            }

            //TODO: Do we need to translate expression one more time here?
            var newTree = ParameterExpander.Expand(QueryExpression.Translate(Session.Factory, false), map);
            var key     = new StringBuilder(QueryExpression.Key);

            foreach (var pair in map)
            {
                key.Append(' ');
                key.Append(pair.Key);
                key.Append(':');
                foreach (var s in pair.Value)
                {
                    key.Append(s);
                }
            }

            return(new ExpandedQueryExpression(QueryExpression, newTree, key.ToString()));
        }
        /// <summary>
        /// Warning: adds new parameters to the argument by side-effect, as well as mutating the query expression tree!
        /// </summary>
        protected IQueryExpression ExpandParameters(IDictionary <string, TypedValue> namedParamsCopy)
        {
            if (namedParameterLists.Count == 0)
            {
                // Short circuit straight out
                return(QueryExpression);
            }

            // Build a map from single parameters to lists
            var map = new Dictionary <string, List <string> >();

            foreach (var me in namedParameterLists)
            {
                string name = me.Key;
                var    vals = (ICollection)me.Value.Value;
                var    type = me.Value.Type;

                if (vals.Count == 1)
                {
                    // No expansion needed here
                    var iter = vals.GetEnumerator();
                    iter.MoveNext();
                    namedParamsCopy[name] = new TypedValue(type, iter.Current, Session.EntityMode);
                    continue;
                }

                var aliases = new List <string>();
                var i       = 0;
                var isJpaPositionalParam = parameterMetadata.GetNamedParameterDescriptor(name).JpaStyle;

                foreach (var obj in vals)
                {
                    var alias = (isJpaPositionalParam ? 'x' + name : name + StringHelper.Underscore) + i++ + StringHelper.Underscore;
                    namedParamsCopy[alias] = new TypedValue(type, obj, Session.EntityMode);
                    aliases.Add(alias);
                }

                map.Add(name, aliases);
            }

            var newTree = ParameterExpander.Expand(QueryExpression.Translate(Session.Factory), map);
            var key     = new StringBuilder(QueryExpression.Key);

            map.Aggregate(key, (sb, kvp) =>
            {
                sb.Append(' ');
                sb.Append(kvp.Key);
                sb.Append(':');
                kvp.Value.Aggregate(sb, (sb2, str) => sb2.Append(str));
                return(sb);
            });

            return(new ExpandedQueryExpression(QueryExpression, newTree, key.ToString()));
        }
        public static IASTNode Expand(IASTNode tree, Dictionary <string, IList <string> > map)
        {
            var expander = new ParameterExpander(tree, map);

            return(expander.Expand());
        }
Exemple #4
0
        /// <summary>
        /// Warning: adds new parameters to the argument by side-effect, as well as mutating the query expression tree!
        /// </summary>
        protected override IQueryExpression ExpandParameters(IDictionary <string, TypedValue> namedParamsCopy)
        {
            if (namedParameterLists.Count == 0)
            {
                // Short circuit straight out
                return(QueryExpression);
            }

            // Build a map from single parameters to lists
            var map = new Dictionary <string, IList <string> >();

            foreach (var me in namedParameterLists)
            {
                var name = me.Key;
                var vals = (IEnumerable)me.Value.Value;
                var type = me.Value.Type;

                var typedValues = (from object value in vals
                                   select new TypedValue(type, value, false))
                                  .ToList();

                if (typedValues.Count == 1)
                {
                    namedParamsCopy[name] = typedValues[0];
                    continue;
                }

                var aliases = new string[typedValues.Count];
                var isJpaPositionalParam = parameterMetadata.GetNamedParameterDescriptor(name).JpaStyle;
                for (var index = 0; index < typedValues.Count; index++)
                {
                    var value = typedValues[index];
                    var alias = (isJpaPositionalParam ? 'x' + name : name + StringHelper.Underscore) + index + StringHelper.Underscore;
                    namedParamsCopy[alias] = value;
                    aliases[index]         = alias;
                }

                map.Add(name, aliases);
            }

            if (map.Count == 0)
            {
                // No list parameter needs to be replaced: they are all single valued. They just need
                // to be retyped, which has been done above.
                return(QueryExpression);
            }

            //TODO: Do we need to translate expression one more time here?
            // This is not much an issue anymore: ExpressionQueryImpl are currently created only with NhLinqExpression
            // which do cache their translation.
            var newTree = ParameterExpander.Expand(QueryExpression.Translate(Session.Factory, _isFilter), map);
            var key     = new StringBuilder(QueryExpression.Key);

            foreach (var pair in map)
            {
                key.Append(' ');
                key.Append(pair.Key);
                key.Append(':');
                foreach (var s in pair.Value)
                {
                    key.Append(s);
                }
            }

            return(new ExpandedQueryExpression(QueryExpression, newTree, key.ToString()));
        }
		public static IASTNode Expand(IASTNode tree, Dictionary<string, IList<string>> map)
		{
			var expander = new ParameterExpander(tree, map);

			return expander.Expand();
		}