Пример #1
0
 private static void CopyPropertyValue(this Dictionary <string, object> toEntityProperties,
                                       Dictionary <string, object> fromEntityProperties,
                                       SelectDefinition select)
 {
     toEntityProperties[select.FieldName] =
         fromEntityProperties[select.JoinedFieldName];
 }
Пример #2
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            var aSelectNode = (SelectNode)parseNode.ChildNodes[0].AstNode;

            SelectDefinition = new SelectDefinition(aSelectNode.TypeList, aSelectNode.SelectedElements, aSelectNode.WhereExpressionDefinition,
                                                    aSelectNode.GroupByIDs, aSelectNode.Having, aSelectNode.Limit, aSelectNode.Offset, aSelectNode.OrderByDefinition, aSelectNode.ResolutionDepth);
        }
Пример #3
0
        public IQueryResult ExecuteSelect(SecurityToken mySecurityToken, Int64 myTransactionToken, SelectDefinition selectDefinition, String myQuery)
        {
            #region Data

            List <String> alreadyUsedTypes = new List <string>();
            Stopwatch     sw = Stopwatch.StartNew();

            #endregion

            #region Resolve types

            Dictionary <String, IVertexType> typeList = ResolveTypes(selectDefinition.TypeList, mySecurityToken, myTransactionToken);

            #endregion

            #region Create SelectResultManager which will do the lazy select

            var selectResultManager = CreateResultManager(mySecurityToken, myTransactionToken, selectDefinition, typeList);

            #endregion

            #region Get an expressiongraph if a whereExpression exists

            IExpressionGraph exprGraph;

            if (selectDefinition.WhereExpressionDefinition != null)
            {
                exprGraph = GetExpressionGraphFromWhere(selectDefinition.WhereExpressionDefinition, mySecurityToken, myTransactionToken);

                selectResultManager.ExpressionGraph = exprGraph;
            }

            #endregion

            List <IEnumerable <IVertexView> > _ListOfVertices1 = CreateVertices(mySecurityToken, myTransactionToken, typeList, selectResultManager, selectDefinition.WhereExpressionDefinition, selectDefinition.ResolutionDepth, selectDefinition.OrderByDefinition, selectDefinition.Limit, selectDefinition.Offset);

            #region TypeIndependendResults

            var _ListOfVertices2 = selectResultManager.GetTypeIndependendResult(mySecurityToken, myTransactionToken);
            if (_ListOfVertices2.CountIsGreater(0))
            {
                _ListOfVertices1.Add(_ListOfVertices2);
            }

            #endregion

            sw.Stop();

            return(QueryResult.Success(myQuery, SonesGQLConstants.GQL, AggregateListOfVertices(_ListOfVertices1), Convert.ToUInt64(sw.Elapsed.TotalMilliseconds)));
        }
Пример #4
0
        /// <summary>
        /// Creates the result manager and adds all selected elements
        /// </summary>
        private SelectResultManager CreateResultManager(SecurityToken mySecurityToken, Int64 myTransactionToken, SelectDefinition selectDefinition, Dictionary <String, IVertexType> myTypeList)
        {
            var _SelectResultManager = new SelectResultManager(_graphdb, _pluginManager);

            foreach (var selection in selectDefinition.SelectedElements)
            {
                #region Add all selection elements to SelectResultManager

                if (selection.Item1 is IDChainDefinition)
                {
                    #region IDChainDefinition

                    var idChainSelection = (selection.Item1 as IDChainDefinition);

                    idChainSelection.Validate(_pluginManager, _graphdb, mySecurityToken, myTransactionToken, true);

                    if (idChainSelection.SelectType != TypesOfSelect.None)
                    {
                        #region Asterisk, Minus, Rhomb, Ad

                        //there's no limitation
                        foreach (var typeRef in myTypeList)
                        {
                            if (idChainSelection.TypeName != null)
                            {
                                var type = _graphdb.GetVertexType(
                                    mySecurityToken,
                                    myTransactionToken,
                                    new RequestGetVertexType(idChainSelection.TypeName),
                                    (stats, vType) => vType);

                                if (type == null)
                                {
                                    throw new VertexTypeDoesNotExistException(idChainSelection.TypeName, "");
                                }

                                Int64 typeID = type.ID;
                                _SelectResultManager.AddSelectionType(typeRef.Key, typeRef.Value, idChainSelection.SelectType, typeID);
                            }
                            else
                            {
                                _SelectResultManager.AddSelectionType(typeRef.Key, typeRef.Value, idChainSelection.SelectType);
                            }
                        }

                        #endregion

                        continue;
                    }

                    #region Either IDNode or parameterless function

                    if (idChainSelection.Reference == null)
                    { /// this might be a parameterless function without a calling attribute
                        _SelectResultManager.AddElementToSelection(selection.Item2, null, idChainSelection, false);
                    }
                    else //if (!(aColumnItemNode.ColumnSourceValue is AggregateNode))
                    {
                        IVertexType theType   = null;
                        String      reference = idChainSelection.Reference.Item1;
                        // this will happen, if the user selected FROM User u SELECT Name
                        if (!myTypeList.ContainsKey(reference))
                        {
                            // if there is only one type, than we can treat this as the reference
                            if (myTypeList.Count == 1)
                            {
                                theType = myTypeList.First().Value;
                            }
                            else
                            {
                                throw new Exception("Missing type reference for " + reference);
                            }
                        }
                        else
                        {
                            theType = myTypeList[reference];
                        }

                        //if (theType != null && theType.GetAncestorVertexTypesAndSelf().Select(x => x.ID).Contains(idChainSelection.LastAttribute.RelatedType.ID))
                        //    reference = theType.GetAncestorVertexTypesAndSelf().Where(x => x.ID == idChainSelection.LastAttribute.RelatedType.ID).First().Name;

                        if (idChainSelection.SelectType != TypesOfSelect.None)
                        {
                            _SelectResultManager.AddSelectionType(reference, theType, idChainSelection.SelectType);
                        }
                        else
                        {
                            _SelectResultManager.AddElementToSelection(selection.Item2, reference, idChainSelection, false, selection.Item3);
                        }
                        //else
                        //{
                        //    return new Exceptional<SelectResultManager>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                        //}
                    }
                    #endregion

                    #endregion
                }

                else if (selection.Item1 is AggregateDefinition)
                {
                    #region Aggregate

                    var aggregateSelection = selection.Item1 as AggregateDefinition;

                    aggregateSelection.ChainPartAggregateDefinition.Validate(_pluginManager, _graphdb, mySecurityToken, myTransactionToken);

                    var selPartAggr = new SelectionElementAggregate(aggregateSelection.ChainPartAggregateDefinition.Aggregate, selection.Item2,
                                                                    new EdgeList(aggregateSelection.ChainPartAggregateDefinition.Parameter.Edges), new LevelKey(aggregateSelection.ChainPartAggregateDefinition.Parameter.Edges, _graphdb, mySecurityToken, myTransactionToken),
                                                                    aggregateSelection.ChainPartAggregateDefinition.Parameter, aggregateSelection);

                    _SelectResultManager.AddAggregateElementToSelection(mySecurityToken, myTransactionToken, selection.Item2, aggregateSelection.ChainPartAggregateDefinition.Parameter.Reference.Item1, selPartAggr);


                    #endregion
                }

                else
                {
                    throw new NotImplementedQLException("");
                }

                #endregion
            }

            #region Add groupings

            if (selectDefinition.GroupByIDs.IsNotNullOrEmpty())
            {
                foreach (var group in selectDefinition.GroupByIDs)
                {
                    group.Validate(_pluginManager, _graphdb, mySecurityToken, myTransactionToken, true);

                    _SelectResultManager.AddGroupElementToSelection(group.Reference.Item1, group);
                }
            }

            #endregion

            #region Add having

            if (selectDefinition.Having != null)
            {
                selectDefinition.Having.Validate(_pluginManager, _graphdb, mySecurityToken, myTransactionToken);

                _SelectResultManager.AddHavingToSelection(selectDefinition.Having);
            }

            #endregion

            return(_SelectResultManager);
        }