Пример #1
0
        public void VisitInsertClause(InsertClause insertClause, QueryModel queryModel)
        {
            if (insertClause.WithSelector != null)
            {
                QueryText.Append(" insert ");

                GetAqlExpression(insertClause.WithSelector, queryModel);
            }
            else
            {
                QueryText.AppendFormat(" insert {0} ", LinqUtility.ResolvePropertyName(insertClause.ItemName));
            }

            QueryText.AppendFormat(" in {0} ", LinqUtility.ResolveCollectionName(Db, insertClause.CollectionType));
        }
Пример #2
0
        public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
        {
            if (fromClause.FromExpression as SubQueryExpression != null)
            {
                throw new Exception("MainFromClause.FromExpression cant be SubQueryExpression because group by is handle in itself clause");
            }

            string fromName = LinqUtility.ResolveCollectionName(this.Db, fromClause.ItemType);

            //  .Select(g => g.Select(gList => gList.Age)) subquery select, changes the fromName to group name (C1 for example)
            if (fromClause.FromExpression.Type.Name == "IGrouping`2")
            {
                var groupByClause = LinqUtility.PriorGroupBy(ParnetModelVisitor);

                var parentMVisitor = LinqUtility.FindParentModelVisitor(this);
                //parentMVisitor.GroupByNameCounter++;

                fromName = groupByClause[0].TranslateIntoName();

                fromName = LinqUtility.ResolvePropertyName(fromName);
            }

            //  == "IGrouping`2" => .Select(g => g.Select(gList => gList.Age)) subquery select
            if (fromClause.FromExpression.NodeType == ExpressionType.Constant ||
                fromClause.FromExpression.Type.Name == "IGrouping`2")
            {
                if (fromClause.FromExpression.Type.Name == "ArangoQueryable`1" || fromClause.FromExpression.Type.Name == "IGrouping`2")
                {
                    QueryText.AppendFormat(" for {0} in {1} ", LinqUtility.ResolvePropertyName(fromClause.ItemName), fromName);
                }
                else
                {
                    QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName));
                    GetAqlExpression(fromClause.FromExpression, queryModel);
                }
            }
            else
            {
                QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName));
                GetAqlExpression(fromClause.FromExpression, queryModel);
            }

            base.VisitMainFromClause(fromClause, queryModel);
        }
Пример #3
0
        public override void VisitAdditionalFromClause(AdditionalFromClause fromClause, QueryModel queryModel, int index)
        {
            var subQuery = fromClause.FromExpression as SubQueryExpression;

            if (subQuery != null)
            {
                this.DontReturn = true;
                GetAqlExpression(subQuery, queryModel, handleJoin: true);
            }
            else if (fromClause.FromExpression.Type.Name == "ArangoQueryable`1")
            {
                string fromName = LinqUtility.ResolveCollectionName(this.Db, fromClause.ItemType);
                QueryText.AppendFormat(" for {0} in {1} ", LinqUtility.ResolvePropertyName(fromClause.ItemName), fromName);
            }
            else
            {
                QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName));
                GetAqlExpression(fromClause.FromExpression, queryModel);
            }
        }
Пример #4
0
        protected override Expression VisitQuerySourceReference(QuerySourceReferenceExpression expression)
        {
            ModelVisitor.QueryText.AppendFormat(" {0}", LinqUtility.ResolvePropertyName(expression.ReferencedQuerySource.ItemName));

            var mainFromClause = expression.ReferencedQuerySource as MainFromClause;

            //  .Select(g => g.Select(gList => gList.Age)) subquery select, handle prior groupby source parameter names
            if (mainFromClause != null && mainFromClause.FromExpression.Type.Name == "IGrouping`2")
            {
                var groupByClauses = LinqUtility.PriorGroupBy(ModelVisitor);

                for (int i = 0; i < groupByClauses.Count; i++)
                {
                    ModelVisitor.QueryText.AppendFormat("{0}{1}{2}"
                                                        , i == 0 ? "." : ""
                                                        , LinqUtility.ResolvePropertyName(groupByClauses[i].FromParameterName)
                                                        , i != groupByClauses.Count - 1 ? "." : "");
                }
            }

            return(expression);
        }
Пример #5
0
        public void VisitGroupByClause(GroupByClause groupByClause, QueryModel queryModel, int index)
        {
            var parentMVisitor = LinqUtility.FindParentModelVisitor(this);

            parentMVisitor.GroupByNameCounter++;
            groupByClause.IntoName          = "C" + parentMVisitor.GroupByNameCounter;
            groupByClause.FuncIntoName      = Db.Setting.Linq.TranslateGroupByIntoName;
            groupByClause.FromParameterName = queryModel.MainFromClause.ItemName;

            QueryText.Append(" collect ");

            if (groupByClause.Selector.NodeType != ExpressionType.New)
            {
                groupByClause.CollectVariableName = "CV" + parentMVisitor.GroupByNameCounter;
                QueryText.AppendFormat(" {0} = ", LinqUtility.ResolvePropertyName(groupByClause.CollectVariableName));
            }

            GetAqlExpression(groupByClause.Selector, queryModel, true);

            QueryText.AppendFormat(" into {0} ", LinqUtility.ResolvePropertyName(groupByClause.TranslateIntoName()));

            groupByClause.Visited = true;
        }
Пример #6
0
        protected override Expression VisitParameter(ParameterExpression expression)
        {
            string name = expression.Name;

            if (expression.Type.Name == "TraversalData`2")
            {
                string prefix = LinqUtility.MemberNameFromMap(name, "graph", ModelVisitor);

                ModelVisitor.QueryText.AppendFormat(" {{ {0} : {1}, {2} : {3}, {4} : {5} }} ",
                                                    LinqUtility.ResolvePropertyName($"vertex"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                                    LinqUtility.ResolvePropertyName($"edge"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Edge"),
                                                    LinqUtility.ResolvePropertyName($"path"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Path"));

                return(expression);
            }

            if (expression.Type.Name == "ShortestPathData`2")
            {
                string prefix = LinqUtility.MemberNameFromMap(name, "graph", ModelVisitor);

                ModelVisitor.QueryText.AppendFormat(" {{ {0} : {1}, {2} : {3} }} ",
                                                    LinqUtility.ResolvePropertyName($"vertex"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                                    LinqUtility.ResolvePropertyName($"edge"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Edge"));

                return(expression);
            }

            ModelVisitor.QueryText.AppendFormat(" {0} ", LinqUtility.ResolvePropertyName(name));

            return(expression);
        }
Пример #7
0
        public void VisitTraversalClause(ITraversalClause traversalClause, QueryModel queryModel, int index)
        {
            string prefix = LinqUtility.MemberNameFromMap(traversalClause.Identifier, "graph", this);

            if (traversalClause.TargetVertex != null)
            {
                QueryText.AppendFormat(" for {0}, {1} in ",
                                       LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                       LinqUtility.ResolvePropertyName($"{prefix}_Edge"));
            }
            else
            {
                QueryText.AppendFormat(" for {0}, {1}, {2} in ",
                                       LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                       LinqUtility.ResolvePropertyName($"{prefix}_Edge"),
                                       LinqUtility.ResolvePropertyName($"{prefix}_Path"));
            }

            if (traversalClause.Min != null && traversalClause.Max != null)
            {
                QueryText.AppendFormat(" {0}..{1} ", traversalClause.Min.Value, traversalClause.Max);
            }

            QueryText.AppendFormat(" {0} ", traversalClause.Direction != null
                ? traversalClause.Direction.Value
                : Utils.EdgeDirectionToString(EdgeDirection.Any));

            if (traversalClause.TargetVertex != null)
            {
                QueryText.Append(" shortest_path ");
                GetAqlExpression(traversalClause.StartVertex, queryModel);
                QueryText.Append(" to ");
                GetAqlExpression(traversalClause.TargetVertex, queryModel);
            }
            else
            {
                GetAqlExpression(traversalClause.StartVertex, queryModel);
            }

            if (string.IsNullOrEmpty(traversalClause.GraphName) == false)
            {
                QueryText.AppendFormat("  graph \"{0}\" ", traversalClause.GraphName);
            }
            else
            {
                StringBuilder edges = new StringBuilder();

                for (int i = 0; i < traversalClause.EdgeCollections.Count; i++)
                {
                    var e = traversalClause.EdgeCollections[i];

                    if (i != 0)
                    {
                        edges.Append(", ");
                    }

                    if (e.Direction.HasValue)
                    {
                        edges.AppendFormat("{0} ", Utils.EdgeDirectionToString(e.Direction.Value));
                    }

                    edges.Append(LinqUtility.ResolvePropertyName(e.CollectionName));
                }

                QueryText.Append(edges);
            }

            if (traversalClause.Options != null)
            {
                QueryText.AppendFormat(" options {0} ", new DocumentSerializer(Db).SerializeWithoutReader(traversalClause.Options.Value));
            }
        }
Пример #8
0
        public void VisitUpdateReplaceClause(UpdateReplaceClause updateReplaceClause, QueryModel queryModel)
        {
            if (updateReplaceClause.KeySelector != null)
            {
                QueryText.AppendFormat(" {0} ", updateReplaceClause.Command);

                GetAqlExpression(updateReplaceClause.KeySelector, queryModel);

                QueryText.AppendFormat(" with ");
            }
            else
            {
                QueryText.AppendFormat(" {0} {1} with ", updateReplaceClause.Command, LinqUtility.ResolvePropertyName(updateReplaceClause.ItemName));
            }

            GetAqlExpression(updateReplaceClause.WithSelector, queryModel);

            QueryText.AppendFormat(" in {0} ", LinqUtility.ResolveCollectionName(Db, updateReplaceClause.CollectionType));
        }