public IASTNode Translate(ISessionFactoryImplementor sessionFactory, bool filter) { if (ExpressionToHqlTranslationResults != null) { // Query has already been translated. Arguments do not really matter, because queries are anyway tied // to a single session factory and cannot switch from being a filter query (query on a mapped collection) // or not. return(DuplicateTree(ExpressionToHqlTranslationResults.Statement.AstNode)); } var requiredHqlParameters = new List <NamedParameterDescriptor>(); var queryModel = NhRelinqQueryParser.Parse(_expression); var visitorParameters = new VisitorParameters(sessionFactory, _constantToParameterMap, requiredHqlParameters, new QuerySourceNamer(), TargetType, QueryMode); ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, visitorParameters, true, ReturnType); if (ExpressionToHqlTranslationResults.ExecuteResultTypeOverride != null) { Type = ExpressionToHqlTranslationResults.ExecuteResultTypeOverride; } ParameterDescriptors = requiredHqlParameters.AsReadOnly(); CanCachePlan = CanCachePlan && // If some constants do not have matching HQL parameters, their values from first query will // be embedded in the plan and reused for subsequent queries: do not cache the plan. !ParameterValuesByName .Keys .Except(requiredHqlParameters.Select(p => p.Name)) .Any(); // The ast node may be altered by caller, duplicate it for preserving the original one. return(DuplicateTree(ExpressionToHqlTranslationResults.Statement.AstNode)); }
public IASTNode Translate(ISessionFactoryImplementor sessionFactory, bool filter) { var requiredHqlParameters = new List <NamedParameterDescriptor>(); var queryModel = NhRelinqQueryParser.Parse(_expression); var visitorParameters = new VisitorParameters(sessionFactory, _constantToParameterMap, requiredHqlParameters, new QuerySourceNamer(), TargetType, QueryMode); ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, visitorParameters, true, ReturnType); if (ExpressionToHqlTranslationResults.ExecuteResultTypeOverride != null) { Type = ExpressionToHqlTranslationResults.ExecuteResultTypeOverride; } ParameterDescriptors = requiredHqlParameters.AsReadOnly(); CanCachePlan = CanCachePlan && // If some constants do not have matching HQL parameters, their values from first query will // be embedded in the plan and reused for subsequent queries: do not cache the plan. !ParameterValuesByName .Keys .Except(requiredHqlParameters.Select(p => p.Name)) .Any(); return(ExpressionToHqlTranslationResults.Statement.AstNode); }
private void AssertResult( IQueryable query, bool rewriteQuery, bool supported, string expectedEntityName, string expectedMemberPath, Predicate <IType> expectedMemberType, Predicate <IAbstractComponentType> expectedComponentType = null, bool nullability = true) { expectedComponentType = expectedComponentType ?? (o => o == null); var expression = query.Expression; var preTransformResult = NhRelinqQueryParser.PreTransform(expression, new PreTransformationParameters(QueryMode.Select, Sfi)); expression = preTransformResult.Expression; var constantToParameterMap = ExpressionParameterVisitor.Visit(preTransformResult); var queryModel = NhRelinqQueryParser.Parse(expression); var requiredHqlParameters = new List <NamedParameterDescriptor>(); var visitorParameters = new VisitorParameters( Sfi, constantToParameterMap, requiredHqlParameters, new QuerySourceNamer(), expression.Type, QueryMode.Select); if (rewriteQuery) { QueryModelVisitor.GenerateHqlQuery( queryModel, visitorParameters, true, NhLinqExpressionReturnType.Scalar); } var found = _tryGetMappedType( Sfi, queryModel.SelectClause.Selector, out var memberType, out var entityPersister, out var componentType, out var memberPath); Assert.That(found, Is.EqualTo(supported), $"Expression should be {(supported ? "supported" : "unsupported")}"); Assert.That(entityPersister?.EntityName, Is.EqualTo(expectedEntityName), "Invalid entity name"); Assert.That(memberPath, Is.EqualTo(expectedMemberPath), "Invalid member path"); Assert.That(() => expectedMemberType(memberType), $"Invalid member type: {memberType?.Name ?? "null"}"); Assert.That(() => expectedComponentType(componentType), $"Invalid component type: {componentType?.Name ?? "null"}"); if (found) { Assert.That(_tryGetMappedNullability(Sfi, queryModel.SelectClause.Selector, out var isNullable), Is.True, "Expression should be supported"); Assert.That(nullability, Is.EqualTo(isNullable), "Nullability is not correct"); } }
public IASTNode Translate(ISessionFactoryImplementor sessionFactory, bool filter) { var requiredHqlParameters = new List <NamedParameterDescriptor>(); var querySourceNamer = new QuerySourceNamer(); var queryModel = NhRelinqQueryParser.Parse(_expression); var visitorParameters = new VisitorParameters(sessionFactory, _constantToParameterMap, requiredHqlParameters, querySourceNamer); ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, visitorParameters, true); ParameterDescriptors = requiredHqlParameters.AsReadOnly(); return(ExpressionToHqlTranslationResults.Statement.AstNode); }
public IASTNode Translate(ISessionFactoryImplementor sessionFactory) { //if (_astNode == null) { var requiredHqlParameters = new List <NamedParameterDescriptor>(); // TODO - can we cache any of this? var queryModel = NhRelinqQueryParser.Parse(_expression); ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, new VisitorParameters( sessionFactory, _constantToParameterMap, requiredHqlParameters), true); ParameterDescriptors = requiredHqlParameters.AsReadOnly(); _astNode = ExpressionToHqlTranslationResults.Statement.AstNode; } return(_astNode); }