Ejemplo n.º 1
0
 public AttributeRemoveList(IDChainDefinition myIDChainDefinition, string myAttributeName, TupleDefinition myTupleDefinition)
 {
     // TODO: Complete member initialization
     this.AttributeIDChain = myIDChainDefinition;
     this.AttributeName = myAttributeName;
     this.TupleDefinition = myTupleDefinition;
 }
Ejemplo n.º 2
0
 public SetRefDefinition(TupleDefinition tupleDefinition, bool myIsREFUUID, String myReferencedVertexType, Dictionary<String, object> parameters)
 {
     TupleDefinition = tupleDefinition;
     IsREFUUID = myIsREFUUID;
     Parameters = parameters;
     ReferencedVertexType = myReferencedVertexType;
 }
Ejemplo n.º 3
0
        public override IEnumerable<ObjectUUID> IndexOperation(AAttributeIndex myIndex, TupleDefinition myTuple, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext)
        {
            if (myTuple.Count() != 2)
            {
                throw new GraphDBException(new Error_InvalidInRangeInterval(2, myTuple.Count()));
            }

            var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID);

            #region As soon as the index supports ranges use them!!

            //limits
            var fromKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myTuple.ElementAt(0).Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);
            var toKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myTuple.ElementAt(1).Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);

            switch (myTuple.KindOfTuple)
            {
                case KindOfTuple.Inclusive:
                    return myIndex.InRange(fromKey, toKey, true, true, currentType, dbContext);
                case KindOfTuple.LeftExclusive:
                    return myIndex.InRange(fromKey, toKey, false, true, currentType, dbContext);
                case KindOfTuple.RightExclusive:
                    return myIndex.InRange(fromKey, toKey, true, false, currentType, dbContext);
                case KindOfTuple.Exclusive:
                    return myIndex.InRange(fromKey, toKey, false, false, currentType, dbContext);
                default:
                    throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
            }

            #endregion
        }
Ejemplo n.º 4
0
 public SetRefDefinition(TupleDefinition tupleDefinition, bool myIsREFUUID, String myReferencedVertexType, Dictionary <String, object> parameters)
 {
     TupleDefinition      = tupleDefinition;
     IsREFUUID            = myIsREFUUID;
     Parameters           = parameters;
     ReferencedVertexType = myReferencedVertexType;
 }
Ejemplo n.º 5
0
        public SetRefDefinition(TupleDefinition tupleDefinition, Dictionary <String, object> myParameters)
        {
            System.Diagnostics.Debug.Assert(tupleDefinition != null);

            this.TupleDefinition = tupleDefinition;
            this.Parameters      = myParameters;
            ReferencedVertexType = null;
        }
Ejemplo n.º 6
0
        public SetRefDefinition(TupleDefinition tupleDefinition, Dictionary<String, object> myParameters)
        {

            System.Diagnostics.Debug.Assert(tupleDefinition != null);

            this.TupleDefinition = tupleDefinition;
            this.Parameters = myParameters;
            ReferencedVertexType = null;
        }
        /// <summary>
        /// Get the scope of an remove list update
        /// </summary>
        /// <param name="context">Irony compiler context</param>
        /// <param name="parseNode">The parse node that contains the information</param>
        public void GetContent(CompilerContext context, ParseTreeNode parseNode)
        {
            if (parseNode.ChildNodes[1].AstNode is CollectionOfDBObjectsNode)
            {
                var collection = parseNode.ChildNodes[1].AstNode as CollectionOfDBObjectsNode;

                if (collection.CollectionDefinition.CollectionType != CollectionType.SetOfUUIDs)
                {
                    throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                }

                TupleDefinition = collection.CollectionDefinition.TupleDefinition;
            }

            if (parseNode.ChildNodes[1].AstNode is TupleNode)
            {
                TupleDefinition = ((TupleNode)parseNode.ChildNodes[1].AstNode).TupleDefinition;
            }
        }
Ejemplo n.º 8
0
        public virtual AOperationDefinition GetValidTupleReloaded(TupleDefinition myTupleDefinition, DBContext dbContext)
        {
            switch (myTupleDefinition.KindOfTuple)
            {
                case KindOfTuple.Exclusive:

                    if (myTupleDefinition.TupleElements.Count == 1)
                    {
                        return myTupleDefinition.TupleElements[0].Value as ValueDefinition;
                    }
                    else
                    {
                        return myTupleDefinition;
                    }

                default:

                    return myTupleDefinition;

            }
        }
Ejemplo n.º 9
0
        public static AOperationDefinition GetValidTupleReloaded(TupleDefinition myTupleDefinition,
            IGraphDB myIGraphDB,
            SecurityToken mySecurityToken,
            TransactionToken myTransactionToken)
        {
            switch (myTupleDefinition.KindOfTuple)
            {
                case KindOfTuple.Exclusive:

                    if (myTupleDefinition.TupleElements.Count == 1)
                    {
                        return myTupleDefinition.TupleElements[0].Value as ValueDefinition;
                    }
                    else
                    {
                        return myTupleDefinition;
                    }

                default:

                    return myTupleDefinition;

            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="myTupleDefinition"></param>
 /// <returns></returns>
 private bool IsEncapsulatedBinaryExpression(TupleDefinition myTupleDefinition)
 {
     if (myTupleDefinition.Count() == 1)
     {
         if ((myTupleDefinition.First().Value is BinaryExpressionDefinition) || (myTupleDefinition.First().Value is UnaryExpressionDefinition))
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 11
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
        }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
0
        public override IEnumerable<ObjectUUID> IndexOperation(AAttributeIndex myIndex, TupleDefinition myTuple, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext)
        {
            HashSet<ObjectUUID> interestingUUIDs = new HashSet<ObjectUUID>();
            IndexKey idxLookupKey = null;
            var currentType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID);

            var myOperationValues = myTuple;

            switch (typeOfBinExpr)
            {
                case TypesOfBinaryExpression.LeftComplex:

                    if (!myIndex.IsListOfBaseObjectsIndex)
                    {
                        foreach (var aItem in myOperationValues)
                        {
                            idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (aItem.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);
                            interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));
                        }
                    }
                    else
                    {
                        #region In case the index is from a set or list of baseobjects we use this way to get the values

                        foreach (var aItem in myOperationValues)
                        {
                            idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (aItem.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);
                            interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));
                        }

                        /* What the hack is that??? - This is too slow for any usual usage of in operator! */

                        var indexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(myIndex.IndexRelatedTypeUUID);

                        foreach (var aKey in myIndex.GetKeys(currentType, dbContext).Where(item => !myOperationValues.Contains(new TupleElement(new ValueDefinition(item.IndexKeyValues[0])))))
                        {
                            foreach (var aMatch in myIndex.GetValues(aKey, indexRelatedType, dbContext).Intersect(interestingUUIDs))
                            {
                                interestingUUIDs.Remove(aMatch);
                            }
                        }

                        #endregion
                    }

                    break;

                case TypesOfBinaryExpression.RightComplex:

                    var myEnumerator = myOperationValues.GetEnumerator();

                    if (myEnumerator.MoveNext())
                    {
                        idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myEnumerator.Current.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);

                        interestingUUIDs.UnionWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));

                        while (myEnumerator.MoveNext())
                        {
                            idxLookupKey = new IndexKey(myIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs[0], (myEnumerator.Current.Value as ValueDefinition).Value, myIndex.IndexKeyDefinition);
                            interestingUUIDs.IntersectWith(myIndex.GetValues(idxLookupKey, currentType, dbContext));
                        }
                    }

                    break;

                case TypesOfBinaryExpression.Atom:
                case TypesOfBinaryExpression.Complex:
                case TypesOfBinaryExpression.Unknown:
                default:
                    break;
            }

            foreach (var aValidUUID in interestingUUIDs)
            {
                yield return aValidUUID;
            }

            yield break;
        }
Ejemplo n.º 14
0
        protected Exceptional<AOperationDefinition> SimpleOperation(TupleDefinition left, TupleDefinition right, TypesOfBinaryExpression myTypeOfBinaryExpression)
        {
            Object resultValue = true;
            HashSet<ADBBaseObject> anotherValues = new HashSet<ADBBaseObject>();

            switch (myTypeOfBinaryExpression)
            {
                case TypesOfBinaryExpression.LeftComplex:

                    #region left complex

                    //foreach (var aRightValue in right)
                    //{
                    //    anotherValues.Add(GraphDBTypeMapper.GetGraphObjectFromType(left.TypeOfOperatorResult, (aRightValue.Value as ValueDefinition).Value.Value));
                    //}

                    foreach (var aLeft in left)
                    {
                        if (!right.Contains(aLeft))
                        {
                            resultValue = false;
                            break;
                        }
                    }

                    #endregion

                    break;
                case TypesOfBinaryExpression.RightComplex:

                    #region right complex

                    //foreach (var aLeftValue in left.TupleValue.GetAllValues())
                    //{
                    //    anotherValues.Add(GraphDBTypeMapper.GetGraphObjectFromType(right.TupleValue.TypeOfValue, aLeftValue));
                    //}

                    foreach (var aAnother in left)
                    {
                        if (!right.Contains(aAnother))
                        {
                            resultValue = false;
                            break;
                        }
                    }

                    #endregion

                    break;
                default:
                    break;
            }

            return new Exceptional<AOperationDefinition>(new ValueDefinition(BasicType.Boolean, (object)resultValue));
        }
Ejemplo n.º 15
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
        }
Ejemplo n.º 16
0
 public CollectionDefinition(CollectionType myCollectionType, TupleDefinition myTupleDefinition)
 {
     CollectionType = myCollectionType;
     TupleDefinition = myTupleDefinition;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// This will check all tupe value. If it contains only one value it will be converted to a ValueDefinition. If it contains a SelectDefinition it will be executed and the result added to the tuple.
        /// </summary>
        /// <param name="myTupleDefinition"></param>
        /// <param name="myOperator"></param>
        /// <param name="myDBContext"></param>
        /// <returns></returns>
        private Exceptional<AOperationDefinition> AssignCorrectTuple(TupleDefinition myTupleDefinition, ABinaryOperator myOperator, DBContext myDBContext)
        {
            var retVal = new TupleDefinition(myTupleDefinition.KindOfTuple);
            var validTuple = myOperator.GetValidTupleReloaded(myTupleDefinition, myDBContext);

            if (validTuple is TupleDefinition)
            {
                foreach (var tupleVal in (validTuple as TupleDefinition))
                {
                    if (tupleVal.Value is ValueDefinition)
                    {
                        retVal.AddElement(tupleVal);
                    }
                    else if (tupleVal.Value is SelectDefinition)
                    {

                        #region partial select

                        var selectManager = new SelectManager();
                        var qresult = selectManager.ExecuteSelect(myDBContext, (tupleVal.Value as SelectDefinition));
                        if (qresult.Failed)
                        {
                            return new Exceptional<AOperationDefinition>(qresult.Errors);
                        }

                        TypeAttribute curAttr = ((tupleVal.Value as SelectDefinition).SelectedElements.First().Item1 as IDChainDefinition).LastAttribute;

                        var dbTypeOfAttribute = curAttr.GetDBType(myDBContext.DBTypeManager);

                        var aTypeOfOperatorResult = GraphDBTypeMapper.ConvertGraph2CSharp(dbTypeOfAttribute.Name);

                        foreach (var _Vertex in qresult.Vertices)
                        {
                            if (!(_Vertex.IsAttribute(curAttr.Name)))
                                continue;

                            if (curAttr != null)
                            {
                                var val = new ValueDefinition(aTypeOfOperatorResult, _Vertex.ObsoleteAttributes[curAttr.Name]);
                                retVal.AddElement(new TupleElement(aTypeOfOperatorResult, val));
                            }
                            else
                            {
                                return new Exceptional<AOperationDefinition>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                            }
                        }

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

            return new Exceptional<AOperationDefinition>(retVal);
        }
Ejemplo n.º 18
0
        public Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, TupleDefinition right)
        {
            right.Remove(left);

            return new Exceptional<AOperationDefinition>(right);
        }
Ejemplo n.º 19
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
        }
Ejemplo n.º 20
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            //TupleDefinition = new TupleDefinition(GetKindOfTuple(context, parseNode));
            TupleDefinition = new TupleDefinition();

            ParseTreeNodeList childNodes;

            if (parseNode.ChildNodes[0].AstNode == null && parseNode.ChildNodes[0].ChildNodes.Count > 0) // this is a not resolved node and has childNodes
            {
                childNodes = parseNode.ChildNodes[0].ChildNodes;
            }

            else // single expression tuple - SetRefNode seems MarkTransient the tuple
            {
                childNodes = parseNode.ChildNodes;
            }

            #region get tuple elements

            foreach (ParseTreeNode aExpressionNode in childNodes)
            {
                #region Data

                Type         typeOfExpression = null;
                TupleElement aElement         = null;

                #endregion

                #region Check the AstNode type and set the typeOfExpression. In case of a tuple just add them.

                if (aExpressionNode.Term != null)
                {
                    if ((aExpressionNode.Term.Name == SonesGQLConstants.BracketLeft) || (aExpressionNode.Term.Name == SonesGQLConstants.BracketRight))
                    {
                        continue;
                    }
                }

                if (aExpressionNode.AstNode is ExpressionOfAListNode)
                {
                    typeOfExpression = ((ExpressionOfAListNode)aExpressionNode.AstNode).GetType();
                }
                else if (aExpressionNode.AstNode is ExpressionNode)
                {
                    typeOfExpression = ((ExpressionNode)aExpressionNode.AstNode).GetType();
                }
                else if (aExpressionNode.AstNode is BinaryExpressionNode)
                {
                    typeOfExpression = aExpressionNode.Term.GetType();
                }
                else if (aExpressionNode.AstNode is UnaryExpressionNode)
                {
                    typeOfExpression = aExpressionNode.Term.GetType();
                }
                else if (aExpressionNode.AstNode is TupleNode)
                {
                    TupleDefinition = ((TupleNode)aExpressionNode.AstNode).TupleDefinition;
                    continue;
                }
                else if (aExpressionNode.AstNode is PartialSelectStmtNode)
                {
                    typeOfExpression = aExpressionNode.Term.GetType();
                }
                else if (aExpressionNode.AstNode is IDNode)
                {
                    throw new NotImplementedQLException("");
                }
                else
                {
                    var val = new ValueDefinition(aExpressionNode.Token.Value);
                    TupleDefinition.AddElement(new TupleElement(val));
                    continue;
                }

                #endregion

                if (aExpressionNode.AstNode is ExpressionNode)
                {
                    aElement = new TupleElement(((ExpressionNode)aExpressionNode.AstNode).ExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is ExpressionOfAListNode)
                {
                    aElement = new TupleElement((((ExpressionOfAListNode)aExpressionNode.AstNode).ExpressionDefinition));

                    if (((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters != null)
                    {
                        aElement.Parameters = ((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters;
                    }
                }
                else if (aExpressionNode.AstNode is BinaryExpressionNode)
                {
                    aElement = new TupleElement((aExpressionNode.AstNode as BinaryExpressionNode).BinaryExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is UnaryExpressionNode)
                {
                    aElement = new TupleElement((aExpressionNode.AstNode as UnaryExpressionNode).UnaryExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is PartialSelectStmtNode)
                {
                    #region partial select

                    aElement = new TupleElement(((PartialSelectStmtNode)aExpressionNode.AstNode).SelectDefinition);

                    #endregion
                }

                else if (aExpressionNode.AstNode is ExpressionNode)
                {
                    aElement = new TupleElement(((ExpressionNode)aExpressionNode.AstNode).ExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is ExpressionOfAListNode)
                {
                    aElement = new TupleElement(((ExpressionOfAListNode)aExpressionNode.AstNode).ExpressionDefinition);

                    if (((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters != null)
                    {
                        aElement.Parameters = ((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters;
                    }
                }
                else
                {
                    throw new NotImplementedQLException("");
                }

                TupleDefinition.AddElement(aElement);
            }

            #endregion
        }
Ejemplo n.º 21
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            //TupleDefinition = new TupleDefinition(GetKindOfTuple(context, parseNode));
            TupleDefinition = new TupleDefinition();

            ParseTreeNodeList childNodes;
            if (parseNode.ChildNodes[0].AstNode == null && parseNode.ChildNodes[0].ChildNodes.Count > 0) // this is a not resolved node and has childNodes
            {
                childNodes = parseNode.ChildNodes[0].ChildNodes;
            }

            else // single expression tuple - SetRefNode seems MarkTransient the tuple
            {
                childNodes = parseNode.ChildNodes;
            }

            #region get tuple elements

            foreach (ParseTreeNode aExpressionNode in childNodes)
            {

                #region Data

                Type typeOfExpression = null;
                TupleElement aElement = null;

                #endregion

                #region Check the AstNode type and set the typeOfExpression. In case of a tuple just add them.

                if (aExpressionNode.Term != null)
                {
                    if ((aExpressionNode.Term.Name == SonesGQLConstants.BracketLeft) || (aExpressionNode.Term.Name == SonesGQLConstants.BracketRight))
                    {
                        continue;
                    }
                }

                if (aExpressionNode.AstNode is ExpressionOfAListNode)
                {
                    typeOfExpression = ((ExpressionOfAListNode)aExpressionNode.AstNode).GetType();
                }
                else if (aExpressionNode.AstNode is ExpressionNode)
                {
                    typeOfExpression = ((ExpressionNode)aExpressionNode.AstNode).GetType();
                }
                else if (aExpressionNode.AstNode is BinaryExpressionNode)
                {
                    typeOfExpression = aExpressionNode.Term.GetType();
                }
                else if (aExpressionNode.AstNode is UnaryExpressionNode)
                {
                    typeOfExpression = aExpressionNode.Term.GetType();
                }
                else if (aExpressionNode.AstNode is TupleNode)
                {
                    TupleDefinition = ((TupleNode)aExpressionNode.AstNode).TupleDefinition;
                    continue;
                }
                else if (aExpressionNode.AstNode is PartialSelectStmtNode)
                {
                    typeOfExpression = aExpressionNode.Term.GetType();
                }
                else if (aExpressionNode.AstNode is IDNode)
                {
                    throw new NotImplementedQLException("");
                }
                else
                {
                    var val = new ValueDefinition(aExpressionNode.Token.Value);
                    TupleDefinition.AddElement(new TupleElement(val));
                    continue;
                }

                #endregion

                if (aExpressionNode.AstNode is ExpressionNode)
                {
                    aElement = new TupleElement(((ExpressionNode)aExpressionNode.AstNode).ExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is ExpressionOfAListNode)
                {
                    aElement = new TupleElement((((ExpressionOfAListNode)aExpressionNode.AstNode).ExpressionDefinition));

                    if (((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters != null)
                    {
                        aElement.Parameters = ((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters;
                    }
                }
                else if (aExpressionNode.AstNode is BinaryExpressionNode)
                {
                    aElement = new TupleElement((aExpressionNode.AstNode as BinaryExpressionNode).BinaryExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is UnaryExpressionNode)
                {
                    aElement = new TupleElement((aExpressionNode.AstNode as UnaryExpressionNode).UnaryExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is PartialSelectStmtNode)
                {
                    #region partial select

                    aElement = new TupleElement(((PartialSelectStmtNode)aExpressionNode.AstNode).SelectDefinition);

                    #endregion
                }

                else if (aExpressionNode.AstNode is ExpressionNode)
                {
                    aElement = new TupleElement(((ExpressionNode)aExpressionNode.AstNode).ExpressionDefinition);
                }
                else if (aExpressionNode.AstNode is ExpressionOfAListNode)
                {
                    aElement = new TupleElement(((ExpressionOfAListNode)aExpressionNode.AstNode).ExpressionDefinition);

                    if (((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters != null)
                    {
                        aElement.Parameters = ((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters;
                    }
                }
                else
                {
                    throw new NotImplementedQLException("");
                }

                TupleDefinition.AddElement(aElement);

            }

            #endregion
        }
Ejemplo n.º 22
0
        /// <summary>
        /// This will check all tupe value. If it contains only one value it will be converted to a ValueDefinition. If it contains a SelectDefinition it will be executed and the result added to the tuple.
        /// </summary>
        private AOperationDefinition AssignCorrectTuple(GQLPluginManager myPluginManager, 
                                                        TupleDefinition myTupleDefinition, 
                                                        BinaryOperator myOperator, 
                                                        IGraphDB myGraphDB, 
                                                        SecurityToken mySecurityToken, 
                                                        Int64 myTransactionToken)
        {
            var retVal = new TupleDefinition(myTupleDefinition.KindOfTuple);
            var validTuple = ABinaryOperator.GetValidTupleReloaded(myTupleDefinition, myGraphDB, mySecurityToken, myTransactionToken);

            if (validTuple is TupleDefinition)
            {
                foreach (var tupleVal in (validTuple as TupleDefinition))
                {
                    if (tupleVal.Value is ValueDefinition)
                    {
                        retVal.AddElement(tupleVal);
                    }
                    else if (tupleVal.Value is SelectDefinition)
                    {

                        #region partial select

                        var selectManager = new SelectManager(myGraphDB, myPluginManager);
                        var qresult = selectManager.ExecuteSelect(mySecurityToken, myTransactionToken, (tupleVal.Value as SelectDefinition), String.Empty);
                        if (qresult.Error !=  null)
                        {
                            throw qresult.Error;
                        }

                        IAttributeDefinition curAttr = ((tupleVal.Value as SelectDefinition).SelectedElements.First().Item1 as IDChainDefinition).LastAttribute;

                        foreach (var _Vertex in qresult.Vertices)
                        {
                            if (!(_Vertex.HasProperty(curAttr.Name)))
                                continue;

                            if (curAttr != null)
                            {
                                var val = new ValueDefinition(_Vertex.GetProperty<Object>(curAttr.Name));
                                retVal.AddElement(new TupleElement(val));
                            }
                            else
                            {
                                throw new NotImplementedQLException("");
                            }
                        }


                        #endregion
                    }
                    else
                    {
                        throw new NotImplementedQLException("");
                    }
                }
            }
            else
            {
                return validTuple;
            }

            return retVal;
        }
Ejemplo n.º 23
0
        protected Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, TupleDefinition right, TypesOfBinaryExpression myTypeOfBinaryExpression)
        {
            #region Data

            ValueDefinition resultObject = null;
            Object resultValue = false;

            #endregion

            resultValue = right.Contains(new TupleElement(left));

            resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue);

            return new Exceptional<AOperationDefinition>(resultObject);
        }
Ejemplo n.º 24
0
        private Exceptional<Boolean> MatchComplexData(TypesOfAssociativity associativity, DataContainer data, DBContext dbContext, DBObjectCache dbObjectCache, TypesOfBinaryExpression typeOfBinExpr, IEnumerable<Tuple<GraphDBType, AAttributeIndex>> leftIndices, IEnumerable<Tuple<GraphDBType, AAttributeIndex>> rightIndices, ref List<GraphDBError> errors, ref IExpressionGraph result, SessionSettings mySessionToken)
        {
            #region data

            Dictionary<DBObjectStream, AOperationDefinition> operandsLeft = null;
            Dictionary<DBObjectStream, AOperationDefinition> operandsRight = null;

            #endregion

            #region handle extraordinaries

            if (data.Extraordinaries.Item1 != null)
            {
                #region left extraordinary
                //there is something like a function or so

                operandsLeft = new Dictionary<DBObjectStream, AOperationDefinition>();

                //we have to calculate the real operand.
                //TODO: try to use attribute idx instead of uuid idx

                foreach (var aLeftIDX in leftIndices)
                {
                    AAttributeIndex currentLeftIdx = null;

                    #region get UUID idx
                    if (!(aLeftIDX.Item2.IsUUIDIndex))
                    {
                        currentLeftIdx = aLeftIDX.Item1.GetUUIDIndex(dbContext);
                    }
                    else
                    {
                        currentLeftIdx = aLeftIDX.Item2;
                    }

                    #endregion

                    var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(currentLeftIdx.IndexRelatedTypeUUID);

                    foreach (var aObjectUUIDs_Left in currentLeftIdx.GetAllValues(currentIndexRelatedType, dbContext))
                    {
                        foreach (var aObjectUUID_Left in aObjectUUIDs_Left)
                        {
                            var leftDBObject = dbObjectCache.LoadDBObjectStream(aLeftIDX.Item1, aObjectUUID_Left);
                            if (leftDBObject.Failed())
                            {
                                throw new NotImplementedException();
                            }

                            if (IsValidDBObjectStreamForBinExpr(leftDBObject.Value, data.IDChainDefinitions.Item1.LastAttribute, dbContext.DBTypeManager))
                            {
                                var oper = GetOperand(data.IDChainDefinitions.Item1, data.Extraordinaries.Item1, dbContext, leftDBObject.Value, dbObjectCache, mySessionToken);
                                if (oper.Failed())
                                    return new Exceptional<bool>(oper);

                                if (oper != null)
                                {
                                    operandsLeft.Add(leftDBObject.Value, oper.Value);
                                }
                            }
                        }
                    }
                }

                //from now on the binary expression is right complex, because there are atom values on the left
                typeOfBinExpr = TypesOfBinaryExpression.RightComplex;

                #endregion
            }

            if (data.Extraordinaries.Item2 != null)
            {
                #region right extraordinary
                //there is something like a function or so
                operandsRight = new Dictionary<DBObjectStream, AOperationDefinition>();

                foreach (var aRightIDX in rightIndices)
                {
                    AAttributeIndex currentRightIdx = null;

                    #region get UUID idx
                    //we have to calculate the real operand.
                    //TODO: try to use attribute idx instead of uuid idx

                    if (!(aRightIDX.Item2.IsUUIDIndex))
                    {
                        currentRightIdx = aRightIDX.Item1.GetUUIDIndex(dbContext);
                    }
                    else
                    {
                        currentRightIdx = aRightIDX.Item2;
                    }

                    #endregion

                    var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(currentRightIdx.IndexRelatedTypeUUID);

                    foreach (var aObjectUUIDs_Right in currentRightIdx.GetAllValues(currentIndexRelatedType, dbContext))
                    {
                        foreach (var aObjectUUID_Right in aObjectUUIDs_Right)
                        {
                            var rightDBObject = dbObjectCache.LoadDBObjectStream(aRightIDX.Item1, aObjectUUID_Right);
                            if (rightDBObject.Failed())
                            {
                                throw new NotImplementedException();
                            }

                            if (IsValidDBObjectStreamForBinExpr(rightDBObject.Value, data.IDChainDefinitions.Item2.LastAttribute, dbContext.DBTypeManager))
                            {
                                var oper = GetOperand(data.IDChainDefinitions.Item2, data.Extraordinaries.Item2, dbContext, rightDBObject.Value, dbObjectCache, mySessionToken);
                                if (oper.Failed())
                                    return new Exceptional<bool>(oper);

                                if (oper != null)
                                {
                                    operandsRight.Add(rightDBObject.Value, oper.Value);
                                }
                            }
                        }
                    }
                }

                if (typeOfBinExpr == TypesOfBinaryExpression.RightComplex)
                {
                    typeOfBinExpr = TypesOfBinaryExpression.Atom;
                }

                #endregion
            }

            #endregion

            switch (typeOfBinExpr)
            {
                case TypesOfBinaryExpression.Atom:

                    #region atom

                    switch (associativity)
                    {
                        case TypesOfAssociativity.Unknown:
                        case TypesOfAssociativity.Neutral:
                            GetComplexAtom(dbContext, operandsLeft, operandsRight, data.IDChainDefinitions.Item1, dbObjectCache, ref result);
                            GetComplexAtom(dbContext, operandsRight, operandsLeft, data.IDChainDefinitions.Item2, dbObjectCache, ref result);
                            break;

                        case TypesOfAssociativity.Left:

                            GetComplexAtom(dbContext, operandsLeft, operandsRight, data.IDChainDefinitions.Item1, dbObjectCache, ref result);

                            break;
                        case TypesOfAssociativity.Right:

                            GetComplexAtom(dbContext, operandsRight, operandsLeft, data.IDChainDefinitions.Item2, dbObjectCache, ref result);

                            break;

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

                    #endregion

                    break;
                case TypesOfBinaryExpression.LeftComplex:

                    #region Left complex

                    GetComplexMatch(leftIndices, operandsRight, dbObjectCache, data.IDChainDefinitions.Item1, data.IDChainDefinitions.Item2, dbContext, associativity, ref result, mySessionToken);

                    #endregion

                    break;
                case TypesOfBinaryExpression.RightComplex:

                    #region Right complex

                    GetComplexMatch(rightIndices, operandsLeft, dbObjectCache, data.IDChainDefinitions.Item2, data.IDChainDefinitions.Item1, dbContext, associativity, ref result, mySessionToken);

                    #endregion

                    break;
                case TypesOfBinaryExpression.Complex:

                    #region Complex

                    LevelKey leftLevelKey = CreateLevelKey(data.IDChainDefinitions.Item1, dbContext.DBTypeManager);
                    LevelKey rightLevelKey = CreateLevelKey(data.IDChainDefinitions.Item2, dbContext.DBTypeManager);
                    GraphDBType leftGraphDBType = data.IDChainDefinitions.Item1.LastType;
                    GraphDBType rightGraphDBType = data.IDChainDefinitions.Item2.LastType;

                    #region exception

                    if (leftIndices.CountIsGreater(1) || rightIndices.CountIsGreater(1))
                    {
                        return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                    }

                    #endregion

                    var leftIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(leftIndices.First().Item2.IndexRelatedTypeUUID);
                    var rightIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(rightIndices.First().Item2.IndexRelatedTypeUUID);

                    foreach (var ObjectUUIDs_left in leftIndices.First().Item2.GetAllValues(leftIndexRelatedType, dbContext))
                    {
                        foreach (var aLeftUUID in ObjectUUIDs_left)
                        {
                            var leftDBObject = dbObjectCache.LoadDBObjectStream(leftIndices.First().Item1, aLeftUUID);
                            if (leftDBObject.Failed())
                            {
                                return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                            }

                            if (IsValidDBObjectStreamForBinExpr(leftDBObject.Value, data.IDChainDefinitions.Item1.LastAttribute, dbContext.DBTypeManager))
                            {

                                foreach (var ObjectUUIDs_right in rightIndices.First().Item2.GetAllValues(rightIndexRelatedType, dbContext))
                                {
                                    foreach (var aRightUUID in ObjectUUIDs_right)
                                    {

                                        var rightDBObject = dbObjectCache.LoadDBObjectStream(rightIndices.First().Item1, aRightUUID);
                                        if (rightDBObject.Failed())
                                        {
                                            return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                                        }

                                        if (IsValidDBObjectStreamForBinExpr(rightDBObject.Value, data.IDChainDefinitions.Item2.LastAttribute, dbContext.DBTypeManager))
                                        {
                                            //everything is valid

                                            var leftType = GraphDBTypeMapper.ConvertGraph2CSharp(data.IDChainDefinitions.Item1.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);
                                            var rightType = GraphDBTypeMapper.ConvertGraph2CSharp(data.IDChainDefinitions.Item2.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);

                                            AOperationDefinition leftValue;
                                            AOperationDefinition rightValue;

                                            if (data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.SetOfReferences
                                                || data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.ListOfNoneReferences || data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.SetOfNoneReferences)
                                                leftValue = new TupleDefinition(leftType, leftDBObject.Value.GetAttribute(data.IDChainDefinitions.Item1.LastAttribute.UUID), data.IDChainDefinitions.Item1.LastAttribute.GetDBType(dbContext.DBTypeManager));
                                            else
                                                leftValue = new ValueDefinition(leftType, leftDBObject.Value.GetAttribute(data.IDChainDefinitions.Item1.LastAttribute.UUID, data.IDChainDefinitions.Item1.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext));

                                            if (data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.SetOfReferences
                                                || data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.ListOfNoneReferences || data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.SetOfNoneReferences)
                                                rightValue = new TupleDefinition(rightType, rightDBObject.Value.GetAttribute(data.IDChainDefinitions.Item2.LastAttribute.UUID), data.IDChainDefinitions.Item2.LastAttribute.GetDBType(dbContext.DBTypeManager));
                                            else
                                                rightValue = new ValueDefinition(rightType, rightDBObject.Value.GetAttribute(data.IDChainDefinitions.Item2.LastAttribute.UUID, data.IDChainDefinitions.Item2.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext));

                                            var tempSimpleOperationResult = this.SimpleOperation(leftValue, rightValue, typeOfBinExpr);
                                            if (tempSimpleOperationResult.Failed())
                                                return new Exceptional<bool>(tempSimpleOperationResult);

                                            var tempOperatorResult = tempSimpleOperationResult.Value;

                                            if ((Boolean)(tempOperatorResult as ValueDefinition).Value.Value)
                                            {
                                                //found sth that is really true

                                                #region insert into graph

                                                switch (associativity)
                                                {
                                                    case TypesOfAssociativity.Neutral:
                                                    case TypesOfAssociativity.Left:

                                                        IntegrateInGraph(leftDBObject.Value, result, leftLevelKey, dbContext, dbObjectCache);

                                                        break;
                                                    case TypesOfAssociativity.Right:

                                                        IntegrateInGraph(rightDBObject.Value, result, rightLevelKey, dbContext, dbObjectCache);

                                                        break;
                                                    case TypesOfAssociativity.Unknown:

                                                        if (Type == TypesOfOperators.AffectsLowerLevels)
                                                        {
                                                            result.AddNodesWithComplexRelation(leftDBObject, leftLevelKey, rightDBObject, rightLevelKey, dbObjectCache, 1);
                                                        }
                                                        else
                                                        {
                                                            result.AddNodesWithComplexRelation(leftDBObject, leftLevelKey, rightDBObject, rightLevelKey, dbObjectCache, 0);
                                                        }

                                                        break;
                                                    default:

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

                                                #endregion
                                            }
                                        }
                                    }
                                }

                                #region clean lower levels

                                if (Type == TypesOfOperators.AffectsLowerLevels)
                                {
                                    switch (associativity)
                                    {
                                        case TypesOfAssociativity.Neutral:
                                        case TypesOfAssociativity.Left:

                                            CleanLowerLevel(leftLevelKey, dbContext, dbObjectCache, result);

                                            break;
                                        case TypesOfAssociativity.Right:

                                            CleanLowerLevel(rightLevelKey, dbContext, dbObjectCache, result);

                                            break;
                                        case TypesOfAssociativity.Unknown:

                                            CleanLowerLevel(leftLevelKey, dbContext, dbObjectCache, result);
                                            CleanLowerLevel(rightLevelKey, dbContext, dbObjectCache, result);

                                            break;
                                        default:

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

                                #endregion
                            }
                        }
                    }

                    #endregion

                    break;
                default:

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

            return new Exceptional<bool>(true);
        }
Ejemplo n.º 25
0
 public override AOperationDefinition GetValidTupleReloaded(TupleDefinition aTupleNode, DBContext dbContext)
 {
     return CreateTupleValue(aTupleNode);
 }
Ejemplo n.º 26
0
 public virtual IEnumerable<ObjectUUID> IndexOperation(AAttributeIndex myIndex, TupleDefinition myOperationValues, TypesOfBinaryExpression typeOfBinExpr, DBContext dbContext)
 {
     throw new GraphDBException(new Error_InvalidIndexOperation(myIndex.IndexName));
 }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
 protected AOperationDefinition CreateTupleValue(TupleDefinition myTupleDefinition)
 {
     return myTupleDefinition;
 }
Ejemplo n.º 29
0
        protected Exceptional<AOperationDefinition> SimpleOperation(TupleDefinition left, TupleDefinition right)
        {
            #region Data

            ValueDefinition resultObject = null;
            Object resultValue = false;

            #endregion

            //foreach (ADBBaseObject leftObj in left.Values)
            foreach (var valLeft in left)
            {
                ADBBaseObject leftObj = (valLeft.Value as ValueDefinition).Value;
                //foreach (ADBBaseObject rightObj in right.Values)
                foreach(var valRight in right)
                {
                    ADBBaseObject rightObj = (valRight.Value as ValueDefinition).Value;

                    if (!GraphDBTypeMapper.ConvertToBestMatchingType(ref leftObj, ref rightObj).Value)
                    {
                        return new Exceptional<AOperationDefinition>(new Error_DataTypeDoesNotMatch(leftObj.Type.ToString(), rightObj.Type.ToString()));
                    }

                    var res = Compare(leftObj, rightObj);
                    if (res.Failed())
                        return new Exceptional<AOperationDefinition>(res);

                    if (res.Value)
                    {
                        resultValue = true;
                    }
                    else
                    {
                        resultValue = false;
                        break;
                    }
                }
                if (!(Boolean)resultValue)
                    break;
            }
            resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue);

            return new Exceptional<AOperationDefinition>(resultObject);
        }
Ejemplo n.º 30
0
        protected new Exceptional<AOperationDefinition> SimpleOperation(TupleDefinition left, TupleDefinition right)
        {
            #region Data

            ValueDefinition resultObject = null;
            Object resultValue = false;

            #endregion

            foreach (var leftVal in left)
            {
                foreach (var rightVal in right)
                {
                    var comp = Compare((leftVal.Value as ValueDefinition).Value, (rightVal.Value as ValueDefinition).Value);
                    if (comp.Failed())
                        return new Exceptional<AOperationDefinition>(comp);

                    if (!comp.Value)
                    {
                        resultValue = false;
                        break;
                    }
                    else
                    {
                        resultValue = true;
                    }
                }
                if ((Boolean)resultValue) break;
            }

            resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue);

            return new Exceptional<AOperationDefinition>(resultObject);
        }
Ejemplo n.º 31
0
        protected AOperationDefinition CreateTupleValue(TupleDefinition myTupleDefinition)
        {
            //var result = new TupleDefinition(myTupleDefinition.KindOfTuple);

            //foreach (var item in myTupleDefinition)
            //{
            //    result.AddElement(new TupleElement((item.Value as ValueDefinition)));
            //}

            //return result;
            return myTupleDefinition;
        }
Ejemplo n.º 32
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);
        }
Ejemplo n.º 33
0
        public Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, TupleDefinition right)
        {
            right.AddElement(new TupleElement(left));

            return new Exceptional<AOperationDefinition>(right);
        }
Ejemplo n.º 34
0
        public override void GetContent(CompilerContext myCompilerContext, ParseTreeNode myParseTreeNode)
        {
            var _GraphQLGrammar = GetGraphQLGrammar(myCompilerContext);

            _Targets = new HashSet<AAttributeAssignOrUpdateOrRemove>();

            #region FROM Sources

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

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

            if(_Sources.Count() > 1 )
            {
                var firstElement = (BinaryExpressionDefinition)_Sources.First().Value;
                _Sources.Remove(_Sources.First());
                _Condition = GetConditionNode(new OrOperator().ContraryOperationSymbol, 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.AsSymbol == _GraphQLGrammar.S_VIA)
            {
                _EdgeAttr = (myParseTreeNode.ChildNodes[4].AstNode as IDNode);
            }

            else // Human language style...
            {
                if (myParseTreeNode.ChildNodes[5].Token.AsSymbol == _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.AsSymbol == _GraphQLGrammar.S_TO)
            {
                typeNode = (myParseTreeNode.ChildNodes[6].ChildNodes[0].AstNode as ATypeNode);
                tupleDef = (myParseTreeNode.ChildNodes[6].ChildNodes[1].AstNode as TupleNode).TupleDefinition;
            }

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

            #endregion

            #region Processing...

            ParsingResult.PushIExceptional(typeNode.ParsingResult);

            var _TargetType        = typeNode.ReferenceAndType;
            var tupleDefTargetType = new TupleDefinition(tupleDef.KindOfTuple);

            foreach (var item in tupleDef.TupleElements)
            {

                var attrName = _TargetType.TypeName + DBConstants.EdgeTraversalDelimiterSymbol + ((IDChainDefinition)((BinaryExpressionDefinition)item.Value).Left).ContentString;
                var leftNode = new IDChainDefinition(attrName, new List<TypeReferenceDefinition>() { _TargetType });
                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(item.TypeOfValue, binExpression));

            }

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

            #endregion
        }
Ejemplo n.º 35
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
        }
Ejemplo n.º 36
0
        public Exceptional<AOperationDefinition> SimpleOperation(TupleDefinition left, TupleDefinition right)
        {
            right.Union(left);

            return new Exceptional<AOperationDefinition>(right);
        }