public DescribeSettingDefinition(TypesSettingScope? mySettingType, String mySettingName = null, String myTypeName = null, IDChainDefinition myIDChain = null)
 {
     _SettingType = mySettingType;
     _SettingName = mySettingName;
     _SettingTypeName = myTypeName;
     _SettingAttribute = myIDChain;
 }
Exemple #2
0
 public SelectionElement(string myAlias, Select.EdgeList myEdgeList, bool myIsGroupedOrAggregated, IDChainDefinition myRelatedIDChainDefinition, IAttributeDefinition myElement = null)
     : this(myAlias, myRelatedIDChainDefinition)
 {
     EdgeList = myEdgeList;
     IsGroupedOrAggregated = myIsGroupedOrAggregated;
     Element = myElement;
 }
Exemple #3
0
        public void Init(ParsingContext context, ParseTreeNode myParseTreeNode)
        {
            if (HasChildNodes(myParseTreeNode.ChildNodes[0]))
            {
                if (myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode is IDNode)
                {
                    _IndexAttribute = (myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode as IDNode).IDChainDefinition;
                }
                else
                {
                    throw new NotImplementedQLException(myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode.GetType().ToString());
                }
            }

            if (myParseTreeNode.ChildNodes.Count > 1 && HasChildNodes(myParseTreeNode.ChildNodes[1]))
            {
                _OrderDirection = myParseTreeNode.ChildNodes[1].FirstChild.Token.ValueString;
            }
            else
            {
                _OrderDirection = String.Empty;
            }
            #region index attribute validation

            if (_IndexAttribute.Count() > 2)
            {
                throw new NotImplementedQLException("Only one attribute and one optional function are allowed! e.g. Name.TOUPPER()");
            }

            #endregion

            IndexAttributeDefinition = new IndexAttributeDefinition(_IndexAttribute, _IndexType, _OrderDirection);
        }
Exemple #4
0
        public void GetContent(CompilerContext myCompilerContext, ParseTreeNode myParseTreeNode)
        {
            if (myParseTreeNode.ChildNodes[0].HasChildNodes())
            {

                if (myParseTreeNode.ChildNodes[0].ChildNodes[0].ChildNodes.Count > 1)
                {

                    _IndexType = ((ATypeNode)myParseTreeNode.ChildNodes[0].ChildNodes[0].ChildNodes[0].AstNode).ReferenceAndType.TypeName;
                    _IndexAttribute = ((IDNode)myParseTreeNode.ChildNodes[0].ChildNodes[0].ChildNodes[2].AstNode).IDChainDefinition;

                }

                else
                {
                    //_IndexAttribute = myParseTreeNode.ChildNodes[0].ChildNodes[0].Token.ValueString;
                    _IndexAttribute = new IDChainDefinition();
                    _IndexAttribute.AddPart(new ChainPartTypeOrAttributeDefinition(myParseTreeNode.ChildNodes[0].ChildNodes[0].Token.ValueString));
                }

            }

            if (myParseTreeNode.ChildNodes.Count > 1 && myParseTreeNode.ChildNodes[1].HasChildNodes())
            {
                _OrderDirection = myParseTreeNode.ChildNodes[1].FirstChild.Token.ValueString;
            }
            else
            {
                _OrderDirection = String.Empty;
            }

            IndexAttributeDefinition = new IndexAttributeDefinition(_IndexAttribute, _IndexType, _OrderDirection);
        }
 public AttributeRemoveList(IDChainDefinition myIDChainDefinition, string myAttributeName, Object myTupleDefinition)
 {
     // TODO: Complete member initialization
     this.AttributeIDChain = myIDChainDefinition;
     this.AttributeName    = myAttributeName;
     this.TupleDefinition  = myTupleDefinition;
 }
Exemple #6
0
 public AttributeRemoveList(IDChainDefinition myIDChainDefinition, string myAttributeName, TupleDefinition myTupleDefinition)
 {
     // TODO: Complete member initialization
     this.AttributeIDChain = myIDChainDefinition;
     this.AttributeName = myAttributeName;
     this.TupleDefinition = myTupleDefinition;
 }
        private static LevelKey CreateLevelKey(IDChainDefinition myIDChainDefinition, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            if (myIDChainDefinition.Level == 0)
            {
                return(new LevelKey(new List <EdgeKey>()
                {
                    new EdgeKey(myIDChainDefinition.Edges[0].VertexTypeID)
                }, myGraphDB, mySecurityToken, myTransactionToken));
            }
            else
            {
                if (myIDChainDefinition.Last() is ChainPartFuncDefinition)
                {
                    // the funtion in the last idnode part processes the last attribute

                    if (myIDChainDefinition.Level == 1)
                    {
                        return(new LevelKey(new List <EdgeKey>()
                        {
                            new EdgeKey(myIDChainDefinition.Edges[0].VertexTypeID)
                        }, myGraphDB, mySecurityToken, myTransactionToken));
                    }
                    else
                    {
                        return(new LevelKey(myIDChainDefinition.Edges.Take(myIDChainDefinition.Level - 1), myGraphDB, mySecurityToken, myTransactionToken));
                    }
                }
                else
                {
                    return(new LevelKey(myIDChainDefinition.Edges.Take(myIDChainDefinition.Level), myGraphDB, mySecurityToken, myTransactionToken));
                }
            }
        }
 /// <summary>
 /// This method gets the associativity of a binary expression.
 /// </summary>
 /// <param name="leftIDNode">Left IDNode.</param>
 /// <param name="rightIDNode">Right IDNode.</param>
 /// <returns>The associativity</returns>
 private TypesOfAssociativity GetAssociativityReloaded(IDChainDefinition leftIDNode, IDChainDefinition rightIDNode)
 {
     if (leftIDNode != null && rightIDNode != null)
     {
         if (leftIDNode.Reference == rightIDNode.Reference)
         {
             return(TypesOfAssociativity.Neutral);
         }
         else
         {
             return(TypesOfAssociativity.Unknown);
         }
     }
     else
     {
         if (leftIDNode != null)
         {
             return(TypesOfAssociativity.Left);
         }
         else
         {
             if (rightIDNode != null)
             {
                 return(TypesOfAssociativity.Right);
             }
             else
             {
                 return(TypesOfAssociativity.Neutral);
             }
         }
     }
 }
Exemple #9
0
        public IDNode(IVertexType myType, String myReference)
        {
            IDChainDefinition = new IDChainDefinition();
            IDChainDefinition.AddPart(new ChainPartTypeOrAttributeDefinition(myType.Name));
            var listOfRefs = new Dictionary <String, IVertexType>();

            listOfRefs.Add(myReference, myType);
        }
Exemple #10
0
        public IDNode(IVertexType myType, String myReference)
        {

            IDChainDefinition = new IDChainDefinition();
            IDChainDefinition.AddPart(new ChainPartTypeOrAttributeDefinition(myType.Name));
            var listOfRefs = new Dictionary<String, IVertexType>();
            listOfRefs.Add(myReference, myType);

        }
Exemple #11
0
 public SelectionElementAggregate(IGQLAggregate myBaseAggregate, string myAlias, EdgeList myEdgeList, LevelKey myLevelKey, IDChainDefinition myRelatedIDChainDefinition, AggregateDefinition myAggregateDefinition)
 {
     Alias                    = myAlias;
     EdgeList                 = myEdgeList;
     LevelKey                 = myLevelKey;
     Aggregate                = myBaseAggregate;
     AggregateDefinition      = myAggregateDefinition;
     RelatedIDChainDefinition = myRelatedIDChainDefinition;
 }
Exemple #12
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            ExtractIDNodeString(parseNode);

            IDChainDefinition = new IDChainDefinition(_IDNodeString, GetTypeReferenceDefinitions(context));

            foreach (var child in parseNode.ChildNodes)
            {

                if (child.AstNode is EdgeTraversalNode)
                {

                    #region EdgeTraversalNode

                    var edgeTraversal = (child.AstNode as EdgeTraversalNode);
                    if (edgeTraversal.FuncCall != null)
                    {
                        IDChainDefinition.AddPart(edgeTraversal.FuncCall.FuncDefinition, new IDChainDelemiter(edgeTraversal.Delimiter.GetKindOfDelimiter()));
                    }
                    else
                    {
                        IDChainDefinition.AddPart(new ChainPartTypeOrAttributeDefinition(edgeTraversal.AttributeName), new IDChainDelemiter(edgeTraversal.Delimiter.GetKindOfDelimiter()));
                    }

                    #endregion

                }

                else if (child.AstNode is EdgeInformationNode)
                {

                    #region EdgeInformation

                    var aEdgeInformation = (EdgeInformationNode)child.AstNode;

                    throw new NotImplementedQLException("Start here integrating edgeinfos");

                    #endregion

                }

                else if (child.AstNode is FuncCallNode)
                {
                    IDChainDefinition.AddPart((child.AstNode as FuncCallNode).FuncDefinition);
                }

                else
                {
                    IDChainDefinition.AddPart(new ChainPartTypeOrAttributeDefinition(child.Token.ValueString));
                }

            }
        }
Exemple #13
0
        public void GetContent(CompilerContext context, ParseTreeNode parseNode)
        {
            System.Diagnostics.Debug.Assert(parseNode.Span.Start.Line == 0);

            _SourceParsedString = context.CurrentParseTree.SourceText.Substring(parseNode.Span.Start.Position, parseNode.Span.Length);

            _FuncName = parseNode.ChildNodes[0].Token.ValueString.ToUpper();

            FuncDefinition = new ChainPartFuncDefinition(); // new
            FuncDefinition.SourceParsedString = _SourceParsedString; // new
            FuncDefinition.FuncName = _FuncName; // new

            #region Retrieve the parameters

            if (parseNode.ChildNodes.Count > 1)// && parseNode.ChildNodes[1].HasChildNodes())
            {

                if (parseNode.ChildNodes[1].Token != null)
                {
                    if (parseNode.ChildNodes[1].Token.Terminal.DisplayName == "*")
                    {
                        #region asterisk

                        if (GetTypeReferenceDefinitions(context).Count != 1)
                        {
                            throw new GraphDBException(new Error_FunctionParameterInvalidReference(("It is not allowed to execute a function with an asterisk as parameter and more than one type.")));
                        }

                        var listOfReferences = GetTypeReferenceDefinitions(context);
                        var idChainDef = new IDChainDefinition(listOfReferences.First().TypeName, listOfReferences);

                        FuncDefinition.Parameters.Add(idChainDef); // new

                        #endregion
                    }
                    else
                    {
                        GenerateData(context, parseNode.ChildNodes.Skip(1).ToList());
                    }
                }
                else
                {
                    GenerateData(context, parseNode.ChildNodes.Skip(1).ToList());
                }
            }
            else if (parseNode.ChildNodes.Count > 1)
            {
                GenerateData(context, parseNode.ChildNodes.Skip(1).ToList());
            }

            #endregion
        }
Exemple #14
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            System.Diagnostics.Debug.Assert(parseNode.Span.Location.Line == 0);

            _SourceParsedString = context.CurrentParseTree.SourceText.Substring(parseNode.Span.Location.Position, parseNode.Span.Length);

            _FuncName = parseNode.ChildNodes[0].Token.ValueString.ToUpper();

            FuncDefinition = new ChainPartFuncDefinition();          // new
            FuncDefinition.SourceParsedString = _SourceParsedString; // new
            FuncDefinition.FuncName           = _FuncName;           // new

            #region Retrieve the parameters

            if (parseNode.ChildNodes.Count > 1)// && parseNode.ChildNodes[1].HasChildNodes())
            {
                if (parseNode.ChildNodes[1].Token != null)
                {
                    if (parseNode.ChildNodes[1].Token.Terminal.Name == "*")
                    {
                        #region asterisk

                        if (GetTypeReferenceDefinitions(context).Count != 1)
                        {
                            throw new FunctionParameterInvalidReferenceException("It is not allowed to execute a function with an asterisk as parameter and more than one type.");
                        }

                        var listOfReferences = GetTypeReferenceDefinitions(context);
                        var idChainDef       = new IDChainDefinition(listOfReferences.First().TypeName, listOfReferences);

                        FuncDefinition.Parameters.Add(idChainDef); // new

                        #endregion
                    }
                    else
                    {
                        GenerateData(context, parseNode.ChildNodes.Skip(1).ToList());
                    }
                }
                else
                {
                    GenerateData(context, parseNode.ChildNodes.Skip(1).ToList());
                }
            }
            else if (parseNode.ChildNodes.Count > 1)
            {
                GenerateData(context, parseNode.ChildNodes.Skip(1).ToList());
            }

            #endregion
        }
Exemple #15
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            ExtractIDNodeString(parseNode);

            IDChainDefinition = new IDChainDefinition(_IDNodeString, GetTypeReferenceDefinitions(context));

            foreach (var child in parseNode.ChildNodes)
            {
                if (child.AstNode is EdgeTraversalNode)
                {
                    #region EdgeTraversalNode

                    var edgeTraversal = (child.AstNode as EdgeTraversalNode);
                    if (edgeTraversal.FuncCall != null)
                    {
                        IDChainDefinition.AddPart(edgeTraversal.FuncCall.FuncDefinition, new IDChainDelemiter(edgeTraversal.Delimiter.GetKindOfDelimiter()));
                    }
                    else
                    {
                        IDChainDefinition.AddPart(new ChainPartTypeOrAttributeDefinition(edgeTraversal.AttributeName), new IDChainDelemiter(edgeTraversal.Delimiter.GetKindOfDelimiter()));
                    }

                    #endregion
                }

                else if (child.AstNode is EdgeInformationNode)
                {
                    #region EdgeInformation

                    var aEdgeInformation = (EdgeInformationNode)child.AstNode;

                    throw new NotImplementedQLException("Start here integrating edgeinfos");

                    #endregion
                }

                else if (child.AstNode is FuncCallNode)
                {
                    IDChainDefinition.AddPart((child.AstNode as FuncCallNode).FuncDefinition);
                }

                else
                {
                    IDChainDefinition.AddPart(new ChainPartTypeOrAttributeDefinition(child.Token.ValueString));
                }
            }
        }
Exemple #16
0
        public override void GetContent(CompilerContext myCompilerContext, ParseTreeNode myParseTreeNode)
        {
            _IDChainDefinitions = new List<IDChainDefinition>();

            _TypeReferenceDefinitions = (myParseTreeNode.ChildNodes[1].AstNode as TypeListNode).Types;

            if (myParseTreeNode.ChildNodes[3].HasChildNodes())
            {
                IDNode tempIDNode;
                foreach (var _ParseTreeNode in myParseTreeNode.ChildNodes[3].ChildNodes[0].ChildNodes)
                {
                    if (_ParseTreeNode.AstNode is IDNode)
                    {
                        tempIDNode = (IDNode)_ParseTreeNode.AstNode;
                        _IDChainDefinitions.Add(tempIDNode.IDChainDefinition);
                    }
                }
            }
            else
            {
                foreach (var type in _TypeReferenceDefinitions)
                {
                    var def = new IDChainDefinition();
                    def.AddPart(new ChainPartTypeOrAttributeDefinition(type.Reference));
                    _IDChainDefinitions.Add(def);
                }
            }

            #region whereClauseOpt

            if (myParseTreeNode.ChildNodes[4].HasChildNodes())
            {
                WhereExpressionNode tempWhereNode = (WhereExpressionNode)myParseTreeNode.ChildNodes[4].AstNode;
                _WhereExpression = tempWhereNode.BinaryExpressionDefinition;

            }

            #endregion
        }
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region get myAttributeName

            _AttributeIDNode = ((IDNode)parseNode.ChildNodes[0].AstNode).IDChainDefinition;

            #endregion

            var _Node = parseNode.ChildNodes[2];

            if ((_Node.AstNode is CollectionOfEdgesNode))
            {
                #region collection like list

                AttributeValue = new AttributeAssignOrUpdateList((_Node.AstNode as CollectionOfEdgesNode).CollectionDefinition, _AttributeIDNode, true);

                #endregion
            }
            else
            {
                throw new NotImplementedQLException("");
            }
        }
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region get myAttributeName

            _AttributeIDNode = ((IDNode)parseNode.ChildNodes[0].AstNode).IDChainDefinition;

            #endregion

            var _Node = parseNode.ChildNodes[2];

            if ((_Node.AstNode is CollectionOfEdgesNode))
            {
                #region collection like list

                AttributeValue = new AttributeAssignOrUpdateList((_Node.AstNode as CollectionOfEdgesNode).CollectionDefinition, _AttributeIDNode, true);

                #endregion
            }
            else
            {
                throw new NotImplementedQLException("");
            }
        }
        public void Init(ParsingContext context, ParseTreeNode myParseTreeNode)
        {
            if (HasChildNodes(myParseTreeNode.ChildNodes[0]))
            {

                if (myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode is IDNode)
                {
                    _IndexAttribute = (myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode as IDNode).IDChainDefinition;
                }
                else
                {
                    throw new NotImplementedQLException(myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode.GetType().ToString());
                }

            }

            if (myParseTreeNode.ChildNodes.Count > 1 && HasChildNodes(myParseTreeNode.ChildNodes[1]))
            {
                _OrderDirection = myParseTreeNode.ChildNodes[1].FirstChild.Token.ValueString;
            }
            else
            {
                _OrderDirection = String.Empty;
            }
            #region index attribute validation

            if (_IndexAttribute.Count() > 2)
            {
                throw new NotImplementedQLException("Only one attribute and one optional function are allowed! e.g. Name.TOUPPER()");
            }

            #endregion

            IndexAttributeDefinition = new IndexAttributeDefinition(_IndexAttribute, _IndexType, _OrderDirection);

        }
Exemple #20
0
        public void GetContent(CompilerContext myCompilerContext, ParseTreeNode myParseTreeNode)
        {
            if (myParseTreeNode.ChildNodes[0].HasChildNodes())
            {

                if (myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode is IDNode)
                {
                    _IndexAttribute = (myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode as IDNode).IDChainDefinition;
                    ParsingResult.PushIExceptional((myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode as IDNode).ParsingResult);
                }
                else
                {
                    ParsingResult.PushIError(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), myParseTreeNode.ChildNodes[0].ChildNodes[0].AstNode .GetType().ToString()));
                }

            }

            if (myParseTreeNode.ChildNodes.Count > 1 && myParseTreeNode.ChildNodes[1].HasChildNodes())
            {
                _OrderDirection = myParseTreeNode.ChildNodes[1].FirstChild.Token.ValueString;
            }
            else
            {
                _OrderDirection = String.Empty;
            }
            #region index attribute validation

            if (_IndexAttribute.Count() > 2)
            {
                ParsingResult.PushIError(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "Only one attribute and one optional function are allowed! e.g. Name.TOUPPER()"));
            }

            #endregion

            IndexAttributeDefinition = new IndexAttributeDefinition(_IndexAttribute, _IndexType, _OrderDirection);
        }
 public IndexAttributeDefinition(IDChainDefinition myIndexAttribute, string myIndexType, string myOrderDirection)
 {
     IndexAttribute = myIndexAttribute;
     IndexType      = myIndexType;
     OrderDirection = myOrderDirection;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="myCollectionDefinition"></param>
 /// <param name="iDChainDefinition"></param>
 /// <param name="myAssign">True to assign, False to update</param>
 public AttributeAssignOrUpdateList(CollectionDefinition myCollectionDefinition, IDChainDefinition iDChainDefinition, Boolean myAssign)
 {
     CollectionDefinition = myCollectionDefinition;
     AttributeIDChain = iDChainDefinition;
     Assign = myAssign;
 }
Exemple #23
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            _Sources = new HashSet <AAttributeAssignOrUpdateOrRemove>();

            #region VIA edge

            IDNode _EdgeAttr = null;

            if (parseNode.ChildNodes[4].AstNode is IDNode) //Semantic Web Yoda style
            {
                _EdgeAttr = (parseNode.ChildNodes[4].AstNode as IDNode);
            }
            else //Human language style
            {
                _EdgeAttr = (parseNode.ChildNodes[6].AstNode as IDNode);
            }

            #endregion

            #region sources

            var typeNode = ((ATypeNode)parseNode.ChildNodes[1].AstNode).ReferenceAndType.TypeName;

            var tupleDef = (parseNode.ChildNodes[2].AstNode as TupleNode).TupleDefinition;

            var tupleDefSourceType = new TupleDefinition(tupleDef.KindOfTuple);

            _TargetType = typeNode;

            foreach (var item in tupleDef.TupleElements)
            {
                var attrName = typeNode + SonesGQLConstants.EdgeTraversalDelimiterSymbol + ((IDChainDefinition)((BinaryExpressionDefinition)item.Value).Left).ContentString;
                var leftNode = new IDChainDefinition(attrName, new List <TypeReferenceDefinition>()
                {
                    new TypeReferenceDefinition(typeNode, typeNode)
                });
                leftNode.AddPart(new ChainPartTypeOrAttributeDefinition(((IDChainDefinition)((BinaryExpressionDefinition)item.Value).Left).ContentString));
                var rightNode = ((BinaryExpressionDefinition)item.Value).Right;

                var binExpression = new BinaryExpressionDefinition(((BinaryExpressionDefinition)item.Value).OperatorSymbol, leftNode, rightNode);

                tupleDefSourceType.AddElement(new TupleElement(binExpression));
            }

            _Sources.Add(new AttributeRemoveList(_EdgeAttr.IDChainDefinition, _EdgeAttr.IDChainDefinition.ContentString, tupleDefSourceType));

            #endregion

            #region sources FROM

            if (parseNode.ChildNodes[6].ChildNodes[0].AstNode is ATypeNode)  //Semantic Web Yoda style
            {
                typeNode = ((ATypeNode)parseNode.ChildNodes[6].ChildNodes[0].AstNode).ReferenceAndType.TypeName;
                _Targets = (parseNode.ChildNodes[6].ChildNodes[1].AstNode as TupleNode).TupleDefinition;
            }
            else  //Human language style
            {
                typeNode = ((ATypeNode)parseNode.ChildNodes[4].ChildNodes[0].AstNode).ReferenceAndType.TypeName;
                _Targets = (parseNode.ChildNodes[4].ChildNodes[1].AstNode as TupleNode).TupleDefinition;
            }

            _SourceType = typeNode;

            if (_Targets.Count() > 1)
            {
                var firstElement = (BinaryExpressionDefinition)_Targets.First().Value;
                _Targets.Remove(_Targets.First());

                _Condition = GetConditionNode("OR", firstElement, _Targets);
            }
            else
            {
                _Condition = (BinaryExpressionDefinition)_Targets.First().Value;
            }

            #endregion
        }
 public AAttributeAssignOrUpdate(IDChainDefinition myIDChainDefinition)
 {
     AttributeIDChain = myIDChainDefinition;
 }
Exemple #25
0
        private static LevelKey CreateLevelKey(IDChainDefinition myIDChainDefinition, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            if (myIDChainDefinition.Level == 0)
            {
                return new LevelKey(new List<EdgeKey>() { new EdgeKey(myIDChainDefinition.Edges[0].VertexTypeID) }, myGraphDB, mySecurityToken, myTransactionToken);
            }
            else
            {
                if (myIDChainDefinition.Last() is ChainPartFuncDefinition)
                {
                    // the funtion in the last idnode part processes the last attribute

                    if (myIDChainDefinition.Level == 1)
                    {
                        return new LevelKey(new List<EdgeKey>() { new EdgeKey(myIDChainDefinition.Edges[0].VertexTypeID) }, myGraphDB, mySecurityToken, myTransactionToken);
                    }
                    else
                    {
                        return new LevelKey(myIDChainDefinition.Edges.Take(myIDChainDefinition.Level - 1), myGraphDB, mySecurityToken, myTransactionToken);
                    }
                }
                else
                {
                    return new LevelKey(myIDChainDefinition.Edges.Take(myIDChainDefinition.Level), myGraphDB, mySecurityToken, myTransactionToken);
                }
            }
        }
Exemple #26
0
        private Exceptional<Boolean> GetComplexMatch(IEnumerable<Tuple<GraphDBType, AAttributeIndex>> myIDX, Dictionary<DBObjectStream, AOperationDefinition> operands, DBObjectCache dbObjectCache, IDChainDefinition primIDNode, IDChainDefinition operandIDNode, DBContext dbContext, TypesOfAssociativity associativity, ref IExpressionGraph resultGraph, SessionSettings mySessionToken)
        {
            LevelKey primLevelKey = CreateLevelKey(primIDNode, dbContext.DBTypeManager);
            LevelKey operandLevelKey = CreateLevelKey(operandIDNode, dbContext.DBTypeManager);

            foreach (var aIDX in myIDX)
            {
                if (aIDX.Item2.IsUUIDIndex)
                {
                    #region UUID idx

                    var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(aIDX.Item2.IndexRelatedTypeUUID);

                    foreach (var aOperand in operands)
                    {

                        foreach (var _ObjectUUIDs in ((UUIDIndex)aIDX.Item2).GetAllUUIDs(currentIndexRelatedType, dbContext))
                        {
                            var DBObjectStream = dbObjectCache.LoadDBObjectStream(aIDX.Item1, _ObjectUUIDs);
                            if (DBObjectStream.Failed())
                            {
                                return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                            }

                            if (IsValidDBObjectStreamForBinExpr(DBObjectStream.Value, primIDNode.LastAttribute, dbContext.DBTypeManager))
                            {
                                var aCtype = GraphDBTypeMapper.ConvertGraph2CSharp(primIDNode.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);
                                IObject dbos = GetDbos(primIDNode, DBObjectStream.Value, dbContext, mySessionToken, dbObjectCache);

                                Exceptional<AOperationDefinition> tempResult;
                                if (aCtype == BasicType.SetOfDBObjects)
                                {
                                    tempResult = this.SimpleOperation(new TupleDefinition(aCtype, dbos, primIDNode.LastAttribute.GetDBType(dbContext.DBTypeManager)), aOperand.Value, TypesOfBinaryExpression.Complex);
                                }
                                else
                                {
                                    tempResult = this.SimpleOperation(new ValueDefinition(aCtype, dbos), aOperand.Value, TypesOfBinaryExpression.Complex);

                                }

                                if (tempResult.Failed())
                                    return new Exceptional<bool>(tempResult);

                                var tempOperatorResult = ((ValueDefinition)tempResult.Value);

                                if ((Boolean)tempOperatorResult.Value.Value)
                                {
                                    switch (associativity)
                                    {
                                        case TypesOfAssociativity.Neutral:
                                        case TypesOfAssociativity.Left:

                                            IntegrateInGraph(aOperand.Key, resultGraph, operandLevelKey, dbContext, dbObjectCache);

                                            break;
                                        case TypesOfAssociativity.Right:

                                            IntegrateInGraph(DBObjectStream.Value, resultGraph, primLevelKey, dbContext, dbObjectCache);

                                            break;
                                        default:

                                            return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                }
                else
                {
                    return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                }
            }

            return new Exceptional<bool>(true);
        }
Exemple #27
0
        private LevelKey CreateLevelKey(IDChainDefinition myIDChainDefinition, DBTypeManager myTypeManager)
        {
            if (myIDChainDefinition.Level == 0)
            {
                return new LevelKey(new List<EdgeKey>() { new EdgeKey(myIDChainDefinition.Edges[0].TypeUUID, null) }, myTypeManager);
            }
            else
            {
                if (myIDChainDefinition.Last() is ChainPartFuncDefinition)
                {
                    // the funtion in the last idnode part processes the last attribute

                    if (myIDChainDefinition.Level == 1)
                    {
                        return new LevelKey(new List<EdgeKey>() { new EdgeKey(myIDChainDefinition.Edges[0].TypeUUID, null) }, myTypeManager);
                    }
                    else
                    {
                        return new LevelKey(myIDChainDefinition.Edges.Take(myIDChainDefinition.Level - 1), myTypeManager);
                    }
                }
                else
                {
                    return new LevelKey(myIDChainDefinition.Edges.Take(myIDChainDefinition.Level), myTypeManager);
                }
            }
        }
Exemple #28
0
        /// <summary>
        /// Single IDNode selection attribute
        /// </summary>
        /// <param name="myReference"></param>
        /// <param name="myAlias"></param>
        /// <param name="myAStructureNode"></param>
        /// <param name="myGraphType"></param>
        public Exceptional AddElementToSelection(string myAlias, String myReference, IDChainDefinition myIDChainDefinition, Boolean myIsGroupedOrAggregated, SelectValueAssignment mySelectValueAssignment = null)
        {
            SelectionElement lastElem = null;

            var curLevel = new EdgeList();
            EdgeList preLevel = null;

            if (myReference != null && _Selections.ContainsKey(myReference) && _Selections[myReference].Any(kv => kv.Value.Any(se => se.RelatedIDChainDefinition == myIDChainDefinition && se.Alias == myAlias)))
            {
                return new Exceptional(new Error_DuplicateAttributeSelection(myAlias));
            }

            foreach (var nodeEdgeKey in myIDChainDefinition)
            {

                if (nodeEdgeKey is ChainPartTypeOrAttributeDefinition)
                {

                    #region Usual attribute 

                    preLevel = null;

                    var selElem = new SelectionElement(myAlias, curLevel, myIsGroupedOrAggregated, myIDChainDefinition);

                    var typeOrAttr = (nodeEdgeKey as ChainPartTypeOrAttributeDefinition);

                    if (true || typeOrAttr.DBType != null && typeOrAttr.TypeAttribute != null)
                    {
                        #region defined

                        var edgeKey = typeOrAttr.EdgeKey;
                        selElem.Element = typeOrAttr.TypeAttribute; //_DBContext.DBTypeManager.GetTypeAttributeByEdge(edgeKey);

                        if (String.IsNullOrEmpty(selElem.Alias) || (nodeEdgeKey.Next != null && !(nodeEdgeKey.Next is ChainPartFuncDefinition)))
                        {
                            selElem.Alias = typeOrAttr.TypeAttribute.Name;//_DBContext.DBTypeManager.GetTypeAttributeByEdge(edgeKey).Name;
                        }

                        curLevel += edgeKey;
                        preLevel = curLevel.GetPredecessorLevel(); 

                        #endregion
                    }
                    else
                    {
                        #region undefined attribute
                        
                        if (myIDChainDefinition.Level == 0)
                        {
                            preLevel = new EdgeList(myIDChainDefinition.LastType.UUID);
                        }
                        else
                        {
                            var element = _Selections[myReference].Last();

                            preLevel = curLevel.GetPredecessorLevel();
                            //preLevel = curLevel;
                        }
                        selElem.Alias = typeOrAttr.TypeOrAttributeName;
                        selElem.Element = new UndefinedTypeAttribute(typeOrAttr.TypeOrAttributeName);

                        #endregion
                    }

                    #region Add to _Selections if valid

                    if (!_Selections.ContainsKey(myReference))
                    {
                        _Selections.Add(myReference, new Dictionary<EdgeList, List<SelectionElement>>());
                    }

                    if (!_Selections[myReference].ContainsKey(preLevel))
                    {
                        _Selections[myReference].Add(preLevel, new List<SelectionElement>());
                    }

                    ///
                    /// Duplicate AttributeSelection is: "U.Name, U.Name" or "U.Name.TOUPPER(), U.Name" but not "U.Friends.TOP(1).Name, U.Friends.TOP(1).Age"
                    if ((nodeEdgeKey.Next == null || (nodeEdgeKey.Next is ChainPartFuncDefinition && nodeEdgeKey.Next.Next == null))
                        //                                                        U.Name, U.Name                  U.Name.TOUPPER, U.Name
                        && _Selections[myReference][preLevel].Exists(item => item.Alias == selElem.Alias && selElem.EdgeList.Level == item.EdgeList.Level && item.RelatedIDChainDefinition.Depth == selElem.RelatedIDChainDefinition.Depth && item.Element != null) && !myIsGroupedOrAggregated)
                    {
                        return new Exceptional(new Error_DuplicateAttributeSelection(selElem.Alias));
                    }

                    // Do not add again if:
                    // - it is a defined attribute and there is an asterisk selection at this level
                    // - it is not the last part AND
                    // - there is already an item of this part with the same alias and the same Depth
                    if (nodeEdgeKey.Next == null || _Selections[myReference][preLevel].Count == 0 || _Selections[myReference][preLevel].Any(item => IsNewSelectionElement(item, selElem)))
                    {
                        _Selections[myReference][preLevel].Add(selElem);
                    }

                    #endregion

                    lastElem = selElem;

                    #endregion

                }
                else if (nodeEdgeKey is ChainPartFuncDefinition)
                {

                    var chainPartFuncDefinition = (nodeEdgeKey as ChainPartFuncDefinition);

                    #region Function

                    if (myReference == null)
                    {

                        #region Type independent functions

                        var selElem = new SelectionElement(myAlias, myIDChainDefinition);
                        if (String.IsNullOrEmpty(selElem.Alias))
                        {
                            selElem.Alias = chainPartFuncDefinition.SourceParsedString;
                        }
                        var funcElem = new SelectionElementFunction(selElem, chainPartFuncDefinition, chainPartFuncDefinition.Parameters);

                        if (lastElem is SelectionElementFunction)
                        {
                            (lastElem as SelectionElementFunction).AddFollowingFunction(funcElem);
                            lastElem = funcElem;
                        }
                        else
                        {
                            if (_SelectionElementsTypeIndependend.Any(se => se.Alias == funcElem.Alias))
                            {
                                return new Exceptional(new Error_DuplicateAttributeSelection(funcElem.Alias));
                            }

                            _SelectionElementsTypeIndependend.Add(funcElem);
                            lastElem = funcElem;
                        }

                        #endregion

                    }
                    else
                    {

                        #region Type dependent function

                        var funcElem = new SelectionElementFunction(lastElem, (nodeEdgeKey as ChainPartFuncDefinition), (nodeEdgeKey as ChainPartFuncDefinition).Parameters);
                        funcElem.RelatedIDChainDefinition = myIDChainDefinition;

                        if (!String.IsNullOrEmpty(myAlias) && nodeEdgeKey.Next == null)
                        {
                            funcElem.Alias = myAlias;
                        }

                        if (lastElem is SelectionElementFunction)
                        {
                            (lastElem as SelectionElementFunction).AddFollowingFunction(funcElem);
                            lastElem = funcElem;
                        }
                        else if (_Selections[myReference][preLevel].Contains(lastElem))
                        {

                            #region Add function to the last selection element (replace it)

                            _Selections[myReference][preLevel].Remove(lastElem);

                            //lastElem = new SelectionElementFunction(lastElem, (nodeEdgeKey as ChainPartFuncDefinition), (nodeEdgeKey as ChainPartFuncDefinition).Parameters);
                            //lastElem.RelatedIDChainDefinition = myIDChainDefinition;

                            //if (!String.IsNullOrEmpty(alias) && nodeEdgeKey.Next == null)
                            //{
                            //    lastElem.Alias = alias;
                            //}
                            lastElem = funcElem;

                            if (!_Selections[myReference][preLevel].Contains(lastElem)) // In case this Element with func is already in the selection list do nothing.
                            {

                                _Selections[myReference][preLevel].Add(lastElem);

                            }

                            #endregion

                        }
                        else if (!_Selections[myReference][preLevel].Contains(funcElem))
                        {

                            #region In this case we have a similar function but NOT THE SAME. Since we don't know what to do, return error.

                            return new Exceptional(new Error_InvalidAttributeSelection(myIDChainDefinition.ContentString));

                            #endregion

                        }

                        #endregion

                    }
                    
                    #endregion

                }

            }

            #region Set the SelectValueAssignment for the last element

            if (lastElem != null && mySelectValueAssignment != null)
            {

                #region Error handling

                System.Diagnostics.Debug.Assert(lastElem.Element != null);

                if (lastElem.Element.IsUserDefinedType(_DBContext.DBTypeManager))
                {
                    return new Exceptional(new Error_InvalidSelectValueAssignment(lastElem.Element.Name));
                }

                if (!(mySelectValueAssignment.TermDefinition is ValueDefinition))
                {
                    return new Exceptional(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                }

                #endregion

                #region Validate datatype if the attribute is a defined attribute

                if (!(lastElem.Element is UndefinedTypeAttribute))
                {

                    if (!lastElem.Element.GetADBBaseObjectType(_DBContext.DBTypeManager).IsValidValue((mySelectValueAssignment.TermDefinition as ValueDefinition).Value.Value))
                    {
                        return new Exceptional(new Error_SelectValueAssignmentDataTypeDoesNotMatch(lastElem.Element.GetADBBaseObjectType(_DBContext.DBTypeManager).ObjectName, (mySelectValueAssignment.TermDefinition as ValueDefinition).Value.ObjectName));
                    }
                    var typedValue = new ValueDefinition(lastElem.Element.GetADBBaseObjectType(_DBContext.DBTypeManager).Clone((mySelectValueAssignment.TermDefinition as ValueDefinition).Value.Value));
                    mySelectValueAssignment.TermDefinition = typedValue;
                }

                #endregion

                lastElem.SelectValueAssignment = mySelectValueAssignment;
            }


            #endregion

            return Exceptional.OK;

        }
Exemple #29
0
        public void Init(ParsingContext context, ParseTreeNode myParseTreeNode)
        {
            var _GraphQLGrammar = (SonesGQLGrammar)context.Language.Grammar;

            _Targets = new HashSet <AAttributeAssignOrUpdateOrRemove>();


            #region FROM Sources

            _SourceType = ((ATypeNode)myParseTreeNode.ChildNodes[1].AstNode).ReferenceAndType.TypeName;
            var typeNode = _SourceType;

            _Sources = (myParseTreeNode.ChildNodes[2].AstNode as TupleNode).TupleDefinition;

            if (_Sources.Count() > 1)
            {
                var firstElement = (BinaryExpressionDefinition)_Sources.First().Value;
                _Sources.Remove(_Sources.First());
                _Condition = GetConditionNode("OR", firstElement, _Sources);
            }

            else
            {
                _Condition = (BinaryExpressionDefinition)_Sources.First().Value;
            }

            #endregion

            #region Find statement "VIA Edge"

            IDNode _EdgeAttr = null;

            // Semantic Web Yoda-style...
            if (myParseTreeNode.ChildNodes[3].Token.KeyTerm == _GraphQLGrammar.S_VIA)
            {
                _EdgeAttr = (myParseTreeNode.ChildNodes[4].AstNode as IDNode);
            }

            else // Human language style...
            {
                if (myParseTreeNode.ChildNodes[5].Token.KeyTerm == _GraphQLGrammar.S_VIA)
                {
                    _EdgeAttr = (myParseTreeNode.ChildNodes[6].AstNode as IDNode);
                }
            }

            #endregion

            #region Find statement "TO Targets"

            TupleDefinition tupleDef = null;

            // Semantic Web Yoda-style...
            if (myParseTreeNode.ChildNodes[5].Token.KeyTerm == _GraphQLGrammar.S_TO)
            {
                typeNode = ((ATypeNode)myParseTreeNode.ChildNodes[6].ChildNodes[0].AstNode).ReferenceAndType.TypeName;
                tupleDef = (myParseTreeNode.ChildNodes[6].ChildNodes[1].AstNode as TupleNode).TupleDefinition;
            }

            else // Human language style...
            {
                if (myParseTreeNode.ChildNodes[3].Token.KeyTerm == _GraphQLGrammar.S_TO)
                {
                    typeNode = ((ATypeNode)myParseTreeNode.ChildNodes[4].ChildNodes[0].AstNode).ReferenceAndType.TypeName;
                    tupleDef = (myParseTreeNode.ChildNodes[4].ChildNodes[1].AstNode as TupleNode).TupleDefinition;
                }
            }

            #endregion

            #region Processing...

            var tupleDefTargetType = new TupleDefinition(tupleDef.KindOfTuple);

            foreach (var item in tupleDef.TupleElements)
            {
                var attrName = typeNode + SonesGQLConstants.EdgeTraversalDelimiterSymbol + ((IDChainDefinition)((BinaryExpressionDefinition)item.Value).Left).ContentString;
                var leftNode = new IDChainDefinition(attrName, new List <TypeReferenceDefinition>()
                {
                    new TypeReferenceDefinition(typeNode, typeNode)
                });
                leftNode.AddPart(new ChainPartTypeOrAttributeDefinition(((IDChainDefinition)((BinaryExpressionDefinition)item.Value).Left).ContentString));
                var rightNode = ((BinaryExpressionDefinition)item.Value).Right;

                var binExpression = new BinaryExpressionDefinition(((BinaryExpressionDefinition)item.Value).OperatorSymbol, leftNode, rightNode);

                tupleDefTargetType.AddElement(new TupleElement(binExpression));
            }

            _Targets.Add(new AttributeAssignOrUpdateList(new CollectionDefinition(CollectionType.Set, tupleDefTargetType), _EdgeAttr.IDChainDefinition, false));

            #endregion
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="myCollectionDefinition"></param>
 /// <param name="iDChainDefinition"></param>
 /// <param name="myAssign">True to assign, False to update</param>
 public AttributeAssignOrUpdateList(CollectionDefinition myCollectionDefinition, IDChainDefinition iDChainDefinition, Boolean myAssign)
 {
     CollectionDefinition = myCollectionDefinition;
     AttributeIDChain     = iDChainDefinition;
     Assign = myAssign;
 }
Exemple #31
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region get myAttributeName

            _AttributeIDNode = ((IDNode)parseNode.ChildNodes[0].AstNode).IDChainDefinition;

            #endregion

            var _Node = parseNode.ChildNodes[2];

            if (_Node.Token != null)
            {
                AttributeValue = new AttributeAssignOrUpdateValue(_AttributeIDNode, _Node.Token.Value);
            }
            else if (_Node.AstNode is BinaryExpressionNode)
            {
                #region binary expression

                AttributeValue = new AttributeAssignOrUpdateExpression(_AttributeIDNode, (_Node.AstNode as BinaryExpressionNode).BinaryExpressionDefinition);

                #endregion
            }
            else if (_Node.AstNode is TupleNode)
            {
                #region Tuple

                TupleNode tempTupleNode = (TupleNode)_Node.AstNode;

                if (tempTupleNode.TupleDefinition.Count() == 1)
                {
                    if (tempTupleNode.TupleDefinition.First().Value is BinaryExpressionDefinition)
                    {
                        AttributeValue = new AttributeAssignOrUpdateExpression(_AttributeIDNode, tempTupleNode.TupleDefinition.First().Value as BinaryExpressionDefinition);
                    }
                    else
                    {
                        throw new InvalidTupleException("Could not extract BinaryExpressionNode from TupleNode.");
                    }
                }
                else
                {
                    throw new InvalidTupleException("It is not possible to have more than one binary expression in one tuple. Please check brackets.");
                }

                #endregion
            }
            else if (_Node.AstNode is IDNode)
            {
                throw new InvalidVertexAttributeValueException(_AttributeIDNode.ToString(), (_Node.AstNode as IDNode).ToString());
            }
            else if (_Node.AstNode is SetRefNode)
            {
                #region setref

                AttributeValue = new AttributeAssignOrUpdateSetRef(_AttributeIDNode, (_Node.AstNode as SetRefNode).SetRefDefinition);

                #endregion
            }
            else if ((_Node.AstNode is CollectionOfDBObjectsNode))
            {
                #region collection like list

                AttributeValue = new AttributeAssignOrUpdateList((_Node.AstNode as CollectionOfDBObjectsNode).CollectionDefinition, _AttributeIDNode, true);

                #endregion
            }
            else
            {
                throw new NotImplementedQLException("");
            }
        }
 public AttributeAssignOrUpdateValue(IDChainDefinition myIDChainDefinition, Object myValue)
     : base(myIDChainDefinition)
 {
     this.Value = myValue;
 }
Exemple #33
0
 public SelectionElementAggregate(IGQLAggregate myBaseAggregate, string myAlias, EdgeList myEdgeList, LevelKey myLevelKey, IDChainDefinition myRelatedIDChainDefinition, AggregateDefinition myAggregateDefinition)
 {
     Alias = myAlias;
     EdgeList = myEdgeList;
     LevelKey = myLevelKey;
     Aggregate = myBaseAggregate;
     AggregateDefinition = myAggregateDefinition;
     RelatedIDChainDefinition = myRelatedIDChainDefinition;
 }
 private ValueDefinition GetAtomValue(IDChainDefinition iDNode, IVertex aDBObject)
 {
     return(new ValueDefinition((iDNode.LastAttribute as IPropertyDefinition).GetValue(aDBObject)));
 }
Exemple #35
0
        /// <summary>
        /// Adds a group element to the selection and validat it
        /// </summary>
        /// <param name="myReference"></param>
        /// <param name="myIDChainDefinition"></param>
        public Exceptional AddGroupElementToSelection(string myReference, IDChainDefinition myIDChainDefinition)
        {

            if (myIDChainDefinition.Edges.Count > 1)
            {
                return new Exceptional(new Error_InvalidGroupByLevel(myIDChainDefinition));
            }

            // if the grouped attr is not selected
            if ((!_Selections.ContainsKey(myReference) || !_Selections[myReference].Any(l => l.Value.Any(se => se.Element != null && se.Element == myIDChainDefinition.LastAttribute))) && !myIDChainDefinition.IsUndefinedAttribute)
            {
                return new Exceptional(new Error_GroupedAttributeIsNotSelected(myIDChainDefinition.LastAttribute));
            }
            else
            {
                if (!_Groupings.ContainsKey(myReference))
                {
                    _Groupings.Add(myReference, new List<SelectionElement>());
                }
                _Groupings[myReference].Add(new SelectionElement(myReference, new EdgeList(myIDChainDefinition.Edges), false, myIDChainDefinition, myIDChainDefinition.LastAttribute));
            }

            return Exceptional.OK;
        }
Exemple #36
0
        private void GetContent(CompilerContext context, ParseTreeNode parseNode)
        {
            #region get myAttributeName

            _AttributeIDNode = ((IDNode)parseNode.ChildNodes[0].AstNode).IDChainDefinition;

            var attributeType = GraphDBTypeMapper.ConvertGraph2CSharp(parseNode.ChildNodes[2].Term.GetType().Name);

            #endregion

            var _Node = parseNode.ChildNodes[2];

            if (_Node.Token != null)
            {
                AttributeValue = new AttributeAssignOrUpdateValue(_AttributeIDNode, attributeType, _Node.Token.Value);
            }
            else if (_Node.AstNode is BinaryExpressionNode)
            {
                #region binary expression

                AttributeValue = new AttributeAssignOrUpdateExpression(_AttributeIDNode, (_Node.AstNode as BinaryExpressionNode).BinaryExpressionDefinition);

                #endregion
            }
            else if (_Node.AstNode is TupleNode)
            {
                #region Tuple

                TupleNode tempTupleNode = (TupleNode)_Node.AstNode;

                if (tempTupleNode.TupleDefinition.Count() == 1)
                {
                    if (tempTupleNode.TupleDefinition.First().Value is BinaryExpressionDefinition)
                    {
                        AttributeValue = new AttributeAssignOrUpdateExpression(_AttributeIDNode, tempTupleNode.TupleDefinition.First().Value as BinaryExpressionDefinition);
                    }
                    else
                    {
                        throw new GraphDBException(new Error_InvalidTuple("Could not extract BinaryExpressionNode from TupleNode."));
                    }
                }
                else
                {
                    throw new GraphDBException(new Error_InvalidTuple("It is not possible to have more than one binary expression in one tuple. Please check brackets."));
                }

                #endregion
            }
            else if (_Node.AstNode is IDNode)
            {
                throw new GraphDBException(new Error_InvalidAttributeValue(_AttributeIDNode.ToString(), (_Node.AstNode as IDNode).ToString()));
            }
            else if (_Node.AstNode is SetRefNode)
            {
                #region setref

                AttributeValue = new AttributeAssignOrUpdateSetRef(_AttributeIDNode, (_Node.AstNode as SetRefNode).SetRefDefinition);

                #endregion
            }
            else if ((_Node.AstNode is CollectionOfDBObjectsNode))
            {
                #region collection like list

                AttributeValue = new AttributeAssignOrUpdateList((_Node.AstNode as CollectionOfDBObjectsNode).CollectionDefinition, _AttributeIDNode, true);

                #endregion
            }
            else
            {
                throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
            }
        }
Exemple #37
0
 public AttributeAssignOrUpdateValue(IDChainDefinition myIDChainDefinition, Object myValue)
     : base(myIDChainDefinition)
 {
     this.Value = myValue;
 }
Exemple #38
0
        private Exceptional<IExpressionGraph> GetComplexAtom(DBContext dbContext, Dictionary<DBObjectStream, AOperationDefinition> operandsPrim, Dictionary<DBObjectStream, AOperationDefinition> operandsComparism, IDChainDefinition myIDChainDefinition, DBObjectCache dbObjectCache, ref IExpressionGraph result)
        {
            #region data

            LevelKey myLevelKey = CreateLevelKey(myIDChainDefinition, dbContext.DBTypeManager);

            #endregion

            foreach (var left in operandsPrim)
            {
                foreach (var right in operandsComparism)
                {
                    var tempResult = this.SimpleOperation(left.Value, right.Value, TypesOfBinaryExpression.Atom);
                    if (tempResult.Failed())
                        return new Exceptional<IExpressionGraph>(tempResult);

                    if ((Boolean)((ValueDefinition)tempResult.Value).Value.Value)
                    {
                        IntegrateInGraph(left.Key, result, myLevelKey, dbContext,dbObjectCache);
                        break;
                    }
                }
            }

            return new Exceptional<IExpressionGraph>(result);
        }
 public AttributeAssignOrUpdateSetRef(IDChainDefinition myIDChainDefinition, SetRefDefinition mySetRefDefinition)
     : base(myIDChainDefinition)
 {
     SetRefDefinition = mySetRefDefinition;
 }
Exemple #40
0
        private IObject GetDbos(IDChainDefinition myIDChainDefinition, DBObjectStream myDBObjectStream, DBContext dbContext, SessionSettings mySessionToken, DBObjectCache dbObjectCache)
        {
            if (myIDChainDefinition.LastAttribute.IsBackwardEdge)
            {
                var contBackwardExcept = myDBObjectStream.ContainsBackwardEdge(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition, dbContext, dbObjectCache, myIDChainDefinition.LastAttribute.GetRelatedType(dbContext.DBTypeManager));

                if (contBackwardExcept.Failed())
                    throw new GraphDBException(contBackwardExcept.IErrors);

                if (contBackwardExcept.Value)
                {
                    var beStream = dbObjectCache.LoadDBBackwardEdgeStream(myIDChainDefinition.LastType, myDBObjectStream.ObjectUUID).Value;
                    if (beStream.ContainsBackwardEdge(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition))
                        return beStream.GetBackwardEdges(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition);
                    else
                        return null;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                if (myIDChainDefinition.LastAttribute.KindOfType == KindsOfType.SpecialAttribute)
                {
                    return myDBObjectStream.GetAttribute(myIDChainDefinition.LastAttribute.UUID, myIDChainDefinition.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext);
                }
                else
                {
                    return myDBObjectStream.GetAttribute(myIDChainDefinition.LastAttribute.UUID);
                }
            }
        }
Exemple #41
0
 public SelectionElement(string myAlias, IDChainDefinition myRelatedIDChainDefinition)
 {
     Alias = myAlias;
     RelatedIDChainDefinition = myRelatedIDChainDefinition;
 }
 public AttributeAssignOrUpdateSetRef(IDChainDefinition myIDChainDefinition, SetRefDefinition mySetRefDefinition)
     : base(myIDChainDefinition)
 {
     SetRefDefinition = mySetRefDefinition;
 }
Exemple #43
0
 public SelectionElement(string myAlias, Select.EdgeList myEdgeList, bool myIsGroupedOrAggregated, IDChainDefinition myRelatedIDChainDefinition, IAttributeDefinition myElement = null)
     : this(myAlias, myRelatedIDChainDefinition)
 {
     EdgeList = myEdgeList;
     IsGroupedOrAggregated = myIsGroupedOrAggregated;
     Element = myElement;
 }
 public AttributeAssignOrUpdateExpression(IDChainDefinition myIDChainDefinition, BinaryExpressionDefinition binaryExpressionDefinition)
     : base(myIDChainDefinition)
 {
     BinaryExpressionDefinition = binaryExpressionDefinition;
 }
 private ValueDefinition GetAtomValue(IDChainDefinition iDNode, IVertex aDBObject)
 {
     return new ValueDefinition((iDNode.LastAttribute as IPropertyDefinition).GetValue(aDBObject));
 }
        /// <summary>
        /// Extracts data for a binary expression
        /// </summary>
        /// <param name="myComplexValue">The complex part of the binary expression.</param>
        /// <param name="mySimpleValue">The simple/atomic part of the expression.</param>
        /// <param name="errors">The list of errors.</param>
        /// <param name="typeOfBinExpr">The kind of the binary expression</param>
        /// <returns>A data tuple.</returns>
        private static DataContainer ExtractData(AExpressionDefinition myComplexValue,
                                                 AExpressionDefinition mySimpleValue,
                                                 ref TypesOfBinaryExpression typeOfBinExpr,
                                                 GQLPluginManager myPluginManager,
                                                 IGraphDB myGraphDB,
                                                 SecurityToken mySecurityToken,
                                                 Int64 myTransactionToken,
                                                 Boolean aggregateAllowed)
        {
            #region data

            //the complex IDNode (sth. like U.Age or Count(U.Friends))
            IDChainDefinition complexIDNode = null;

            //the value that is on the opposite of the complex IDNode
            AExpressionDefinition simpleValue = null;

            //a complex IDNode may result in a complexValue (i.e. Count(U.Friends) --> 3)
            AExpressionDefinition complexValue = null;

            //reference to former myComplexValue
            AExpressionDefinition extraordinaryValue = null;

            #endregion

            #region extraction

            if (myComplexValue is IDChainDefinition)
            {
                #region IDNode

                #region Data

                complexIDNode = (IDChainDefinition)myComplexValue;
                complexIDNode.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, false);
                if (complexIDNode.Any(id => id is ChainPartFuncDefinition))
                {
                    if (complexIDNode.Edges == null || complexIDNode.Edges.Count == 0)
                    {
                        #region parameterless function

                        var fcn = (complexIDNode.First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition);

                        // somes functions (aggregates) like SUM are not valid for where expressions, though they are not resolved
                        if (fcn.Function == null)
                        {
                            throw new FunctionDoesNotExistException(fcn.FuncName);
                        }

                        FuncParameter pResult = fcn.Function.ExecFunc(null, null, null, myGraphDB, mySecurityToken, myTransactionToken);

                        //simpleValue = new AtomValue(fcn.Function.TypeOfResult, ((FuncParameter)pResult.Value).Value); //the new simple value extraced from the function
                        simpleValue   = new ValueDefinition(((FuncParameter)pResult).Value);
                        typeOfBinExpr = TypesOfBinaryExpression.Unknown; //we do not know if we are left or right associated
                        complexIDNode = null;                            //we resolved it... so it's null

                        #endregion
                    }
                    else
                    {
                        //extraordinaryValue = (complexIDNode.First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition);
                        extraordinaryValue = complexIDNode;

                        if (mySimpleValue is ValueDefinition)
                        {
                            simpleValue = mySimpleValue;
                        }
                    }
                }
                else
                {
                    if (mySimpleValue is ValueDefinition)
                    {
                        try
                        {
                            if (complexIDNode.IsUndefinedAttribute)
                            {
                                throw new VertexAttributeIsNotDefinedException(complexIDNode.UndefinedAttribute);
                            }

                            simpleValue = GetCorrectValueDefinition(complexIDNode.LastAttribute, complexIDNode.LastType, ((ValueDefinition)mySimpleValue));
                        }
                        catch (FormatException)
                        {
                            throw new DataTypeDoesNotMatchException(((IPropertyDefinition)complexIDNode.LastAttribute).BaseType.Name, ((ValueDefinition)mySimpleValue).Value.GetType().Name);
                        }
                    }
                    else
                    {
                        if (mySimpleValue is TupleDefinition)
                        {
                            ((TupleDefinition)mySimpleValue).ConvertToAttributeType(myPluginManager, complexIDNode.LastAttribute, myGraphDB, mySecurityToken, myTransactionToken);

                            simpleValue = mySimpleValue;
                        }
                    }
                }

                #endregion


                #endregion
            }
            else if (myComplexValue is TupleDefinition)
            {
                #region TupleSetNode

                complexValue  = ((TupleDefinition)myComplexValue);
                simpleValue   = mySimpleValue;
                typeOfBinExpr = TypesOfBinaryExpression.Atom;

                #endregion
            }
            else if (myComplexValue is AggregateDefinition)
            {
                #region AggregateNode

                if (aggregateAllowed)
                {
                    if (((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters.Count != 1)
                    {
                        throw new GQLAggregateArgumentException("An aggregate must have exactly one expression.");
                    }

                    if (!(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] is IDChainDefinition))
                    {
                        throw new GQLAggregateArgumentException("An aggregate must have exactly one IDNode.");
                    }

                    #region Data

                    complexIDNode = (((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] as IDChainDefinition);

                    if (complexIDNode == null)
                    {
                        throw new InvalidIDNodeException("Only single IDNodes are currently allowed in aggregates!");
                    }

                    #endregion

                    #region values

                    simpleValue        = mySimpleValue;
                    extraordinaryValue = myComplexValue;

                    #endregion
                }
                else
                {
                    throw new AggregateNotAllowedException(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Aggregate.PluginShortName);
                }
                #endregion
            }
            else
            {
                throw new NotImplementedQLException("");
            }

            #endregion

            return(new DataContainer(new Tuple <IDChainDefinition, IDChainDefinition>(complexIDNode, null),
                                     new Tuple <AExpressionDefinition, AExpressionDefinition>(simpleValue, complexValue),
                                     new Tuple <AExpressionDefinition, AExpressionDefinition>(extraordinaryValue, null)));
        }
 /// <summary>
 /// This method gets the associativity of a binary expression.
 /// </summary>
 /// <param name="leftIDNode">Left IDNode.</param>
 /// <param name="rightIDNode">Right IDNode.</param>
 /// <returns>The associativity</returns>
 private TypesOfAssociativity GetAssociativityReloaded(IDChainDefinition leftIDNode, IDChainDefinition rightIDNode)
 {
     if (leftIDNode != null && rightIDNode != null)
     {
         if (leftIDNode.Reference == rightIDNode.Reference)
         {
             return TypesOfAssociativity.Neutral;
         }
         else
         {
             return TypesOfAssociativity.Unknown;
         }
     }
     else
     {
         if (leftIDNode != null)
         {
             return TypesOfAssociativity.Left;
         }
         else
         {
             if (rightIDNode != null)
             {
                 return TypesOfAssociativity.Right;
             }
             else
             {
                 return TypesOfAssociativity.Neutral;
             }
         }
     }
 }
 public AttributeAssignOrUpdateExpression(IDChainDefinition myIDChainDefinition, BinaryExpressionDefinition binaryExpressionDefinition)
     : base(myIDChainDefinition)
 {
     BinaryExpressionDefinition = binaryExpressionDefinition;
 }
 public AAttributeAssignOrUpdate(IDChainDefinition myIDChainDefinition)
 {
     AttributeIDChain = myIDChainDefinition;
 }
Exemple #50
0
        public override void GetContent(CompilerContext context, ParseTreeNode parseNode)
        {
            _Sources = new HashSet<AAttributeAssignOrUpdateOrRemove>();

            #region VIA edge

            IDNode _EdgeAttr = null;

            if (parseNode.ChildNodes[4].AstNode is IDNode) //Semantic Web Yoda style
            {
                _EdgeAttr = (parseNode.ChildNodes[4].AstNode as IDNode);
            }
            else //Human language style
            {
                _EdgeAttr = (parseNode.ChildNodes[6].AstNode as IDNode);
            }

            #endregion

            #region sources

            var typeNode = (parseNode.ChildNodes[1].AstNode as ATypeNode);
            ParsingResult.PushIExceptional(typeNode.ParsingResult);

            var tupleDef = (parseNode.ChildNodes[2].AstNode as TupleNode).TupleDefinition;

            var tupleDefSourceType = new TupleDefinition(tupleDef.KindOfTuple);

            foreach (var item in tupleDef.TupleElements)
            {
                var attrName = typeNode.ReferenceAndType.TypeName + DBConstants.EdgeTraversalDelimiterSymbol + ((IDChainDefinition)((BinaryExpressionDefinition)item.Value).Left).ContentString;
                var leftNode = new IDChainDefinition(attrName, new List<TypeReferenceDefinition>() { typeNode.ReferenceAndType });
                leftNode.AddPart(new ChainPartTypeOrAttributeDefinition(((IDChainDefinition)((BinaryExpressionDefinition)item.Value).Left).ContentString));
                var rightNode = ((BinaryExpressionDefinition)item.Value).Right;

                var binExpression = new BinaryExpressionDefinition(((BinaryExpressionDefinition)item.Value).OperatorSymbol, leftNode, rightNode);

                tupleDefSourceType.AddElement(new TupleElement(item.TypeOfValue, binExpression));
            }

            _Sources.Add(new AttributeRemoveList(_EdgeAttr.IDChainDefinition, _EdgeAttr.IDChainDefinition.TypeName, tupleDefSourceType));

            #endregion

            #region sources FROM

            if (parseNode.ChildNodes[6].ChildNodes[0].AstNode is ATypeNode)  //Semantic Web Yoda style
            {
                typeNode = (parseNode.ChildNodes[6].ChildNodes[0].AstNode as ATypeNode);
                _Targets = (parseNode.ChildNodes[6].ChildNodes[1].AstNode as TupleNode).TupleDefinition;
            }
            else  //Human language style
            {
                typeNode = (parseNode.ChildNodes[4].ChildNodes[0].AstNode as ATypeNode);
                _Targets = (parseNode.ChildNodes[4].ChildNodes[1].AstNode as TupleNode).TupleDefinition;
            }

            ParsingResult.PushIExceptional(typeNode.ParsingResult);
            _SourceType = typeNode.ReferenceAndType;

            if (_Targets.Count() > 1)
            {
                var firstElement = (BinaryExpressionDefinition)_Targets.First().Value;
                _Targets.Remove(_Targets.First());

                _Condition = GetConditionNode(new OrOperator().ContraryOperationSymbol, firstElement, _Targets);
            }
            else
            {
                _Condition = (BinaryExpressionDefinition)_Targets.First().Value;
            }

            #endregion
        }
Exemple #51
0
        /// <summary>
        /// This method extracts an IOperationValue out of a DBObjectStream.
        /// </summary>
        /// <param name="myIDChainDefinition">The corresponding IDNode.</param>
        /// <param name="myExtraordinary">Sth extraordinary like an aggregate or function call.</param>
        /// <param name="dbContext">The TypeManager of the database.</param>
        /// <param name="myDBObjectStream">The DBObjectStream.</param>
        /// <returns>An IOperationValue.</returns>
        private Exceptional<AOperationDefinition> GetOperand(IDChainDefinition myIDChainDefinition, AExpressionDefinition myExtraordinary, DBContext dbContext, DBObjectStream myDBObjectStream, DBObjectCache dbObjectCache, SessionSettings mySessionToken)
        {
            var aCtype = GraphDBTypeMapper.ConvertGraph2CSharp(myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);
            IObject dbos = GetDbos(myIDChainDefinition, myDBObjectStream, dbContext, mySessionToken, dbObjectCache);

            if (dbos == null)
            {
                return null;
            }

            AOperationDefinition operand = null;

            if (myExtraordinary != null)
            {
                #region extraordinary

                if (myExtraordinary is AggregateDefinition)
                {
                    System.Diagnostics.Debug.Assert(false);

                    //var aggrNode = ((AggregateDefinition)myExtraordinary).ChainPartAggregateDefinition;

                    //aggrNode.Validate(dbContext);

                    ////result of aggregate
                    //var pResult = aggrNode.Aggregate.Aggregate(dbos, myIDChainDefinition.LastAttribute, dbContext);
                    //if (pResult.Failed())
                    //    return new Exceptional<AOperationDefinition>(pResult);

                    //aCtype = aggrNode.Aggregate.TypeOfResult;
                    //operand = new ValueDefinition(aggrNode.Aggregate.TypeOfResult, pResult.Value);
                }
                else
                {
                    if (myExtraordinary is IDChainDefinition)
                    {
                        var chainFunc = (myExtraordinary as IDChainDefinition).First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition;

                        chainFunc.Validate(dbContext);

                        var func = chainFunc.Function;
                        func.CallingAttribute = myIDChainDefinition.LastAttribute;
                        func.CallingObject = dbos;
                        //result of function

                        var pResult = chainFunc.Execute(myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager), myDBObjectStream, myIDChainDefinition.Reference.Item1, dbContext);
                        if (pResult.Failed())
                            return new Exceptional<AOperationDefinition>(pResult);

                        //aCtype = funcCallNode.Function.TypeOfResult;
                        //aCtype = ((FuncParameter)pResult.Value).TypeOfOperatorResult;
                        operand = new ValueDefinition(((FuncParameter)pResult.Value).Value);
                        aCtype = (operand as ValueDefinition).Value.Type;
                    }
                    else
                    {
                    return new Exceptional<AOperationDefinition>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                    }
                }

                #endregion
            }
            else
            {
                #region simple

                if (aCtype == BasicType.SetOfDBObjects)
                {
                    operand = new TupleDefinition(aCtype, dbos, myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager));
                }
                else
                {
                    if (dbos is AListOfBaseEdgeType)
                    {
                        operand = new TupleDefinition(aCtype, dbos, myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager));
                    }
                    else if (dbos is ADBBaseObject)
                    {
                        operand = new ValueDefinition(dbos as ADBBaseObject);
                    }
                    else
                    {
                        operand = new ValueDefinition(aCtype, dbos);
                    }
                }

                #endregion
            }
            return new Exceptional<AOperationDefinition>(operand);
        }
 public OrderByAttributeDefinition(IDChainDefinition myIDChainDefinition, String myAsOrderByString)
 {
     IDChainDefinition = myIDChainDefinition;
     AsOrderByString   = myAsOrderByString;
 }
Exemple #53
0
 public SelectionElement(string myAlias, IDChainDefinition myRelatedIDChainDefinition)
 {
     Alias = myAlias;
     RelatedIDChainDefinition = myRelatedIDChainDefinition;
 }