internal override WalkedToken Walk(WalkedToken left, WalkedToken right) { Disjunction crit = new Disjunction(); crit.Add(left.Criterion); crit.Add(right.Criterion); return(WalkedToken.FromCriterion(crit)); }
/// <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>()))); }
/// <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>())); }
/// <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))); }
/// <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))); }
internal override WalkedToken Walk(WalkedToken token) { return(WalkedToken.FromCriterion(NHibernate.Expressions.Expression.Not(token.Criterion))); }
/// <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>()))); }