Esempio n. 1
0
        private static void InSubquery(this IHqlExpressionFactory hqlExpressionFactory, string propertyName, string subquery)
        {
            var aux      = (hqlExpressionFactory as DefaultHqlExpressionFactory);
            var crit     = InSubquery(propertyName, subquery);
            var property = typeof(DefaultHqlExpressionFactory).GetProperty("Criterion");

            property.SetValue(aux, crit);
        }
Esempio n. 2
0
        public static void InsensitiveLikeSpecificAlias(this IHqlExpressionFactory hqlExpressionFactory, string alias, string propertyName, string value, HqlMatchMode matchMode)
        {
            var aux = (hqlExpressionFactory as DefaultHqlExpressionFactory);

            aux.InsensitiveLike(propertyName, value, matchMode);
            var criterion = GetCriterion(alias, propertyName, value, matchMode);
            var property  = typeof(DefaultHqlExpressionFactory).GetProperty("Criterion");

            property.SetValue(aux, criterion);
        }
        private static void BuildPartitionExpression <T>(IHqlExpressionFactory expressionFactory, Action <IHqlExpressionFactory, T[]> partitionExpression, IEnumerable <T> values, int partitionSize)
        {
            if (values.Count() <= partitionSize)
            {
                partitionExpression(expressionFactory, values.ToArray());
                return;
            }

            expressionFactory.Or(lhs => partitionExpression(lhs, values.Take(partitionSize).ToArray()), rhs => BuildPartitionExpression(rhs, partitionExpression, values.Skip(partitionSize), partitionSize));
        }
Esempio n. 4
0
        /// <summary>Search inside the results of a parameterized query.</summary>
        /// <param name="propertyName">The property to compare.</param>
        /// <param name="subquery">The subquery to evaluate. It can contain parameters.
        /// A parameter is expressed as a word starting with ':' and no other character before.
        /// (i.e. SELECT * FROM table WHERE column = :param)</param>
        /// <param name="parameters">A dictionary containing the parameter names (without ':') as keys and their values.</param>
        public static void InSubquery(this IHqlExpressionFactory hqlExpressionFactory, string propertyName, string subquery, Dictionary <string, object> parameters)
        {
            string subqueryWithParameters = "";

            Regex re = new Regex(@"(?<![^\s]):[^\s]+");

            subqueryWithParameters = re.Replace(subquery, x => {
                object param;

                if (parameters.TryGetValue(x.ToString().TrimStart(':'), out param))
                {
                    var typeCode = Type.GetTypeCode(param.GetType());
                    switch (typeCode)
                    {
                    case TypeCode.String:
                    case TypeCode.DateTime:
                        return(HqlRestrictions.FormatValue(param));

                    case TypeCode.UInt16:
                    case TypeCode.UInt32:
                    case TypeCode.UInt64:
                    case TypeCode.Int16:
                    case TypeCode.Int32:
                    case TypeCode.Int64:
                    case TypeCode.Decimal:
                    case TypeCode.Double:
                        return(FormatNumber(param));

                    default:
                        return("");
                    }
                }

                return("");
            });

            InSubquery(hqlExpressionFactory, propertyName, subqueryWithParameters);
        }
 /// <summary>
 /// Applies the expression in partitions of given size, ORed together.
 /// This helps to overcome limitations with certain clauses (like IN()) that only accept a specific amount of arguments.
 /// </summary>
 /// <typeparam name="T">Type of the values used in the expression</typeparam>
 /// <param name="expressionFactory">The HQL expression factory</param>
 /// <param name="partitionExpression">Expression to apply on a partition of values</param>
 /// <param name="values">All the values to use</param>
 /// <param name="partitionSize">Determines how many values will be used for one partition</param>
 public static void PartitionedExpression <T>(this IHqlExpressionFactory expressionFactory, Action <IHqlExpressionFactory, T[]> partitionExpression, IEnumerable <T> values, int partitionSize = 1000)
 {
     BuildPartitionExpression(expressionFactory, partitionExpression, values, partitionSize);
 }