Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stack"></param>
 /// <returns></returns>
 internal override WalkedToken Walk(WalkedToken token)
 {
     if (token.TokenType != TokenType.PropertyPath)
     {
         throw new ApplicationException("Cannot apply any to token of type " + token.TokenType);
     }
     return(WalkedToken.FromCriterion(Expression.IsNotEmpty(token.GetValue <String>())));
 }
Exemplo n.º 2
0
        internal override WalkedToken Walk(WalkedToken left, WalkedToken right)
        {
            Disjunction crit = new Disjunction();

            crit.Add(left.Criterion);
            crit.Add(right.Criterion);
            return(WalkedToken.FromCriterion(crit));
        }
Exemplo n.º 3
0
 ///// <summary>
 ///// If a type is nullable of we must
 ///// </summary>
 ///// <param name="type"></param>
 ///// <returns></returns>
 //private System.Type GetTypeCheckForNullable(System.Type type) {
 //if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {…}
 //w.FinalType.GetGenericArguments()
 //}
 /// <summary>
 /// Ok we have a sql function, the inner token already created a criterion we
 /// only needs to configureIt
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 private WalkedToken WalkSqlFunction(WalkedToken left, WalkedToken right)
 {
     CustomCriterion.SqlFunctionCriterion crit = (CustomCriterion.SqlFunctionCriterion)left.Criterion;
     //configureSqlCustomCriterion(crit);
     NHibernate.Expressions.ICriterion outCriterion = expCreator("", null);
     crit.StrOperator = outCriterion.GetType().GetProperty(
         "Op", BindingFlags.NonPublic | BindingFlags.Instance)
                        .GetValue(outCriterion, null) as String;
     crit.ValueToCompareTo = right.GetValue <Object>();
     return(left);
 }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stack"></param>
        /// <returns></returns>
        internal override WalkedToken Walk(WalkedToken left, WalkedToken right)
        {
            if (left.TokenType != TokenType.PropertyPath)
            {
                throw new ApplicationException("Cannot apply any to token of type " + left.TokenType);
            }
            //now create the criterion
            DetachedCriteria d = DetachedCriteria.For(rootCriteria.CriteriaClass)
                                 .SetProjection(Projections.Id())
                                 .Add(Expression.IsNotEmpty(left.GetValue <String>()))
                                 .Add(right.Criterion);

            return(WalkedToken.FromCriterion(Subqueries.Exists(d)));
            //return WalkedToken.FromCriterion(Expression.IsNotEmpty(token.GetValue<String>()));
        }
Exemplo n.º 5
0
        /// <summary>
        /// This is the core function that compose two token.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        internal override WalkedToken Walk(WalkedToken left, WalkedToken right)
        {
            //First of all check if left is a sql expression
            if (left.TokenType == TokenType.SqlFunction)
            {
                return(WalkSqlFunction(left, right));
            }
            //Then check if is a criteria on two properties
            if (left.TokenType == TokenType.PropertyPath && right.TokenType == TokenType.PropertyPath)
            {
                return(WalkTwoProperties(left, right));
            }

            MemberAccessWalker w            = (MemberAccessWalker)(left.TokenType == TokenType.PropertyPath ? left : right);
            Object             value        = left.TokenType == TokenType.PropertyPath ? right.GetValue <Object>() : left.GetValue <Object>();
            String             propertyName = w.MethodName;

            ///Handle null value because it should be treated differently.
            if (value == null)
            {
                return(WalkedToken.FromCriterion(new NHibernate.Expressions.NullExpression(propertyName)));
            }

            if (!w.FinalType.IsAssignableFrom(value.GetType()))
            {
                if (w.FinalType == typeof(Int32))
                {
                    value = ((IConvertible)value).ToInt32(null);
                }
                else if (w.FinalType == typeof(Int16))
                {
                    value = ((IConvertible)value).ToInt16(null);
                }
                else if (w.FinalType == typeof(Int64))
                {
                    value = ((IConvertible)value).ToInt64(null);
                }
                else
                {
                    throw new ApplicationException("Incompatible types");
                }
            }
            return(WalkedToken.FromCriterion(expCreator(propertyName, value)));
        }
Exemplo n.º 6
0
        /// <summary>
        /// We need to pop from the stack all the parameters of the function to call.
        /// </summary>
        /// <param name="queue"></param>
        /// <returns></returns>
        internal override WalkedToken Walk(Stack <WalkedToken> stack)
        {
            //The parameter to pass to sql function except the first that is the method name
            Object[] invokeArguments        = new Object[mParameterNum - 1];
            Int32    propertyParameterIndex = 0;

            for (Int32 pi = invokeArguments.Length - 1; pi >= 0; --pi)
            {
                WalkedToken wt = stack.Pop();
                invokeArguments[pi] = wt.GetValue <Object>();
                if (wt.TokenType == TokenType.PropertyPath)
                {
                    propertyParameterIndex = pi;
                }
            }
            stack.Pop(); //Remove the last element that does not means nothing.
            CustomCriterion.SqlFunctionCriterion crit =
                new CustomCriterion.SqlFunctionCriterion(
                    propertyParameterIndex, null, null, mSqlFunction, invokeArguments);
            return(WalkedToken.FromSqlCriterion(crit));
        }
Exemplo n.º 7
0
        /// <summary>
        /// We can invoke a StartsWith only in a member of a domain class.
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        internal override WalkedToken Walk(WalkedToken left, WalkedToken right)
        {
            System.Diagnostics.Debug.Assert(left.GetType() == typeof(MemberAccessWalker), "A string function can be invoked only on a member of a domain object");
            String searchString;

            switch (func)
            {
            case StringFunction.StartsWith:
                searchString = right.GetValue <String>() + "%";
                break;

            case StringFunction.EndsWith:
                searchString = "%" + right.GetValue <String>();
                break;

            case StringFunction.Contains:
                searchString = "%" + right.GetValue <String>() + "%";
                break;

            default:
                throw new NotImplementedException(String.Format("String function {0} is not implemented", func));
            }
            return(WalkedToken.FromCriterion(Expression.Like(left.GetValue <String>(), searchString)));
        }
Exemplo n.º 8
0
        public static WalkedToken FromSqlCriterion(CustomCriterion.SqlFunctionCriterion criterion)
        {
            WalkedToken token = new WalkedToken(TokenType.SqlFunction, criterion, null);

            return(token);
        }
Exemplo n.º 9
0
        public static WalkedToken FromCriterion(ICriterion criterion)
        {
            WalkedToken token = new WalkedToken(TokenType.CriterionContainer, criterion, null);

            return(token);
        }
Exemplo n.º 10
0
 internal override WalkedToken Walk(WalkedToken token)
 {
     return(token);
 }
Exemplo n.º 11
0
 internal abstract WalkedToken Walk(WalkedToken token);
Exemplo n.º 12
0
 internal abstract WalkedToken Walk(WalkedToken left, WalkedToken right);
Exemplo n.º 13
0
 internal override WalkedToken Walk(WalkedToken token)
 {
     return(WalkedToken.FromCriterion(NHibernate.Expressions.Expression.Not(token.Criterion)));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Execute a comparison between two properties and not between a properties
 /// and a costant.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 private WalkedToken WalkTwoProperties(WalkedToken left, WalkedToken right)
 {
     return(WalkedToken.FromCriterion(
                expPropertyComparisonCreator(left.GetValue <String>(), right.GetValue <String>())));
 }