示例#1
0
 public IVertex UpdateVertex(SecurityToken mySecurityToken, TransactionToken myTransactionToken, long myToBeUpdatedVertexID, long myCorrespondingVertexTypeID, VertexUpdateDefinition myVertexUpdate, Boolean myCreateIncomingEdges = true, string myToBeUpdatedEditions = null, Int64 myToBeUpdatedRevisionIDs = 0L, bool myCreateNewRevision = false)
 {
     return _vertexStore.UpdateVertex(mySecurityToken, myTransactionToken, myToBeUpdatedVertexID, myCorrespondingVertexTypeID, myVertexUpdate, myCreateIncomingEdges, myToBeUpdatedEditions, myToBeUpdatedRevisionIDs, myCreateNewRevision);
 }
示例#2
0
        public override void Delete(RequestDelete myDeleteRequest, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            var toBeProcessedVertices = GetVertices(myDeleteRequest.ToBeDeletedVertices, myTransactionToken, mySecurityToken);

            if (myDeleteRequest.ToBeDeletedAttributes.IsNotNullOrEmpty())
            {
                List<long> toBeDeletedStructuredPropertiesUpdate = new List<long>();
                List<String> tobeDeletedUnstructuredProperties = new List<String>();
                List<long> toBeDeletedBinaryProperties = new List<long>();
                List<long> toBeDeletedSingleEdges = new List<long>();
                List<long> toBeDeletedHyperEdges = new List<long>();
                Dictionary<Int64, IPropertyDefinition> toBeDeletedProperties = new Dictionary<long, IPropertyDefinition>();
                Dictionary<Int64, IOutgoingEdgeDefinition> toBeDeletedEdges = new Dictionary<long, IOutgoingEdgeDefinition>();
                Dictionary<Int64, IBinaryPropertyDefinition> toBeDeletedBinaries = new Dictionary<long, IBinaryPropertyDefinition>();
                HashSet<String> toBeDeletedUndefinedAttributes = new HashSet<string>();

                //remove the attributes
                foreach (var aVertexTypeGroup in toBeProcessedVertices.GroupBy(_ => _.VertexTypeID))
                {
                    var vertexType = _vertexTypeManager.ExecuteManager.GetType(aVertexTypeGroup.Key, myTransactionToken, mySecurityToken);

                    #region prepare update definition

                    toBeDeletedStructuredPropertiesUpdate.Clear();
                    StructuredPropertiesUpdate structuredProperties = new StructuredPropertiesUpdate(null, toBeDeletedStructuredPropertiesUpdate);

                    tobeDeletedUnstructuredProperties.Clear();
                    UnstructuredPropertiesUpdate unstructuredProperties = new UnstructuredPropertiesUpdate(null, tobeDeletedUnstructuredProperties);

                    toBeDeletedBinaryProperties.Clear();
                    BinaryPropertiesUpdate binaryProperties = new BinaryPropertiesUpdate(null, toBeDeletedBinaryProperties);

                    toBeDeletedSingleEdges.Clear();
                    SingleEdgeUpdate singleEdges = new SingleEdgeUpdate(null, toBeDeletedSingleEdges);

                    toBeDeletedHyperEdges.Clear();
                    HyperEdgeUpdate hyperEdges = new HyperEdgeUpdate(null, toBeDeletedHyperEdges);

                    VertexUpdateDefinition update = new VertexUpdateDefinition(null, structuredProperties, unstructuredProperties, binaryProperties, singleEdges, hyperEdges);

                    #endregion

                    #region sorting attributes

                    toBeDeletedProperties.Clear();
                    toBeDeletedEdges.Clear();
                    toBeDeletedBinaries.Clear();
                    toBeDeletedUndefinedAttributes.Clear();

                    foreach (var aToBeDeleted in myDeleteRequest.ToBeDeletedAttributes)
                    {
                        if (!vertexType.HasAttribute(aToBeDeleted))
                        {
                            toBeDeletedUndefinedAttributes.Add(aToBeDeleted);
                        }

                        var attribute = vertexType.GetAttributeDefinition(aToBeDeleted);
                        myDeleteRequest.AddDeletedAttribute(attribute.ID);

                        switch (attribute.Kind)
                        {
                            case AttributeType.Property:
                                toBeDeletedProperties.Add(attribute.ID, (IPropertyDefinition)attribute);
                                break;

                            case AttributeType.OutgoingEdge:
                                toBeDeletedEdges.Add(attribute.ID, (IOutgoingEdgeDefinition)attribute);
                                break;

                            case AttributeType.BinaryProperty:
                                toBeDeletedBinaries.Add(attribute.ID, (IBinaryPropertyDefinition)attribute);
                                break;
                        }
                    }

                    #endregion

                    foreach (var aVertex in aVertexTypeGroup.ToList())
                    {
                        #region fetch to be deleted attributes

                        #region properties

                        foreach (var aToBeDeletedProperty in toBeDeletedProperties)
                        {
                            foreach (var aIndexDefinition in aToBeDeletedProperty.Value.InIndices)
                            {
                                RemoveFromIndices(aVertex, 
                                    _indexManager.GetIndices(vertexType, aIndexDefinition.IndexedProperties, mySecurityToken, myTransactionToken));
                            }
                            toBeDeletedStructuredPropertiesUpdate.Add(aToBeDeletedProperty.Key);
                        }

                        #endregion

                        #region edges

                        foreach (var aToBeDeltedEdge in toBeDeletedEdges)
                        {
                            if (aVertex.HasOutgoingEdge(aToBeDeltedEdge.Key))
                            {
                                switch (aToBeDeltedEdge.Value.Multiplicity)
                                {
                                    case EdgeMultiplicity.SingleEdge:

                                        toBeDeletedSingleEdges.Add(aToBeDeltedEdge.Key);

                                        break;
                                    case EdgeMultiplicity.MultiEdge:
                                    case EdgeMultiplicity.HyperEdge:

                                        toBeDeletedHyperEdges.Add(aToBeDeltedEdge.Key);

                                        break;
                                }
                            }
                        }

                        #endregion

                        #region binaries

                        foreach (var aBinaryProperty in toBeDeletedBinaryProperties)
                        {
                            //TODO: Add HasBinaryProperty to IVertex
                            if (aVertex.GetAllBinaryProperties((_, __) => _ == aBinaryProperty).Count() > 0)
                            {
                                toBeDeletedBinaryProperties.Add(aBinaryProperty);
                            }
                        }

                        #endregion

                        #region undefined data

                        foreach (var aUnstructuredProperty in toBeDeletedUndefinedAttributes)
                        {
                            if (aVertex.HasUnstructuredProperty(aUnstructuredProperty))
                            {
                                tobeDeletedUnstructuredProperties.Add(aUnstructuredProperty);
                            }
                        }

                        #endregion

                        #endregion

                        _vertexStore.UpdateVertex(mySecurityToken, myTransactionToken, aVertex.VertexID, aVertex.VertexTypeID, update, true, aVertex.EditionName, aVertex.VertexRevisionID, false);
                    }
                }
            }
            else
            {
                //remove the nodes
                foreach (var aVertexTypeGroup in toBeProcessedVertices.GroupBy(_ => _.VertexTypeID))
                {
                    var vertexType = _vertexTypeManager.ExecuteManager.GetType(aVertexTypeGroup.Key, myTransactionToken, mySecurityToken);

                    foreach (var aVertex in aVertexTypeGroup.ToList())
                    {
                        myDeleteRequest.AddDeletedVertex(aVertex.VertexID);
                        RemoveVertex(aVertex, vertexType, mySecurityToken, myTransactionToken);
                    }
                }
            }
        }
        public IVertex UpdateVertex(
            SecurityToken mySecurityToken, Int64 myTransactionID,
            long myToBeUpdatedVertexID, long myCorrespondingVertexTypeID,
            VertexUpdateDefinition myVertexUpdate, Boolean myCreateIncomingEdges = true,
            string myToBeUpdatedEditions = null, Int64 myToBeUpdatedRevisionIDs = 0L, bool myCreateNewRevision = false)
        {
            var toBeUpdatedVertex = GetVertexPrivate(myToBeUpdatedVertexID, myCorrespondingVertexTypeID);

            if (toBeUpdatedVertex == null || toBeUpdatedVertex.IsBulkVertex)
            {
                throw new VertexDoesNotExistException(myCorrespondingVertexTypeID, myToBeUpdatedVertexID);
            }

            var updatedVertex = UpdateVertex_private(toBeUpdatedVertex, myVertexUpdate);

            ConcurrentDictionary<Int64, InMemoryVertex> outValue;

            if (_vertexStore.TryGetValue(myCorrespondingVertexTypeID, out outValue))
            {
                outValue.AddOrUpdate(myToBeUpdatedVertexID, updatedVertex, (key, oldValue) =>
                {
                    lock (oldValue)
                    {
                        oldValue = updatedVertex;
                        return oldValue;
                    }
                });
            }

            return updatedVertex;
        }
        /// <summary>
        /// Updates an InMemoryVertex
        /// </summary>
        /// <param name="toBeUpdatedVertex">The vertex that should be updated</param>
        /// <param name="myVertexUpdate">The definition of the vertex update</param>
        /// <returns>The updated vertex</returns>
        private InMemoryVertex UpdateVertex_private(InMemoryVertex toBeUpdatedVertex,
                                                    VertexUpdateDefinition myVertexUpdate)
        {
            #region udpate comment

            if (myVertexUpdate.CommentUpdate != null)
            {
                toBeUpdatedVertex.UpdateComment(myVertexUpdate.CommentUpdate);
            }

            #endregion

            #region update binary properties

            if (myVertexUpdate.UpdatedBinaryProperties != null)
            {
                toBeUpdatedVertex.UpdateBinaryProperties(myVertexUpdate.UpdatedBinaryProperties.Updated,
                                                         myVertexUpdate.UpdatedBinaryProperties.Deleted);
            }

            #endregion

            #region udpate single edges

            if (myVertexUpdate.UpdatedSingleEdges != null)
            {
                if (toBeUpdatedVertex.OutgoingEdges == null)
                {
                    lock (toBeUpdatedVertex)
                    {
                        toBeUpdatedVertex.OutgoingEdges = new Dictionary<long, IEdge>();
                    }
                }

                lock (toBeUpdatedVertex.OutgoingEdges)
                {

                    #region delete edges

                    if (myVertexUpdate.UpdatedSingleEdges.Deleted != null)
                    {
                        foreach (var item in myVertexUpdate.UpdatedSingleEdges.Deleted)
                        {
                            IEdge edge = null;

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item, out edge))
                            {
                                if (edge is SingleEdge)
                                {
                                    var targetVertex = edge.GetTargetVertices().First();

                                    RemoveIncommingEdgeFromTargetVertex((InMemoryVertex)targetVertex, targetVertex.VertexTypeID, item, toBeUpdatedVertex);

                                    toBeUpdatedVertex.OutgoingEdges.Remove(item);
                                }
                            }
                        }
                    }

                    #endregion

                    #region update edges

                    if (myVertexUpdate.UpdatedSingleEdges.Updated != null)
                    {
                        foreach (var item in myVertexUpdate.UpdatedSingleEdges.Updated)
                        {
                            IEdge edge = null;
                            var targetVertex = GetOrCreateTargetVertex(item.Value.TargetVertex.VertexTypeID, item.Value.TargetVertex.VertexID);

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item.Key, out edge))
                            {
                                if (edge is SingleEdge)
                                {
                                    var singleEdge = (SingleEdge)edge;

                                    if (edge.Comment != null)
                                    {
                                        singleEdge.UpdateComment(item.Value.CommentUpdate);
                                    }

                                    if (item.Value.EdgeTypeID != null)
                                    {
                                        singleEdge.UpdateEdgeType(item.Value.EdgeTypeID);
                                    }

                                    if (item.Value.UpdatedStructuredProperties != null)
                                    {
                                        singleEdge.UpdateStructuredProperties(
                                        item.Value.UpdatedStructuredProperties.Updated,
                                        item.Value.UpdatedStructuredProperties.Deleted);
                                    }

                                    if (item.Value.UpdatedUnstructuredProperties != null)
                                    {
                                        singleEdge.UpdateUnStructuredProperties(
                                        item.Value.UpdatedUnstructuredProperties.Updated,
                                        item.Value.UpdatedUnstructuredProperties.Deleted);
                                    }

                                    if (item.Value.SourceVertex != null)
                                    {
                                        lock (singleEdge)
                                        {
                                            singleEdge.SourceVertex = toBeUpdatedVertex;
                                        }
                                    }

                                    if (item.Value.TargetVertex != null)
                                    {
                                        lock (singleEdge)
                                        {
                                            if (singleEdge.TargetVertex != null)
                                            {
                                                RemoveIncommingEdgeFromTargetVertex(singleEdge.TargetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                            }

                                            singleEdge.TargetVertex = targetVertex;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                edge = new SingleEdge(item.Value.EdgeTypeID,
                                                      toBeUpdatedVertex,
                                                      targetVertex,
                                                      item.Value.CommentUpdate, 0, 0,
                                                      item.Value.UpdatedStructuredProperties == null ? null : item.Value.UpdatedStructuredProperties.Updated, item.Value.UpdatedUnstructuredProperties == null ? null : item.Value.UpdatedUnstructuredProperties.Updated);

                                toBeUpdatedVertex.OutgoingEdges.Add(item.Key, edge);
                            }

                            CreateOrUpdateIncomingEdgesOnVertex(targetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                        }
                    }

                    #endregion
                }
            }

            #endregion

            #region update hyper edges

            if (myVertexUpdate.UpdateHyperEdges != null)
            {
                if (toBeUpdatedVertex.OutgoingEdges == null)
                {
                    lock (toBeUpdatedVertex)
                    {
                        toBeUpdatedVertex.OutgoingEdges = new Dictionary<long, IEdge>();
                    }
                }

                lock (toBeUpdatedVertex.OutgoingEdges)
                {
                    #region delete edges


                    if (myVertexUpdate.UpdateHyperEdges.Deleted != null)
                    {
                        foreach (var item in myVertexUpdate.UpdateHyperEdges.Deleted)
                        {
                            IEdge edge = null;

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item, out edge))
                            {
                                if (edge is HyperEdge)
                                {
                                    foreach (var targetVertex in edge.GetTargetVertices())
                                    {
                                        RemoveIncommingEdgeFromTargetVertex((InMemoryVertex)targetVertex, targetVertex.VertexTypeID, item, toBeUpdatedVertex);
                                    }

                                    toBeUpdatedVertex.OutgoingEdges.Remove(item);
                                }
                            }
                        }
                    }

                    #endregion

                    #region update edges

                    if (myVertexUpdate.UpdateHyperEdges.Updated != null)
                    {
                        foreach (var item in myVertexUpdate.UpdateHyperEdges.Updated)
                        {
                            IEdge edge = null;

                            if (toBeUpdatedVertex.OutgoingEdges.TryGetValue(item.Key, out edge))
                            {
                                if (edge is HyperEdge)
                                {
                                    var hyperEdge = (HyperEdge)edge;

                                    if (edge.Comment != null)
                                    {
                                        hyperEdge.UpdateComment(item.Value.CommentUpdate);
                                    }

                                    if (item.Value.EdgeTypeID != null)
                                    {
                                        hyperEdge.UpdateEdgeType(item.Value.EdgeTypeID);
                                    }

                                    if (item.Value.UpdatedUnstructuredProperties != null)
                                        hyperEdge.UpdateUnStructuredProperties(
                                            item.Value.UpdatedUnstructuredProperties.Updated,
                                            item.Value.UpdatedUnstructuredProperties.Deleted);

                                    if (item.Value.UpdatedStructuredProperties != null)
                                        hyperEdge.UpdateStructuredProperties(
                                            item.Value.UpdatedStructuredProperties.Updated,
                                            item.Value.UpdatedStructuredProperties.Deleted);

                                    #region update the containing single edges

                                    lock (hyperEdge.ContainedSingleEdges)
                                    {
                                        if (item.Value.ToBeDeletedSingleEdges != null)
                                        {
                                            foreach (var singleEdge in item.Value.ToBeDeletedSingleEdges)
                                            {
                                                var targetVertex = GetOrCreateTargetVertex(singleEdge.TargetVertex.VertexTypeID, singleEdge.TargetVertex.VertexID);
                                                RemoveIncommingEdgeFromTargetVertex(targetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                                hyperEdge.ContainedSingleEdges.RemoveWhere(sEdge => (sEdge.SourceVertex.VertexTypeID == singleEdge.SourceVertex.VertexTypeID && sEdge.SourceVertex.VertexID == singleEdge.SourceVertex.VertexID) && (sEdge.TargetVertex.VertexID == singleEdge.TargetVertex.VertexID && sEdge.TargetVertex.VertexTypeID == singleEdge.TargetVertex.VertexTypeID));
                                            }
                                        }

                                        if (item.Value.ToBeUpdatedSingleEdges != null)
                                        {
                                            var newEdges = new List<SingleEdge>();

                                            foreach (var contEdge in item.Value.ToBeUpdatedSingleEdges)
                                            {
                                                var targetVertex =
                                                    GetOrCreateTargetVertex(contEdge.TargetVertex.VertexTypeID,
                                                                            contEdge.TargetVertex.VertexID);

                                                foreach (var singleEdgeItem in hyperEdge.ContainedSingleEdges)
                                                {
                                                    var correspondTarget =
                                                        GetOrCreateTargetVertex(contEdge.TargetVertex.VertexTypeID,
                                                                                contEdge.TargetVertex.VertexID);

                                                    var correspondSource =
                                                        GetOrCreateTargetVertex(contEdge.SourceVertex.VertexTypeID,
                                                                                contEdge.SourceVertex.VertexID);

                                                    if (correspondTarget == singleEdgeItem.TargetVertex &&
                                                        singleEdgeItem.SourceVertex == correspondSource)
                                                    {
                                                        if (contEdge.CommentUpdate != null)
                                                        {
                                                            singleEdgeItem.UpdateComment(contEdge.CommentUpdate);
                                                        }

                                                        if (contEdge.EdgeTypeID != null)
                                                        {
                                                            singleEdgeItem.UpdateEdgeType(contEdge.EdgeTypeID);
                                                        }

                                                        if (contEdge.UpdatedStructuredProperties != null)
                                                        {
                                                            singleEdgeItem.UpdateStructuredProperties(
                                                                contEdge.UpdatedStructuredProperties.Updated,
                                                                contEdge.UpdatedStructuredProperties.Deleted);
                                                        }

                                                        if (contEdge.UpdatedUnstructuredProperties != null)
                                                        {
                                                            singleEdgeItem.UpdateUnStructuredProperties(
                                                                contEdge.UpdatedUnstructuredProperties.Updated,
                                                                contEdge.UpdatedUnstructuredProperties.Deleted);
                                                        }

                                                        if (contEdge.TargetVertex != null)
                                                        {
                                                            lock (singleEdgeItem)
                                                            {
                                                                if (singleEdgeItem.TargetVertex != null)
                                                                {
                                                                    RemoveIncommingEdgeFromTargetVertex(singleEdgeItem.TargetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                                                }

                                                                singleEdgeItem.TargetVertex = targetVertex;
                                                            }
                                                        }

                                                        if (contEdge.SourceVertex != null)
                                                        {
                                                            lock (singleEdgeItem)
                                                            {
                                                                singleEdgeItem.SourceVertex =
                                                                    GetOrCreateTargetVertex(
                                                                        contEdge.SourceVertex.VertexTypeID,
                                                                        contEdge.SourceVertex.VertexID);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        newEdges.Add(new SingleEdge(contEdge.EdgeTypeID,
                                                                                    toBeUpdatedVertex,
                                                                                    GetOrCreateTargetVertex(
                                                                                        contEdge.TargetVertex.
                                                                                            VertexTypeID,
                                                                                        contEdge.TargetVertex.VertexID),
                                                                                    contEdge.CommentUpdate, 0, 0,
                                                                                    contEdge.UpdatedStructuredProperties ==
                                                                                    null
                                                                                        ? null
                                                                                        : contEdge.
                                                                                              UpdatedStructuredProperties
                                                                                              .
                                                                                              Updated,
                                                                                    contEdge.
                                                                                        UpdatedUnstructuredProperties ==
                                                                                    null
                                                                                        ? null
                                                                                        : contEdge.
                                                                                              UpdatedUnstructuredProperties
                                                                                              .
                                                                                              Updated));
                                                    }
                                                }

                                                CreateOrUpdateIncomingEdgesOnVertex(targetVertex,
                                                                                    toBeUpdatedVertex.VertexTypeID,
                                                                                    item.Key, toBeUpdatedVertex);
                                                hyperEdge.ContainedSingleEdges.UnionWith(newEdges);
                                                newEdges.Clear();
                                            }
                                        }
                                    }

                                    #endregion
                                }
                            }
                            else
                            {

                                var singleEdges = new HashSet<SingleEdge>();

                                if (item.Value.ToBeUpdatedSingleEdges != null)
                                {
                                    foreach (var singleItem in item.Value.ToBeUpdatedSingleEdges)
                                    {
                                        var targetVertex = GetOrCreateTargetVertex(singleItem.TargetVertex.VertexTypeID, singleItem.TargetVertex.VertexID);

                                        singleEdges.Add(new SingleEdge(singleItem.EdgeTypeID, toBeUpdatedVertex, targetVertex,
                                                                       singleItem.CommentUpdate == null ? null : singleItem.CommentUpdate, 0, 0,
                                                                       singleItem.UpdatedStructuredProperties == null
                                                                           ? null
                                                                           : singleItem.UpdatedStructuredProperties.
                                                                                 Updated,
                                                                       singleItem.UpdatedUnstructuredProperties == null
                                                                           ? null
                                                                           : singleItem.UpdatedUnstructuredProperties.
                                                                                 Updated));

                                        CreateOrUpdateIncomingEdgesOnVertex(targetVertex, toBeUpdatedVertex.VertexTypeID, item.Key, toBeUpdatedVertex);
                                    }

                                    toBeUpdatedVertex.OutgoingEdges.Add(item.Key,
                                                                        new HyperEdge(singleEdges,
                                                                                      item.Value.EdgeTypeID,
                                                                                      toBeUpdatedVertex,
                                                                                      item.Value.CommentUpdate == null ? null : item.Value.CommentUpdate,
                                                                                      0, 0,
                                                                                      item.Value.UpdatedStructuredProperties == null ? null : item.Value.UpdatedStructuredProperties.Updated,
                                                                                          item.Value.UpdatedUnstructuredProperties == null ? null : item.Value.UpdatedUnstructuredProperties.Updated));

                                }
                            }

                        }
                    }

                    #endregion
                }
            }

            #endregion

            #region update unstructured properties

            if (myVertexUpdate.UpdatedUnstructuredProperties != null)
            {
                toBeUpdatedVertex.UpdateUnstructuredProperties(myVertexUpdate.UpdatedUnstructuredProperties);
            }

            #endregion

            #region update structured properties

            if (myVertexUpdate.UpdatedStructuredProperties != null)
            {
                toBeUpdatedVertex.UpdateStructuredProperties(myVertexUpdate.UpdatedStructuredProperties);
            }

            #endregion

            return toBeUpdatedVertex;
        }
示例#5
0
        /// <summary>
        /// Change the comment on the vertex type
        /// </summary>
        /// <param name="vertexType"></param>
        /// <param name="myNewComment"></param>
        /// <param name="myTransactionToken"></param>
        /// <param name="mySecurityToken"></param>
        private void ChangeCommentOnVertexType(IVertexType vertexType, string myNewComment, TransactionToken myTransactionToken, SecurityToken mySecurityToken)
        {
            if (!String.IsNullOrEmpty(myNewComment))
            {
                var update = new VertexUpdateDefinition(myNewComment);

                _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, vertexType.ID, (long)BaseTypes.VertexType, update);
            }
        }
示例#6
0
        /// <summary>
        /// Adds a mandatory constraint
        /// </summary>
        /// <param name="myToBeAddedMandatories"></param>
        /// <param name="vertexType"></param>
        /// <param name="myTransactionToken"></param>
        /// <param name="mySecurityToken"></param>
        private void AddMandatoryConstraint(IEnumerable<MandatoryPredefinition> myToBeAddedMandatories, IVertexType vertexType, TransactionToken myTransactionToken, SecurityToken mySecurityToken)
        {
            if (myToBeAddedMandatories.IsNotNullOrEmpty())
            {
                foreach (var aMandatory in myToBeAddedMandatories)
                {
                    var property = vertexType.GetPropertyDefinition(aMandatory.MandatoryAttribute);
                    var defaultValue = property.DefaultValue;

                    //get new mandatory value and set it
                    if (aMandatory.DefaultValue != null)
                    {
                        var defaultValueUpdate = new VertexUpdateDefinition(null, new StructuredPropertiesUpdate(new Dictionary<long, IComparable> { { (long)AttributeDefinitions.PropertyDotDefaultValue, aMandatory.DefaultValue.ToString() } }));
                        _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, property.ID, (long)BaseTypes.Property, defaultValueUpdate);

                        defaultValue = aMandatory.DefaultValue.ToString();
                    }

                    var vertexDefaultValueUpdate = new VertexUpdateDefinition(null, new StructuredPropertiesUpdate(new Dictionary<long, IComparable> { { property.ID, defaultValue } }));

                    foreach (var aVertexType in vertexType.GetDescendantVertexTypesAndSelf())
                    {
                        foreach (var aVertexWithoutPropery in _vertexManager.ExecuteManager.VertexStore.GetVerticesByTypeID(mySecurityToken, myTransactionToken, vertexType.ID).Where(_ => !_.HasProperty(property.ID)).ToList())
                        {
                            if (defaultValue != null)
                            {
                                //update
                                _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, aVertexWithoutPropery.VertexID, aVertexWithoutPropery.VertexTypeID, vertexDefaultValueUpdate);
                            }
                            else
                            {
                                throw new MandatoryConstraintViolationException(aMandatory.MandatoryAttribute);
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Renames a vertex type
        /// </summary>
        /// <param name="vertexType"></param>
        /// <param name="myNewVertexTypeName"></param>
        /// <param name="myTransactionToken"></param>
        /// <param name="mySecurityToken"></param>
        private void RenameVertexType(IVertexType vertexType, string myNewVertexTypeName, TransactionToken myTransactionToken, SecurityToken mySecurityToken)
        {
            if (myNewVertexTypeName != null)
            {
                var update = new VertexUpdateDefinition(null, new StructuredPropertiesUpdate(new Dictionary<long, IComparable> { { (long)AttributeDefinitions.BaseTypeDotName, myNewVertexTypeName } }));

                _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, vertexType.ID, (long)BaseTypes.VertexType, update);
            }
        }
示例#8
0
        /// <summary>
        /// Renames attributes
        /// </summary>
        /// <param name="myToBeRenamedAttributes"></param>
        /// <param name="vertexType"></param>
        /// <param name="myTransactionToken"></param>
        /// <param name="mySecurityToken"></param>
        private void RenameAttributes(Dictionary<string, string> myToBeRenamedAttributes, IVertexType vertexType, TransactionToken myTransactionToken, SecurityToken mySecurityToken)
        {
            if (!myToBeRenamedAttributes.IsNotNullOrEmpty())
                return;

            foreach (var aToBeRenamedAttribute in myToBeRenamedAttributes)
            {
                VertexUpdateDefinition update = new VertexUpdateDefinition(null, new StructuredPropertiesUpdate(new Dictionary<long, IComparable> { { (long)AttributeDefinitions.AttributeDotName, aToBeRenamedAttribute.Value } }));
                var attribute = vertexType.GetAttributeDefinition(aToBeRenamedAttribute.Key);

                switch (attribute.Kind)
                {
                    case AttributeType.Property:
                        _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, attribute.ID, (long)BaseTypes.Property, update);
                        break;

                    case AttributeType.IncomingEdge:
                        _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, attribute.ID, (long)BaseTypes.IncomingEdge, update);

                        break;
                    case AttributeType.OutgoingEdge:
                        _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, attribute.ID, (long)BaseTypes.OutgoingEdge, update);

                        break;
                    case AttributeType.BinaryProperty:
                        _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, attribute.ID, (long)BaseTypes.BinaryProperty, update);

                        break;
                    default:
                        break;
                }
            }
        }
示例#9
0
        /// <summary>
        /// Removes mandatory constraits
        /// </summary>
        /// <param name="myToBeRemovedMandatories"></param>
        /// <param name="myVertexType"></param>
        /// <param name="myTransactionToken"></param>
        /// <param name="mySecurityToken"></param>
        private void RemoveMandatoryConstraint(IEnumerable<string> myToBeRemovedMandatories, IVertexType myVertexType, TransactionToken myTransactionToken, SecurityToken mySecurityToken)
        {
            if (myToBeRemovedMandatories.IsNotNullOrEmpty())
            {
                var update = new VertexUpdateDefinition(null, new StructuredPropertiesUpdate(new Dictionary<long, IComparable> { { (long)AttributeDefinitions.PropertyDotIsMandatory, false } }));

                foreach (var aMandatory in myToBeRemovedMandatories)
                {
                    IPropertyDefinition property = myVertexType.GetPropertyDefinition(aMandatory);

                    _vertexManager.ExecuteManager.VertexStore.UpdateVertex(mySecurityToken, myTransactionToken, property.ID, (long)BaseTypes.Property, null);
                }
            }
        }