public override HqlTreeNode BuildHql( MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { // Get the StringComparison argument. var comparison = (StringComparison)(arguments[1].As <ConstantExpression>().Value); if (comparison == StringComparison.CurrentCultureIgnoreCase || comparison == StringComparison.InvariantCultureIgnoreCase || comparison == StringComparison.OrdinalIgnoreCase) { // If the comparison calls for us to ignore the case, use SQL LOWER() return (treeBuilder.Equality( treeBuilder.MethodCall("lower", new[] { visitor.Visit(targetObject).AsExpression() }), treeBuilder.MethodCall("lower", new[] { visitor.Visit(arguments[0]).AsExpression() }))); } // Otherwise use the database's default string comparison mechanism. return(treeBuilder.Equality( visitor.Visit(targetObject).AsExpression(), visitor.Visit(arguments[0]).AsExpression())); }
private HqlTreeNode VisitTypeBinaryExpression(TypeBinaryExpression expression) { return(_hqlTreeBuilder.Equality( _hqlTreeBuilder.Dot( Visit(expression.Expression).AsExpression(), _hqlTreeBuilder.Class()), _hqlTreeBuilder.Ident(expression.TypeOperand.FullName))); }
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { var comparison = (StringComparison)(arguments[1].As <ConstantExpression>().Value); if (comparison == StringComparison.CurrentCultureIgnoreCase || comparison == StringComparison.InvariantCultureIgnoreCase || comparison == StringComparison.OrdinalIgnoreCase) { return(treeBuilder.Equality( treeBuilder.MethodCall("lower", new[] { visitor.Visit(targetObject).AsExpression() }), treeBuilder.MethodCall("lower", new[] { visitor.Visit(arguments[0]).AsExpression() }))); } return(treeBuilder.Equality( visitor.Visit(targetObject).AsExpression(), visitor.Visit(arguments[0]).AsExpression())); }
internal HqlBooleanExpression BuildOfType(Expression expression, System.Type type) { var sessionFactory = _parameters.SessionFactory; var meta = sessionFactory.GetClassMetadata(type) as Persister.Entity.AbstractEntityPersister; if (meta != null && !meta.IsExplicitPolymorphism) { //Adapted the logic found in SingleTableEntityPersister.DiscriminatorFilterFragment var nodes = meta .SubclassClosure .Select(typeName => (NHibernate.Persister.Entity.IQueryable)sessionFactory.GetEntityPersister(typeName)) .Where(persister => !persister.IsAbstract) .Select(persister => _hqlTreeBuilder.Ident(persister.EntityName)) .ToList(); if (nodes.Count == 1) { return(_hqlTreeBuilder.Equality( _hqlTreeBuilder.Dot(Visit(expression).AsExpression(), _hqlTreeBuilder.Class()), nodes[0])); } if (nodes.Count > 1) { return(_hqlTreeBuilder.In( _hqlTreeBuilder.Dot( Visit(expression).AsExpression(), _hqlTreeBuilder.Class()), _hqlTreeBuilder.ExpressionSubTreeHolder(nodes))); } if (nodes.Count == 0) { const string abstractClassWithNoSubclassExceptionMessageTemplate = @"The class {0} can't be instatiated and does not have mapped subclasses; possible solutions: - don't map the abstract class - map its subclasses."; throw new NotSupportedException(string.Format(abstractClassWithNoSubclassExceptionMessageTemplate, meta.EntityName)); } } return(_hqlTreeBuilder.Equality( _hqlTreeBuilder.Dot(Visit(expression).AsExpression(), _hqlTreeBuilder.Class()), _hqlTreeBuilder.Ident(type.FullName))); }
private HqlEquality GenerateEqualityNode(Expression leftExpr, Expression rightExpr) { // TODO - why two visitors? Can't we just reuse? var left = new HqlGeneratorExpressionTreeVisitor(_parameters); var right = new HqlGeneratorExpressionTreeVisitor(_parameters); return(_hqlTreeBuilder.Equality(left.Visit(leftExpr).AsExpression(), right.Visit(rightExpr).AsExpression())); }
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { HqlExpression targetExpression = visitor.Visit(targetObject).AsExpression(); HqlExpression argument0Expression = visitor.Visit(arguments[0]).AsExpression(); HqlEquality result = treeBuilder.Equality(targetExpression, argument0Expression); return(result); }
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { Expression lhs = arguments.Count == 1 ? targetObject : arguments[0]; Expression rhs = arguments.Count == 1 ? arguments[0] : arguments[1]; return(treeBuilder.Equality( visitor.Visit(lhs).ToArithmeticExpression(), visitor.Visit(rhs).ToArithmeticExpression())); }
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { // HqlGeneratorExpressionTreeVisitor.VisitConstantExpression will always return an HqlEquality // instead of HqlParameter for argument that is of type bool. // Use the HqlParameter that exists as first children to the HqlEquality as second argument into treeBuilder.Equality return(treeBuilder.Equality( visitor.Visit(targetObject).AsExpression(), visitor.Visit(arguments[0]).Children.First().AsExpression())); }
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { var isExtensionMethod = (targetObject == null); var expressions = isExtensionMethod ? arguments : new[] { targetObject }.Concat(arguments); var parameters = expressions.Select(o => visitor.Visit(o).AsExpression()); var methodCall = treeBuilder.MethodCall(SpatialDialect.HqlPrefix + (methodName ?? method.Name), parameters); if (typeof(TResult) == typeof(bool)) { return(treeBuilder.Equality(methodCall, treeBuilder.True())); } return(methodCall); }
public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { var methodCall = treeBuilder.MethodCall(SpatialDialect.HqlPrefix + member.Name, new[] { visitor.Visit(expression).AsExpression() }); if (typeof(TResult) == typeof(bool)) { return(treeBuilder.Equality(methodCall, treeBuilder.True())); } return(methodCall); }
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); }
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { // Instance a.CompareTo(b) or static string.Compare(a, b)? 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 override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { return(treeBuilder.Equality(visitor.Visit(targetObject).AsExpression(), visitor.Visit(arguments[0]).AsExpression())); }
private HqlEquality GenerateEqualityNode(Expression leftExpr, Expression rightExpr, IHqlExpressionVisitor visitor) { return(_hqlTreeBuilder.Equality( visitor.Visit(leftExpr).ToArithmeticExpression(), visitor.Visit(rightExpr).ToArithmeticExpression())); }