コード例 #1
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));
        }
コード例 #2
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>())));
 }
コード例 #3
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>()));
        }
コード例 #4
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)));
        }
コード例 #5
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)));
        }
コード例 #6
0
 internal override WalkedToken Walk(WalkedToken token)
 {
     return(WalkedToken.FromCriterion(NHibernate.Expressions.Expression.Not(token.Criterion)));
 }
コード例 #7
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>())));
 }