Constant() public method

public Constant ( object value ) : HqlConstant
value object
return HqlConstant
示例#1
0
			public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
			{
				return treeBuilder.Like(
						visitor.Visit(targetObject).AsExpression(),
						treeBuilder.Concat(
								treeBuilder.Constant("%"),
								visitor.Visit(arguments[0]).AsExpression(),
								treeBuilder.Constant("%")));
			}
示例#2
0
 public override NHibernate.Hql.Ast.HqlTreeNode BuildHql(System.Reflection.MethodInfo method, System.Linq.Expressions.Expression targetObject, System.Collections.ObjectModel.ReadOnlyCollection <System.Linq.Expressions.Expression> arguments, NHibernate.Hql.Ast.HqlTreeBuilder treeBuilder, NHibernate.Linq.Visitors.IHqlExpressionVisitor visitor)
 {
     //return treeBuilder.Constant(0);
     return(treeBuilder.Case(new HqlWhen[] {
         treeBuilder.When(
             treeBuilder.LessThan(visitor.Visit(arguments[0]).AsExpression(), visitor.Visit(arguments[1]).AsExpression()),
             treeBuilder.Constant(-1)),
         treeBuilder.When(
             treeBuilder.GreaterThan(visitor.Visit(arguments[0]).AsExpression(), visitor.Visit(arguments[1]).AsExpression()),
             treeBuilder.Constant(1))
     },
                             treeBuilder.Constant(0)));
 }
		public override HqlTreeNode BuildHql(
			MethodInfo method,
			Expression targetObject,
			ReadOnlyCollection<Expression> arguments,
			HqlTreeBuilder treeBuilder,
			IHqlExpressionVisitor visitor)
		{
			var left = treeBuilder.Cast(visitor.Visit(targetObject).AsExpression(), typeof(string));
			var right = treeBuilder.Cast(visitor.Visit(arguments.First()).AsExpression(), typeof(string));

			var leftSubstring = treeBuilder.MethodCall("substring", left, treeBuilder.Constant(4));
			var rightSubstring = treeBuilder.MethodCall("substring", right, treeBuilder.Constant(4));
			var equals = treeBuilder.Equality(leftSubstring, rightSubstring);
			return equals;
		}
		private static HqlExpression GetRhs(MethodInfo method, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			if (arguments.Count > 0)
				return visitor.Visit(arguments[0]).AsExpression();

			var returnType = method.ReturnType;
			var instance = returnType.IsValueType ? Activator.CreateInstance(returnType) : null;
			return treeBuilder.Constant(instance);
		}
示例#5
0
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			// Instance CompareTo() or static string.Compare()?
			Expression lhs = arguments.Count == 1 ? targetObject : arguments[0];
			Expression rhs = arguments.Count == 1 ? arguments[0] : arguments[1];

			HqlExpression lhs1 = visitor.Visit(lhs).AsExpression();
			HqlExpression rhs1 = visitor.Visit(rhs).AsExpression();
			HqlExpression lhs2 = visitor.Visit(lhs).AsExpression();
			HqlExpression rhs2 = visitor.Visit(rhs).AsExpression();

			// CASE WHEN (table.[Name] = N'Foo') THEN 0
			//      WHEN (table.[Name] > N'Foo') THEN 1
			//      ELSE -1 END

			return treeBuilder.Case(
				new[]
					{
						treeBuilder.When(treeBuilder.Equality(lhs1, rhs1), treeBuilder.Constant(0)),
						treeBuilder.When(treeBuilder.GreaterThan(lhs2, rhs2), treeBuilder.Constant(1))
					},
				treeBuilder.Constant(-1));
		}
		public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments,
		                            HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			if (arguments.Count == 2)
			{
				return treeBuilder.Like(
					visitor.Visit(arguments[0]).AsExpression(),
					visitor.Visit(arguments[1]).AsExpression());
			}
			if (arguments[2].NodeType == ExpressionType.Constant)
			{
				var escapeCharExpression = (ConstantExpression)arguments[2];
				return treeBuilder.Like(
					visitor.Visit(arguments[0]).AsExpression(),
					visitor.Visit(arguments[1]).AsExpression(),
					treeBuilder.Constant(escapeCharExpression.Value));
			}
			throw new ArgumentException("The escape character must be specified as literal value or a string variable");

		}
示例#7
0
 public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     if (arguments.Count == 1)
     {
         return treeBuilder.MethodCall("locate", 
             visitor.Visit(arguments[0]).AsExpression(),
             visitor.Visit(targetObject).AsExpression(),
             treeBuilder.Constant(0));
     }
     return treeBuilder.MethodCall("locate", 
         visitor.Visit(arguments[0]).AsExpression(),
         visitor.Visit(targetObject).AsExpression(),
         visitor.Visit(arguments[1]).AsExpression());
 }
        ///<summary>
        ///
        ///</summary>
        ///<param name="method"></param>
        ///<param name="targetObject">Should be an ISecurable</param>
        ///<param name="arguments">Not sure what the heck arg[0] is, but arg[1] is the entityName</param>
        ///<param name="treeBuilder"></param>
        ///<param name="visitor"></param>
        ///<returns></returns>
        public override HqlTreeNode BuildHql(
            MethodInfo method,
            Expression targetObject,
            ReadOnlyCollection<Expression> arguments,
            HqlTreeBuilder treeBuilder,
            IHqlExpressionVisitor visitor)
        {
            // arguments[0] is a System.Linq.Expressions.Expression
            // arguments[1] is our constant value
            var expr = arguments[0];

            // This doesn't really help us right now, but log it just in case...
            if (expr is Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression)
            {
                Console.WriteLine(
                    "ReferencedQuerySource: {0}",
                    ((Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression)expr).ReferencedQuerySource
                );
            }

            // Getting somewhere?
            // expr.Type is Spc.Ofp.Tubs.DAL.Entities.Trip
            Console.WriteLine("Expression type: {0}", expr.Type);

            // HqlAlias is "AccessControl" (entity property), "ace" (name used in expression) ?
            // HqlExpression is equality expression ?
            var aceAlias = treeBuilder.Alias("AccessControl as ace");

            var entityName = ((ConstantExpression)arguments[1]).Value;

            Console.WriteLine("entityName: {0}", entityName);

            var equality = treeBuilder.Equality(
                treeBuilder.Alias("ace.EntityName"),
                treeBuilder.Constant(entityName)
            );

            var joinExpression = treeBuilder.Join(equality, aceAlias);

            // This doesn't actually do anything...
            return visitor.Visit(expr).AsExpression();

            /*
             * var dc =
                DetachedCriteria.For<T>()
                                .CreateAlias("AccessControl", "ace", JoinType.InnerJoin)
                                .Add(NHibernate.Criterion.Expression.Eq("ace.EntityName", this._entityName));
             */
        }
        private HqlTreeNode BuildFromArray(Array valueArray, HqlTreeBuilder treeBuilder)
        {
            var elementType = valueArray.GetType().GetElementType();

            if (!elementType.IsValueType && elementType != typeof(string))
                throw new ArgumentException("Only primitives and strings can be used");

            Type enumUnderlyingType = elementType.IsEnum ?
            Enum.GetUnderlyingType(elementType) : null;
            var variants = new HqlExpression[valueArray.Length];

            for (int index = 0; index < valueArray.Length; index++)
            {
                var variant = valueArray.GetValue(index);
                var val = variant;

                if (elementType.IsEnum)
                    val = Convert.ChangeType(variant, enumUnderlyingType);

                variants[index] = treeBuilder.Constant(val);
            }

            return treeBuilder.DistinctHolder(variants);
        }
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			string trimWhere;
			if (method.Name == "TrimStart")
				trimWhere = "leading";
			else if (method.Name == "TrimEnd")
				trimWhere = "trailing";
			else
				trimWhere = "both";

			string trimChars = "";
			if (method.GetParameters().Length > 0)
				foreach (char c in (char[])((ConstantExpression)arguments[0]).Value)
					trimChars += c;


			if (trimChars == "")
			{
				return treeBuilder.MethodCall("trim", treeBuilder.Ident(trimWhere), treeBuilder.Ident("from"), visitor.Visit(targetObject).AsExpression());
			}
			else
			{
				return treeBuilder.MethodCall("trim", treeBuilder.Ident(trimWhere), treeBuilder.Constant(trimChars), treeBuilder.Ident("from"), visitor.Visit(targetObject).AsExpression());
			}
		}
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			HqlMethodCall locate;
			if (arguments.Count == 1)
			{
				locate = treeBuilder.MethodCall("locate",
					visitor.Visit(arguments[0]).AsExpression(),
					visitor.Visit(targetObject).AsExpression()); //,
				//treeBuilder.Constant(0));
			}
			else
			{
				var start = treeBuilder.Add(visitor.Visit(arguments[1]).AsExpression(), treeBuilder.Constant(1));
				locate = treeBuilder.MethodCall("locate",
							visitor.Visit(arguments[0]).AsExpression(),
							visitor.Visit(targetObject).AsExpression(),
							start);
			}
			return treeBuilder.Subtract(locate,treeBuilder.Constant(1));
		}
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			var stringExpr = visitor.Visit(targetObject).AsExpression();
			var start = treeBuilder.Add(visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Constant(1));

			if (arguments.Count == 1)
				return treeBuilder.MethodCall("substring", stringExpr, start);

			var length = visitor.Visit(arguments[1]).AsExpression();
			return treeBuilder.MethodCall("substring", stringExpr, start, length);
		}
			public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
			{
				var length = arguments.Count == 1
								? treeBuilder.Subtract(treeBuilder.MethodCall("length", visitor.Visit(targetObject).AsExpression()), visitor.Visit(arguments[0]).AsExpression())
								: visitor.Visit(arguments[1]).AsExpression();

				return treeBuilder.MethodCall("substring", visitor.Visit(targetObject).AsExpression(),
												treeBuilder.Add(visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Constant(1)),
												length);
			}
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			return treeBuilder.Constant(1);
		}
示例#15
0
        private HqlTreeNode BuildFromArray(IEnumerable valueArray, HqlTreeBuilder treeBuilder, Type elementType)
        {
            Type enumUnderlyingType = elementType.IsEnum ? Enum.GetUnderlyingType(elementType) : null;
            IList<HqlTreeNode> variants = new List<HqlTreeNode>();

            foreach (object variant in valueArray)
            {
                object val = variant;

                if (elementType.IsEnum)
                    val = Convert.ChangeType(variant, enumUnderlyingType);

                HqlConstant hqlConstant = treeBuilder.Constant(val);
                variants.Add(hqlConstant);
            }

            return treeBuilder.ExpressionSubTreeHolder(variants);
        }