Example #1
0
        protected void ValidateBinaryExpression(BinaryExpressionDefinition aUniqueExpr, IVertexType validationType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            switch (aUniqueExpr.TypeOfBinaryExpression)
            {
            case TypesOfBinaryExpression.LeftComplex:
                ValidateBinaryExpressionInternal(aUniqueExpr.Left, validationType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);

                break;

            case TypesOfBinaryExpression.RightComplex:
                ValidateBinaryExpressionInternal(aUniqueExpr.Right, validationType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);

                break;

            case TypesOfBinaryExpression.Complex:
                ValidateBinaryExpressionInternal(aUniqueExpr.Left, validationType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);
                ValidateBinaryExpressionInternal(aUniqueExpr.Right, validationType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);

                break;

            case TypesOfBinaryExpression.Atom:
            default:
                break;
            }
        }
        /// <summary>
        /// This method
        /// </summary>
        /// <param name="aBinExpr"></param>
        /// <param name="aDBObject"></param>
        /// <param name="dbContext"></param>
        protected void SubstituteAttributeNames(BinaryExpressionDefinition aBinExpr, IVertex aDBObject)
        {
            if (aBinExpr.Left is IDChainDefinition)
            {
                aBinExpr.Left = GetAtomValue((IDChainDefinition)aBinExpr.Left, aDBObject);

                switch (aBinExpr.TypeOfBinaryExpression)
                {
                case TypesOfBinaryExpression.LeftComplex:
                    aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                    break;

                case TypesOfBinaryExpression.Complex:
                    aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex;
                    break;

                case TypesOfBinaryExpression.Atom:
                case TypesOfBinaryExpression.RightComplex:
                case TypesOfBinaryExpression.Unknown:
                default:
                    break;
                }
            }
            else
            {
                if (aBinExpr.Left is BinaryExpressionDefinition)
                {
                    SubstituteAttributeNames((BinaryExpressionDefinition)aBinExpr.Left, aDBObject);
                }
            }

            if (aBinExpr.Right is IDChainDefinition)
            {
                aBinExpr.Right = GetAtomValue((IDChainDefinition)aBinExpr.Right, aDBObject);

                switch (aBinExpr.TypeOfBinaryExpression)
                {
                case TypesOfBinaryExpression.RightComplex:
                    aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                    break;

                case TypesOfBinaryExpression.Complex:
                    aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;
                    break;

                case TypesOfBinaryExpression.Atom:
                case TypesOfBinaryExpression.LeftComplex:
                case TypesOfBinaryExpression.Unknown:
                default:
                    break;
                }
            }
            else
            {
                if (aBinExpr.Right is BinaryExpressionDefinition)
                {
                    SubstituteAttributeNames((BinaryExpressionDefinition)aBinExpr.Right, aDBObject);
                }
            }
        }
 public InvalidBinaryExpressionIndexException(BinaryExpressionDefinition myBinaryExpression)
 {
     _msg = String.Format("The index {0} for the BinaryExpression {1} {2} {3} is not valid", 
                             myBinaryExpression.ExpressionIndex, 
                             myBinaryExpression.Left.ToString(), 
                             myBinaryExpression.Operator, 
                             myBinaryExpression.Right.ToString());
 }
Example #4
0
 public SelectDefinition(List<TypeReferenceDefinition> myTypeList, List<Tuple<AExpressionDefinition, string, SelectValueAssignment>> mySelectedElements, BinaryExpressionDefinition myWhereExpressionDefinition,
     List<IDChainDefinition> myGroupByIDs, BinaryExpressionDefinition myHaving, ulong? myLimit, ulong? myOffset, OrderByDefinition myOrderByDefinition, long myResolutionDepth)
 {
     TypeList = myTypeList;
     SelectedElements = mySelectedElements;
     WhereExpressionDefinition = myWhereExpressionDefinition;
     GroupByIDs = myGroupByIDs;
     Having = myHaving;
     Limit = myLimit;
     Offset = myOffset;
     OrderByDefinition = myOrderByDefinition;
     ResolutionDepth = myResolutionDepth;
 }
Example #5
0
 public void Init(ParsingContext context, ParseTreeNode parseNode)
 {
     if (HasChildNodes(parseNode))
     {
         if (parseNode.ChildNodes[1].AstNode is TupleNode && (parseNode.ChildNodes[1].AstNode as TupleNode).TupleDefinition.TupleElements.Count == 1)
         {
             var tuple = (parseNode.ChildNodes[1].AstNode as TupleNode).TupleDefinition.Simplyfy();
             BinaryExpressionDefinition = (tuple.TupleElements[0].Value as BinaryExpressionDefinition);
         }
         else if (parseNode.ChildNodes[1].AstNode is BinaryExpressionNode)
         {
             BinaryExpressionDefinition = ((BinaryExpressionNode)parseNode.ChildNodes[1].AstNode).BinaryExpressionDefinition;
         }
     }
 }
Example #6
0
        public BinaryExpressionDefinition GetBinaryExpression(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            AExpressionDefinition right;
            var op = GetOperatorBySymbol(_OperatorSymbol);
            if (op == null)
            {
                throw new OperatorDoesNotExistException(_OperatorSymbol);
            }

            right = new ValueDefinition(1);

            var binExpr = new BinaryExpressionDefinition("*", _Expression, right);
            binExpr.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);

            return binExpr;
        }
Example #7
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region set type of binary expression

            _OperatorSymbol = parseNode.ChildNodes[1].FirstChild.Token.ValueString;
            _left = GetExpressionDefinition(parseNode.ChildNodes[0]);
            _right = GetExpressionDefinition(parseNode.ChildNodes[2]);

            #endregion

            BinaryExpressionDefinition = new BinaryExpressionDefinition(_OperatorSymbol, _left, _right);

            OriginalString += _left.ToString() + " ";
            OriginalString += _OperatorSymbol + " ";
            OriginalString += _right.ToString();
        }
Example #8
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            if (HasChildNodes(parseNode))
            {
                _TypeName = ((AstNode)(parseNode.ChildNodes[1].AstNode)).AsString;

                if (parseNode.ChildNodes[3] != null && HasChildNodes(parseNode.ChildNodes[3]))
                {
                    _AttributeAssignList = (parseNode.ChildNodes[3].AstNode as AttributeAssignListNode).AttributeAssigns;
                }

                _whereExpression = ((BinaryExpressionNode)parseNode.ChildNodes[5].AstNode).BinaryExpressionDefinition;

                System.Diagnostics.Debug.Assert(_whereExpression != null);
            }
        }
Example #9
0
        public BinaryExpressionDefinition GetBinaryExpression(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            AExpressionDefinition right;
            var op = GetOperatorBySymbol(_OperatorSymbol);

            if (op == null)
            {
                throw new OperatorDoesNotExistException(_OperatorSymbol);
            }

            right = new ValueDefinition(1);

            var binExpr = new BinaryExpressionDefinition("*", _Expression, right);

            binExpr.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);

            return(binExpr);
        }
Example #10
0
 public SelectDefinition(List <TypeReferenceDefinition> myTypeList,
                         List <Tuple <AExpressionDefinition, string, SelectValueAssignment> > mySelectedElements,
                         BinaryExpressionDefinition myWhereExpressionDefinition,
                         List <IDChainDefinition> myGroupByIDs,
                         BinaryExpressionDefinition myHaving,
                         ulong?myLimit,
                         ulong?myOffset,
                         OrderByDefinition myOrderByDefinition,
                         long myResolutionDepth)
 {
     TypeList                  = myTypeList;
     SelectedElements          = mySelectedElements;
     WhereExpressionDefinition = myWhereExpressionDefinition;
     GroupByIDs                = myGroupByIDs;
     Having            = myHaving;
     Limit             = myLimit;
     Offset            = myOffset;
     OrderByDefinition = myOrderByDefinition;
     ResolutionDepth   = myResolutionDepth;
 }
Example #11
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            _toBeDeletedAttributes = new List<String>();

            _typeName = parseNode.ChildNodes[1].Token.ValueString;

            if (HasChildNodes(parseNode.ChildNodes[3]))
            {
                foreach (var _ParseTreeNode in parseNode.ChildNodes[3].ChildNodes[0].ChildNodes)
                {
                    _toBeDeletedAttributes.Add(_ParseTreeNode.ChildNodes[0].Token.ValueString);
                }
            }

            #region whereClauseOpt

            if (parseNode.ChildNodes[4].ChildNodes != null && parseNode.ChildNodes[4].ChildNodes.Count != 0)
            {
                WhereExpressionNode tempWhereNode = (WhereExpressionNode)parseNode.ChildNodes[4].AstNode;
                _WhereExpression = tempWhereNode.BinaryExpressionDefinition;
            }

            #endregion
        }
Example #12
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region get Type

            _TypeName = ((AstNode)parseNode.ChildNodes[1].AstNode).AsString;

            #endregion

            #region get myAttributes

            if (HasChildNodes(parseNode.ChildNodes[3]))
            {
                var AttrUpdateOrAssign = (AttributeUpdateOrAssignListNode)parseNode.ChildNodes[3].AstNode;
                _listOfUpdates = AttrUpdateOrAssign.ListOfUpdate;
            }

            #endregion

            #region whereClauseOpt

            if (parseNode.ChildNodes[4].ChildNodes != null && parseNode.ChildNodes[4].ChildNodes.Count != 0)
            {
                var tempWhereNode = (WhereExpressionNode)parseNode.ChildNodes[4].AstNode;
                _WhereExpression = tempWhereNode.BinaryExpressionDefinition;
            }

            #endregion
        }
 public AttributeAssignOrUpdateExpression(IDChainDefinition myIDChainDefinition, BinaryExpressionDefinition binaryExpressionDefinition)
     : base(myIDChainDefinition)
 {
     BinaryExpressionDefinition = binaryExpressionDefinition;
 }
		/// <summary>
		/// Initializes a new instance of the BinaryExpressionDefinition class.
		/// </summary>
		/// <param name="myBinaryExpression"></param>
		/// <param name="innerException">The exception that is the cause of the current exception, this parameter can be NULL.</param>
        public InvalidBinaryExpressionException(BinaryExpressionDefinition myBinaryExpression, Exception innerException = null) : base(innerException)
        {
            _msg = String.Format("The BinaryExpression is not valid: {0} {1} {2}", myBinaryExpression.Left.ToString(), myBinaryExpression.Operator, myBinaryExpression.Right.ToString());
        }
Example #15
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            if (HasChildNodes(parseNode))
            {
                //get type
                if (parseNode.ChildNodes[1] != null && parseNode.ChildNodes[1].AstNode != null)
                {
                    _type = ((AstNode)(parseNode.ChildNodes[1].AstNode)).AsString;
                }
                else
                {
                    throw new NotImplementedQLException("");
                }

                if (parseNode.ChildNodes[3] != null && HasChildNodes(parseNode.ChildNodes[3]))
                {

                    _attributeAssignList = (parseNode.ChildNodes[3].AstNode as AttributeAssignListNode).AttributeAssigns;

                }

                if (parseNode.ChildNodes[4] != null && ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition != null)
                {
                    _whereExpression = ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition;

                }
            }
        }
Example #16
0
        private BinaryExpressionDefinition GetConditionNode(String myOperator, BinaryExpressionDefinition myPrevNode, TupleDefinition myNodeList)
        {
            var binElem = myNodeList.FirstOrDefault();

            if (binElem == null)
            {
                return myPrevNode;
            }

            myNodeList.Remove(binElem);

            var binNode = new BinaryExpressionDefinition(myOperator, myPrevNode, binElem.Value);
            return GetConditionNode(myOperator, binNode, myNodeList);
        }
Example #17
0
 /// <summary>
 /// Adds a having to the selection
 /// </summary>
 /// <param name="myHavingExpression"></param>
 public void AddHavingToSelection(BinaryExpressionDefinition myHavingExpression)
 {
     _HavingExpression = myHavingExpression;
 }
        /// <summary>
        /// This method
        /// </summary>
        /// <param name="aBinExpr"></param>
        /// <param name="aDBObject"></param>
        /// <param name="dbContext"></param>
        protected void SubstituteAttributeNames(BinaryExpressionDefinition aBinExpr, IVertex aDBObject)
        {
            if (aBinExpr.Left is IDChainDefinition)
            {
                aBinExpr.Left = GetAtomValue((IDChainDefinition)aBinExpr.Left, aDBObject);

                switch (aBinExpr.TypeOfBinaryExpression)
                {
                    case TypesOfBinaryExpression.LeftComplex:
                        aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                        break;
                    case TypesOfBinaryExpression.Complex:
                        aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex;
                        break;

                    case TypesOfBinaryExpression.Atom:
                    case TypesOfBinaryExpression.RightComplex:
                    case TypesOfBinaryExpression.Unknown:
                    default:
                        break;
                }
            }
            else
            {
                if (aBinExpr.Left is BinaryExpressionDefinition)
                {
                    SubstituteAttributeNames((BinaryExpressionDefinition)aBinExpr.Left, aDBObject);
                }
            }

            if (aBinExpr.Right is IDChainDefinition)
            {
                aBinExpr.Right = GetAtomValue((IDChainDefinition)aBinExpr.Right, aDBObject);

                switch (aBinExpr.TypeOfBinaryExpression)
                {
                    case TypesOfBinaryExpression.RightComplex:
                        aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                        break;
                    case TypesOfBinaryExpression.Complex:
                        aBinExpr.TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;
                        break;

                    case TypesOfBinaryExpression.Atom:
                    case TypesOfBinaryExpression.LeftComplex:
                    case TypesOfBinaryExpression.Unknown:
                    default:
                        break;
                }
            }
            else
            {
                if (aBinExpr.Right is BinaryExpressionDefinition)
                {
                    SubstituteAttributeNames((BinaryExpressionDefinition)aBinExpr.Right, aDBObject);
                }
            }
        }
Example #19
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            if (HasChildNodes(parseNode))
            {

                //get type
                if (parseNode.ChildNodes[1] != null && parseNode.ChildNodes[1].AstNode != null)
                {
                    _Type = ((AstNode)(parseNode.ChildNodes[1].AstNode)).AsString;
                }
                else
                {
                    throw new NotImplementedQLException("");
                }


                if (parseNode.ChildNodes[3] != null && HasChildNodes(parseNode.ChildNodes[3]))
                {

                    _AttributeAssignList = new List<AAttributeAssignOrUpdate>((parseNode.ChildNodes[3].AstNode as AttributeUpdateOrAssignListNode).ListOfUpdate.Select(e => e as AAttributeAssignOrUpdate));

                }

                if (parseNode.ChildNodes[4] != null && ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition != null)
                {
                    _WhereExpression = ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition;
                }

            }
        }
Example #20
0
        /// <summary>
        /// fast check if a given binary expression node is suitable for list integration
        /// </summary>
        /// <param name="aUniqueExpr">A BinaryExpressionNode.</param>
        /// <param name="myAttributes"></param>
        /// <returns></returns>
        private bool IsValidBinaryExpressionNode(BinaryExpressionDefinition aUniqueExpr, Dictionary<string, string> attributes)
        {
            switch (aUniqueExpr.TypeOfBinaryExpression)
            {
                case TypesOfBinaryExpression.LeftComplex:

                    #region left complex

                    return CheckIDNode(aUniqueExpr.Left, attributes);

                    #endregion

                case TypesOfBinaryExpression.RightComplex:

                    #region right complex

                    return CheckIDNode(aUniqueExpr.Right, attributes);

                    #endregion


                case TypesOfBinaryExpression.Complex:

                    #region complex

                    #region Data

                    BinaryExpressionDefinition leftNode = null;
                    BinaryExpressionDefinition rightNode = null;

                    #endregion

                    #region get expr

                    #region left

                    if (aUniqueExpr.Left is BinaryExpressionDefinition)
                    {
                        leftNode = (BinaryExpressionDefinition)aUniqueExpr.Left;
                    }
                    else
                    {
                        return false;
                    }

                    #endregion

                    #region right

                    if (aUniqueExpr.Right is BinaryExpressionDefinition)
                    {
                        rightNode = (BinaryExpressionDefinition)aUniqueExpr.Right;
                    }
                    else
                    {
                        return false;
                    }

                    #endregion

                    #endregion

                    #region check

                    if ((leftNode != null) && (rightNode != null))
                    {
                        if (IsValidBinaryExpressionNode(leftNode, attributes) && IsValidBinaryExpressionNode(rightNode, attributes))
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }

                    #endregion

                    #endregion

                #region error cases

                case TypesOfBinaryExpression.Atom:

                default:

                    //in this kind of node it is not allowed to use Atom or complex expressions
                    return false;

                #endregion

            }

        }
Example #21
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
        }
Example #22
0
        private static IEnumerable<IVertex> ProcessBinaryExpression(BinaryExpressionDefinition binExpression, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, IVertexType vertexType)
        {
            //validate
            binExpression.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, vertexType);

            //calculate
            var expressionGraph = binExpression.Calculon(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, new CommonUsageGraph(myGraphDB, mySecurityToken, myTransactionToken), false);

            //extract
            return
                expressionGraph.Select(
                    new LevelKey(vertexType.ID, myGraphDB, mySecurityToken, myTransactionToken), null, true);
        }
Example #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
        }
Example #24
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region Data

            TypeList = new List<TypeReferenceDefinition>();
            GroupByIDs = new List<IDChainDefinition>();
            SelectedElements = new List<Tuple<AExpressionDefinition, string, SelectValueAssignment>>();
            Limit = null;
            Offset = null;
            WhereExpressionDefinition = null;
            ResolutionDepth = -1;

            #endregion

            #region TypeList

            foreach (ParseTreeNode aNode in parseNode.ChildNodes[1].ChildNodes)
            {
                ATypeNode aType = (ATypeNode)aNode.AstNode;

                // use the overrides equals to check duplicated references
                if (!TypeList.Contains(aType.ReferenceAndType))
                {
                    TypeList.Add(aType.ReferenceAndType);
                }
                else
                {
                    throw new DuplicateReferenceOccurrenceException(aType.ReferenceAndType.TypeName);
                }
            }

            #endregion

            #region selList

            foreach (ParseTreeNode aNode in parseNode.ChildNodes[3].ChildNodes)
            {
                SelectionListElementNode aColumnItemNode = (SelectionListElementNode)aNode.AstNode;
                String typeName                          = null;

                if (aColumnItemNode.SelType != TypesOfSelect.None)
                {

                    foreach (var reference in GetTypeReferenceDefinitions(context))
                    {
                        //SelectedElements.Add(new IDChainDefinition(new ChainPartTypeOrAttributeDefinition(reference.TypeName), aColumnItemNode.SelType, typeName), null);
                        SelectedElements.Add(new Tuple<AExpressionDefinition, string, SelectValueAssignment>(
                            new IDChainDefinition(new ChainPartTypeOrAttributeDefinition(reference.TypeName), aColumnItemNode.SelType, typeName), null, aColumnItemNode.ValueAssignment));
                    }
                    continue;
                }

                SelectedElements.Add(new Tuple<AExpressionDefinition, string, SelectValueAssignment>(
                    aColumnItemNode.ColumnSourceValue, aColumnItemNode.AliasId, aColumnItemNode.ValueAssignment));

            }

            #endregion

            #region whereClauseOpt

            if (parseNode.ChildNodes[4].ChildNodes != null && parseNode.ChildNodes[4].ChildNodes.Count > 0)
            {
                WhereExpressionNode tempWhereNode = (WhereExpressionNode)parseNode.ChildNodes[4].AstNode;
                if (tempWhereNode.BinaryExpressionDefinition != null)
                {
                    WhereExpressionDefinition = tempWhereNode.BinaryExpressionDefinition;
                }
            }

            #endregion

            #region groupClauseOpt

            if (HasChildNodes(parseNode.ChildNodes[5]) && HasChildNodes(parseNode.ChildNodes[5].ChildNodes[2]))
            {
                foreach (ParseTreeNode node in parseNode.ChildNodes[5].ChildNodes[2].ChildNodes)
                {
                    GroupByIDs.Add(((IDNode)node.AstNode).IDChainDefinition);
                }
            }

            #endregion

            #region havingClauseOpt

            if (HasChildNodes(parseNode.ChildNodes[6]))
            {
                Having = ((BinaryExpressionNode)parseNode.ChildNodes[6].ChildNodes[1].AstNode).BinaryExpressionDefinition;
            }

            #endregion

            #region orderClauseOpt

            if (HasChildNodes(parseNode.ChildNodes[7]))
            {
                OrderByDefinition = ((OrderByNode)parseNode.ChildNodes[7].AstNode).OrderByDefinition;
            }

            #endregion

            #region Offset

            if (HasChildNodes(parseNode.ChildNodes[8]))
            {
                Offset = ((OffsetNode)parseNode.ChildNodes[8].AstNode).Count;
            }

            #endregion

            #region Limit

            if (HasChildNodes(parseNode.ChildNodes[9]))
            {
                Limit = ((LimitNode)parseNode.ChildNodes[9].AstNode).Count;
            }

            #endregion

            #region Depth

            if (HasChildNodes(parseNode.ChildNodes[10]))
            {
                ResolutionDepth = Convert.ToUInt16(parseNode.ChildNodes[10].ChildNodes[1].Token.Value);
            }

            #endregion

            #region Select Output

            if (HasChildNodes(parseNode.ChildNodes[11]))
            {
                _SelectOutputType = (parseNode.ChildNodes[11].AstNode as SelectOutputOptNode).SelectOutputType;
            }

            #endregion
        }
Example #25
0
        /// <summary>
        /// returns a list of guids which match the tupleNode of the ListOfDBObjects object.
        /// </summary>
        public IEnumerable <Tuple <IVertex, Dictionary <String, object> > > GetCorrespondigDBObjectUUIDAsList(IVertexType myType, IVertexType validationType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            #region Evaluate tuple

            //ask guid-index of type
            foreach (TupleElement aTupleElement in TupleElements)
            {
                if (aTupleElement.Value is BinaryExpressionDefinition)
                {
                    #region Binary Expression

                    var aUniqueExpr = (BinaryExpressionDefinition)aTupleElement.Value;

                    aUniqueExpr.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, validationType);

                    var _graphResult = aUniqueExpr.Calculon(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, new CommonUsageGraph(myGraphDB, mySecurityToken, myTransactionToken));

                    foreach (var aDBO in _graphResult.Select(new LevelKey(validationType.ID, myGraphDB, mySecurityToken, myTransactionToken), null, true))
                    {
                        yield return(new Tuple <IVertex, Dictionary <String, object> >(aDBO, aTupleElement.Parameters));
                    }

                    #endregion
                }
                else
                {
                    #region tuple node

                    if (aTupleElement.Value is TupleDefinition)
                    {
                        var aTupleNode = (TupleDefinition)aTupleElement.Value;

                        if (IsValidTupleNode(aTupleNode.TupleElements, myType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken))
                        {
                            #region get partial results

                            BinaryExpressionDefinition tempNode = null;

                            foreach (TupleElement aElement in aTupleNode)
                            {
                                tempNode = (BinaryExpressionDefinition)aElement.Value;

                                ValidateBinaryExpression(tempNode, validationType, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken);

                                var tempGraphResult = tempNode.Calculon(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, new CommonUsageGraph(myGraphDB, mySecurityToken, myTransactionToken));

                                foreach (var aDBO in tempGraphResult.Select(new LevelKey(validationType.ID, myGraphDB, mySecurityToken, myTransactionToken), null, true))
                                {
                                    yield return(new Tuple <IVertex, Dictionary <String, object> >(aDBO, aTupleElement.Parameters));
                                }
                            }

                            #endregion
                        }
                    }
                    #endregion
                }
            }

            #endregion

            yield break;
        }