public bool HasCorrelation(ReadOnlyExpression readOnlyExpression) { _readOnlyExpression = readOnlyExpression; Visit(_readOnlyExpression); return(_hasCorrelation); }
/// <summary> /// Visit read only expression /// </summary> /// <param name="readOnlyExpression"></param> /// <returns></returns> public Expression VisitReadOnly([NotNull] ReadOnlyExpression expression) { Check.NotNull(expression, nameof(expression)); // TODO: nested read only expression // reading clauses if (expression.ReadingClauses.Count > 0) { IterateGrammer(expression.ReadingClauses); } else { CreatePseudoMatchClause(); } // return items _commandBuilder.Append(" RETURN "); var returnItemsAdded = false; if (expression.IsReturnStar) { _commandBuilder .Append( SqlGenerator.DelimitIdentifier( expression.ReturnStarNode.Alias ) ) .Append(".*"); returnItemsAdded = true; } if (expression.ReturnItems.Count > 0) { if (expression.IsReturnStar) { _commandBuilder.Append(", "); } // TODO: Optimization visitors IterateGrammer(expression.ReturnItems, s => s.Append(", ")); returnItemsAdded = true; } if (!returnItemsAdded) { _commandBuilder.Append("1"); } // TODO: Order, Skip, Limit return(expression); }
/// <summary> /// Add read only expression /// </summary> /// <param name="querySource"></param> /// <param name="readOnlyExpression"></param> public virtual void AddQuery( [NotNull] IQuerySource querySource, [NotNull] ReadOnlyExpression readOnlyExpression ) { Check.NotNull(querySource, nameof(querySource)); Check.NotNull(readOnlyExpression, nameof(readOnlyExpression)); QueriesBySource.Add(querySource, readOnlyExpression); }
protected DefaultQueryCypherGenerator( [NotNull] QuerySqlGeneratorDependencies dependencies, [NotNull] ReadOnlyExpression readOnlyExpression ) { Check.NotNull(dependencies, nameof(dependencies)); Check.NotNull(readOnlyExpression, nameof(readOnlyExpression)); Dependencies = dependencies; ReadOnlyExpression = readOnlyExpression; }
/// <summary> /// /// </summary> /// <param name="queryModelVisitor"></param> /// <param name="targetReadOnlyExpression"></param> /// <param name="topLevelWhere"></param> /// <param name="inReturn"></param> /// <returns></returns> public CypherTranslatingExpressionVisitor Create( [NotNull] CypherQueryModelVisitor queryModelVisitor, [CanBeNull] ReadOnlyExpression targetReadOnlyExpression = null, [CanBeNull] Expression topLevelWhere = null, bool inReturn = false ) => new CypherTranslatingExpressionVisitor( Dependencies, Check.NotNull(queryModelVisitor, nameof(queryModelVisitor)), targetReadOnlyExpression, topLevelWhere, inReturn );
/// <summary> /// Uses the return types (from the read only expression) to /// create a value buffer factory (either typed or untyped) /// </summary> /// <param name="relationalValueBufferFactoryFactory"></param> /// <param name="dataReader"></param> /// <returns></returns> public virtual IRelationalValueBufferFactory CreateValueBufferFactory( IRelationalValueBufferFactoryFactory relationalValueBufferFactoryFactory, DbDataReader dataReader ) { Check.NotNull(relationalValueBufferFactoryFactory, nameof(relationalValueBufferFactoryFactory)); return(relationalValueBufferFactoryFactory .Create( ReadOnlyExpression.GetReturnTypes().ToArray(), indexMap: null )); }
/// <summary> /// Shaper (?) helps transfer entities potentially from state /// </summary> /// <param name="elementType"></param> /// <param name="entityType"></param> /// <param name="readOnlyExpression"></param> /// <returns></returns> private Shaper CreateShaper( Type elementType, IEntityType entityType, ReadOnlyExpression readOnlyExpression ) { Shaper shaper; if (QueryModelVisitor .QueryCompilationContext .QuerySourceRequiresMaterialization(_querySource)) { var materializer = _materializerFactory .CreateMaterializer( entityType, readOnlyExpression, (p, roe) => { return(roe.AddReturnItem(p, _querySource)); }, _querySource, out var typeIndexMapping ) .Compile(); shaper = (Shaper)_createEntityShaperMethodInfo.MakeGenericMethod(elementType) .Invoke( null, new object[] { _querySource, QueryModelVisitor.QueryCompilationContext.IsTrackingQuery, entityType.FindPrimaryKey(), materializer, typeIndexMapping, QueryModelVisitor.QueryCompilationContext.IsQueryBufferRequired }); } else { // TODO: Handle discriminate? shaper = new ValueBufferShaper(_querySource); } return(shaper); }
private bool AddWatch(string variable) { var reference = new ReadOnlyExpression(); reference.Content = variable; foreach (var graph in CompositionManager.TrackingState.Keys) { var value = reference.Execute(graph.Variables); if (!value.IsEmpty) { if (value.TryGetDictionary(out var collection)) { AddWatch(variable, collection); return(true); } else { Debug.LogWarningFormat(_invalidWatchWarning, variable, value.Type); return(false); } } } if (CompositionManager.Exists) { var value = reference.Execute(VariableContext.Default); if (value.TryGetDictionary(out var collection)) { AddWatch(variable, collection); return(true); } else { Debug.LogWarningFormat(_invalidWatchWarning, variable, value.Type); return(false); } } Debug.LogWarningFormat(_missingWatchWarning, variable); return(false); }
public CypherTranslatingExpressionVisitor( [NotNull] SqlTranslatingExpressionVisitorDependencies dependencies, [NotNull] CypherQueryModelVisitor queryModelVisitor, [CanBeNull] ReadOnlyExpression targetReadOnlyExpresion = null, [CanBeNull] Expression topLevelWhere = null, bool inReturn = false ) { Check.NotNull(dependencies, nameof(dependencies)); Check.NotNull(queryModelVisitor, nameof(queryModelVisitor)); _compositeExpressionFragmentTranslator = dependencies.CompositeExpressionFragmentTranslator; _targetReadOnlyExpression = targetReadOnlyExpresion; _inReturn = inReturn; _isTopLevelReturn = inReturn; _queryModelVisitor = queryModelVisitor; _relationalTypeMapper = dependencies.RelationalTypeMapper; }
public override IQuerySqlGenerator CreateDefault(ReadOnlyExpression readOnlyExpression) => new TestQueryCypherGenerator(Dependencies, readOnlyExpression);
public TestQueryCypherGenerator( QuerySqlGeneratorDependencies dependencies, ReadOnlyExpression readOnlyExpression) : base(dependencies, readOnlyExpression) { }
/// <summary> /// Query Sql (cypher) generator /// </summary> /// <param name="readOnlyExpression"></param> /// <returns></returns> public abstract IQuerySqlGenerator CreateDefault( [NotNull] ReadOnlyExpression readOnlyExpression );
/// <summary> /// Uses the read only expression to materialize properties into /// value buffers /// </summary> /// <param name="entityType"></param> /// <param name="readOnlyExpression"></param> /// <param name="Func<IProperty"></param> /// <param name="returnItemHandler"></param> /// <param name="querySource"></param> /// <param name="Dictionary<Type"></param> /// <param name="typeIndexMapping"></param> /// <returns></returns> public Expression <Func <ValueBuffer, object> > CreateMaterializer( [NotNull] IEntityType entityType, [NotNull] ReadOnlyExpression readOnlyExpression, [NotNull] Func <IProperty, ReadOnlyExpression, int> returnItemHandler, [CanBeNull] IQuerySource querySource, out Dictionary <Type, int[]> typeIndexMapping ) { Check.NotNull(entityType, nameof(entityType)); Check.NotNull(readOnlyExpression, nameof(readOnlyExpression)); Check.NotNull(returnItemHandler, nameof(returnItemHandler)); typeIndexMapping = null; ParameterExpression valueBufferParameter = Expression .Parameter( typeof(ValueBuffer), "valueBuffer" ); var concreteEntityTypes = entityType .GetConcreteTypesInHierarchy() .ToList(); // grab first concrete entity type filling the index mapping with return item indexes int[] indexMapping = new int[concreteEntityTypes.First().PropertyCount()]; int propertyIndex = 0; // TODO: Review exclusion of shadow properties var properties = concreteEntityTypes .First() .GetProperties() .Where(p => !p.IsShadowProperty); foreach (var property in properties) { indexMapping[propertyIndex++] = returnItemHandler( property, readOnlyExpression ); } // materializer Expression materializer = _entityMaterializerSource .CreateMaterializeExpression( concreteEntityTypes.First(), valueBufferParameter, indexMapping ); // when single concrete entity type that is the root return just the value buffer to object fn if (concreteEntityTypes.Count == 1 && concreteEntityTypes.First().RootType() == concreteEntityTypes.First()) { return(Expression.Lambda <Func <ValueBuffer, object> >( materializer, valueBufferParameter )); } // TODO: Handle discrimination? throw new NotImplementedException(); }