Exemplo n.º 1
0
 private static void ProcessAAttributeDefinition(GQLPluginManager myPluginManager,
                                                 IGraphDB myGraphDB,
                                                 SecurityToken mySecurityToken,
                                                 Int64 myTransactionToken,
                                                 IVertexType vertexType,
                                                 AAttributeAssignOrUpdate aAttributeDefinition,
                                                 ref RequestInsertVertex result)
 {
     if (vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString))
     {
         ProcessStructuredProperty(myPluginManager,
                                   myGraphDB,
                                   mySecurityToken,
                                   myTransactionToken,
                                   vertexType,
                                   aAttributeDefinition,
                                   ref result);
     }
     else
     {
         ProcessUnstructuredAttribute(vertexType,
                                      aAttributeDefinition,
                                      ref result);
     }
 }
Exemplo n.º 2
0
        private static void ProcessUnstructuredAttribute(IVertexType vertexType,
                                                         AAttributeAssignOrUpdate aAttributeDefinition,
                                                         ref RequestInsertVertex result)
        {
            #region AttributeAssignOrUpdateValue

            if (aAttributeDefinition is AttributeAssignOrUpdateValue)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateValue;

                result.AddUnstructuredProperty(value.AttributeIDChain.ContentString, value.Value);

                return;
            }

            #endregion

            else
            {
                throw new NotImplementedQLException("TODO");
            }
        }
Exemplo n.º 3
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region get myAttributeName

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

            #endregion

            var _Node = parseNode.ChildNodes[2];

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

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

                #endregion
            }
            else
            {
                throw new NotImplementedQLException("");
            }
        }
Exemplo n.º 4
0
        private static void ProcessStructuredProperty(GQLPluginManager myPluginManager,
                                                      IGraphDB myGraphDB,
                                                      SecurityToken mySecurityToken,
                                                      Int64 myTransactionToken,
                                                      IVertexType vertexType,
                                                      AAttributeAssignOrUpdate aAttributeDefinition,
                                                      ref RequestInsertVertex result)
        {
            #region AttributeAssignOrUpdateValue

            if (aAttributeDefinition is AttributeAssignOrUpdateValue)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateValue;

                result.AddUnknownProperty(value.AttributeIDChain.ContentString, value.Value);

                return;
            }

            #endregion

            #region AttributeAssignOrUpdateList

            if (aAttributeDefinition is AttributeAssignOrUpdateList)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateList;

                switch (value.CollectionDefinition.CollectionType)
                {
                case CollectionType.Set:

                    #region set

                    if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString))
                    {
                        throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.",
                                                                                vertexType.Name,
                                                                                aAttributeDefinition.AttributeIDChain.ContentString));
                    }

                    IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition
                                                                                       .AttributeIDChain
                                                                                       .ContentString);

                    EdgePredefinition edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            foreach (var aVertex in ProcessBinaryExpression(
                                         (BinaryExpressionDefinition)aTupleElement.Value,
                                         myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType))
                            {
                                var inneredge = new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID);

                                foreach (var aStructuredProperty in aTupleElement.Parameters)
                                {
                                    inneredge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                                }

                                edgeDefinition.AddEdge(inneredge);
                            }

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

                    result.AddEdge(edgeDefinition);

                    #endregion )

                    return;

                case CollectionType.List:

                    #region list

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();

                    Type myRequestedType;
                    if (vertexType.HasProperty(aAttributeDefinition.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType
                                           .GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.AddStructuredProperty(aAttributeDefinition.AttributeIDChain.ContentString, listWrapper);

                    #endregion )

                    return;

                case CollectionType.SetOfUUIDs:

                    #region SetOfUUIDs

                    EdgePredefinition anotheredgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)value.CollectionDefinition.TupleDefinition).Elements)
                    {
                        foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                        {
                            var innerEdge = new EdgePredefinition();

                            foreach (var aStructuredProperty in aVertexIDTuple.Item2)
                            {
                                innerEdge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                            }

                            innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                            anotheredgeDefinition.AddEdge(innerEdge);
                        }
                    }

                    result.AddEdge(anotheredgeDefinition);

                    #endregion

                    return;

                default:
                    return;
                }
            }

            #endregion

            #region SetRefNode

            if (aAttributeDefinition is AttributeAssignOrUpdateSetRef)
            {
                var value = aAttributeDefinition as AttributeAssignOrUpdateSetRef;

                var edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString);

                if (value.SetRefDefinition.IsREFUUID)
                {
                    #region direct vertex ids

                    foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is ValueDefinition)
                        {
                            #region ValueDefinition

                            foreach (var aProperty in aTupleElement.Parameters)
                            {
                                edgeDefinition.AddUnknownProperty(aProperty.Key, aProperty.Value);
                            }

                            edgeDefinition.AddVertexID(value.SetRefDefinition.ReferencedVertexType,
                                                       Convert.ToInt64(((ValueDefinition)aTupleElement.Value).Value));

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

                    #endregion
                }
                else
                {
                    #region expression

                    if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString))
                    {
                        throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.",
                                                                                vertexType.Name,
                                                                                aAttributeDefinition.AttributeIDChain.ContentString));
                    }
                    IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString);

                    foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition)
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType;

                            var vertexIDs = ProcessBinaryExpression(
                                (BinaryExpressionDefinition)aTupleElement.Value,
                                myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList();

                            if (vertexIDs.Count > 1)
                            {
                                throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices",
                                                                                             vertexIDs.Count));
                            }

                            var inneredge = new EdgePredefinition();

                            foreach (var aStructuredProperty in aTupleElement.Parameters)
                            {
                                edgeDefinition.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value);
                            }

                            edgeDefinition.AddVertexID(vertexIDs.FirstOrDefault().VertexTypeID, vertexIDs.FirstOrDefault().VertexID);

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

                    #endregion
                }

                result.AddEdge(edgeDefinition);

                return;
            }

            #endregion
        }
Exemplo n.º 5
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            var content = parseNode.FirstChild.AstNode as AddToListAttrUpdateNode;

            AttributeUpdateList = content.AttributeUpdateList;
        }
Exemplo n.º 6
0
        public void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            #region get myAttributeName

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

            #endregion

            var _Node = parseNode.ChildNodes[2];

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

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

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

                TupleNode tempTupleNode = (TupleNode)_Node.AstNode;

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

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

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

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

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

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