internal ServiceAlterVertexChangeset(RequestAlterVertexType myRequestAlterVertexType)
 {
     this.NewTypeName = myRequestAlterVertexType.AlteredTypeName;
     this.Comment = myRequestAlterVertexType.AlteredComment;
     this.ToBeAddedProperties = (myRequestAlterVertexType.ToBeAddedProperties == null)
         ? null : myRequestAlterVertexType.ToBeAddedProperties.Select(x => new ServicePropertyPredefinition(x)).ToArray();
     this.ToBeAddedIncomingEdges = (myRequestAlterVertexType.ToBeAddedIncomingEdges == null)
         ? null : myRequestAlterVertexType.ToBeAddedIncomingEdges.Select(x => new ServiceIncomingEdgePredefinition(x)).ToArray();
     this.ToBeAddedOutgoingEdges = (myRequestAlterVertexType.ToBeAddedOutgoingEdges == null)
         ? null : myRequestAlterVertexType.ToBeAddedOutgoingEdges.Select(x => new ServiceOutgoingEdgePredefinition(x)).ToArray();
     this.ToBeAddedIndices = (myRequestAlterVertexType.ToBeAddedIndices == null)
         ? null : myRequestAlterVertexType.ToBeAddedIndices.Select(x => new ServiceIndexPredefinition(x)).ToArray();
     this.ToBeAddedUniques = (myRequestAlterVertexType.ToBeAddedUniques == null)
         ? null : myRequestAlterVertexType.ToBeAddedUniques.Select(x => new ServiceUniquePredefinition(x)).ToArray();
     this.ToBeAddedMandatories = (myRequestAlterVertexType.ToBeAddedMandatories == null)
         ? null : myRequestAlterVertexType.ToBeAddedMandatories.Select(x => new ServiceMandatoryPredefinition(x)).ToArray();
     this.ToBeRemovedProperties = (myRequestAlterVertexType.ToBeRemovedProperties == null)
         ? null : myRequestAlterVertexType.ToBeRemovedProperties.ToArray();
     this.ToBeRemovedIncomingEdges = (myRequestAlterVertexType.ToBeRemovedIncomingEdges == null)
         ? null : myRequestAlterVertexType.ToBeRemovedIncomingEdges.ToArray();
     this.ToBeRemovedOutgoingEdges = (myRequestAlterVertexType.ToBeRemovedOutgoingEdges == null)
         ? null : myRequestAlterVertexType.ToBeRemovedOutgoingEdges.ToArray();
     this.ToBeRemovedIndices = myRequestAlterVertexType.ToBeRemovedIndices;
     this.ToBeRemovedUniques = (myRequestAlterVertexType.ToBeRemovedUniques == null)
         ? null : myRequestAlterVertexType.ToBeRemovedUniques.ToArray();
     this.ToBeRemovedMandatories = (myRequestAlterVertexType.ToBeRemovedMandatories == null)
         ? null : myRequestAlterVertexType.ToBeRemovedMandatories.ToArray();
     this.ToBeRenamedProperties = myRequestAlterVertexType.ToBeRenamedProperties;
     this.ToBeDefinedAttributes = (myRequestAlterVertexType.ToBeDefinedAttributes == null)
         ? null : myRequestAlterVertexType.ToBeDefinedAttributes.Select(x => new ServiceUnknownAttributePredefinition(x)).ToArray();
     this.ToBeUndefinedAttributes = (myRequestAlterVertexType.ToBeUndefinedAttributes == null)
         ? null : myRequestAlterVertexType.ToBeUndefinedAttributes.ToArray();
 }
Example #2
0
        private void ProcessUnique(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_SetUnique)myAlterCommand;

            foreach (var aUnique in command.UniqueAttributes)
            {
                result.AddUnique(new UniquePredefinition(aUnique));
            }

        }
Example #3
0
        private static void CheckToBeAddedMandatory(RequestAlterVertexType myAlterVertexTypeRequest, IVertexType vertexType)
        {
            var mandatories = myAlterVertexTypeRequest.ToBeAddedMandatories;
            var addProperties = myAlterVertexTypeRequest.ToBeAddedProperties;

            if (mandatories == null)
                return;

            var attributes = vertexType.GetAttributeDefinitions(false).ToList();

            foreach (var aMandatory in mandatories)
            {
                if (!attributes.Any(_ => _.Name == aMandatory.MandatoryAttribute) && !addProperties.Any(x => x.AttributeName == aMandatory.MandatoryAttribute))
                {
                    throw new AttributeDoesNotExistException(aMandatory.MandatoryAttribute, vertexType.Name);
                }
            }
        }
Example #4
0
        private void CheckRemoveOutgoingEdges(RequestAlterVertexType myAlterVertexTypeRequest, IVertexType myVertexType, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            if (myAlterVertexTypeRequest.ToBeRemovedOutgoingEdges == null)
                return;

            #region get the list of incoming edges that will be deleted too

            var toBeRemovedIncomingEdgeIDs = new List<long>();

            if (myAlterVertexTypeRequest.ToBeRemovedIncomingEdges != null)
                toBeRemovedIncomingEdgeIDs.AddRange(
                    myAlterVertexTypeRequest.ToBeRemovedIncomingEdges.Select(
                        _ => myVertexType.GetIncomingEdgeDefinition(_).ID));

            #endregion

            foreach (var aOutgoingEdge in myAlterVertexTypeRequest.ToBeRemovedOutgoingEdges)
            {
                var attrDef = myVertexType.GetOutgoingEdgeDefinition(aOutgoingEdge);

                var vertex = _vertexManager.ExecuteManager.GetVertex((long) BaseTypes.OutgoingEdge, attrDef.ID, null,
                                                                     null, myTransactionToken, mySecurityToken);

                var incomingEdges = vertex.GetIncomingVertices((long) BaseTypes.IncomingEdge,
                                                               (long)
                                                               AttributeDefinitions.IncomingEdgeDotRelatedEgde);

                foreach (var incomingEdge in incomingEdges)
                {
                    if (!toBeRemovedIncomingEdgeIDs.Contains(incomingEdge.VertexID))
                    {
                        //TODO a better exception here
                        throw new Exception(
                            "The outgoing edge can not be removed, because there are related incoming edges.");
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Adds a unique constraint
        /// </summary>
        /// <param name="myToBeAddedUniques"></param>
        /// <param name="myTransactionToken"></param>
        /// <param name="mySecurityToken"></param>
        private IEnumerable<IIndexDefinition> AddUniqueConstraint(RequestAlterVertexType myAlterVertexTypeRequest, TransactionToken myTransactionToken, SecurityToken mySecurityToken)
        {
            var indexDefs = new List<IIndexDefinition>();
            var uniques = myAlterVertexTypeRequest.ToBeAddedUniques;

            if (!uniques.IsNotNullOrEmpty())
                return indexDefs;

            foreach (var aUniqueConstraint in uniques)
            {
                var predef = new IndexPredefinition();
                predef.AddProperty(aUniqueConstraint.Properties);
                predef.SetVertexType(myAlterVertexTypeRequest.VertexTypeName);

                indexDefs.Add(_indexManager.CreateIndex(predef, mySecurityToken, myTransactionToken));
            }

            return indexDefs;
        }
Example #6
0
        public TResult AlterVertexType <TResult>(sones.Library.Commons.Security.SecurityToken mySecurityToken, long myTransactionID, sones.GraphDB.Request.RequestAlterVertexType myRequestAlterVertexType, sones.GraphDB.Request.Converter.AlterVertexTypeResultConverter <TResult> myOutputconverter)
        {
            Stopwatch RunningTime   = Stopwatch.StartNew();
            var       svcVertexType = _GraphDSService.AlterVertexType(mySecurityToken, myTransactionID,
                                                                      new ServiceVertexType(myRequestAlterVertexType.TypeName),
                                                                      new ServiceAlterVertexChangeset(myRequestAlterVertexType));
            var vertexType = new RemoteVertexType(svcVertexType, this);

            RunningTime.Stop();
            return(myOutputconverter(new RequestStatistics(new TimeSpan(RunningTime.ElapsedTicks)), vertexType));
        }
Example #7
0
        /// <summary>
        /// Reads an attribute definition from the GraphML File and stores
        /// it internal for later usage on vertex / edge reading.
        /// </summary>
        /// <param name='myReader'>
        /// XmlReader
        /// </param>
        private void ReadAttributeDefinition(XmlReader myReader)
        {
            #region data

            var attrId 		= myReader.GetAttribute(GraphMLTokens.ID);
            var attrFor 	= myReader.GetAttribute(GraphMLTokens.FOR);
            var attrName 	= myReader.GetAttribute(GraphMLTokens.ATTRIBUTE_NAME);
            var attrType 	= myReader.GetAttribute(GraphMLTokens.ATTRIBUTE_TYPE).ToLower();

            string attrDefault = null;

            using (var readerAttribute = myReader.ReadSubtree())
            {
                while (readerAttribute.Read())
                {
                    if (readerAttribute.Name == GraphMLTokens.DEFAULT)
                    {
                        attrDefault = readerAttribute.ReadElementContentAsString();
                    }
                }
            }

            // make attribute type DB conform (capitalize first letter)
            attrType = char.ToUpper(attrType[0]) + attrType.Substring(1).ToLower();
            // and store the whole definition
            _AttributeDefinitions.Add(attrId, new Tuple<string, string, string, string>(attrFor, attrName, attrType, attrDefault));
            // get GraphDB internal type
            attrType = GetInternalTypeName(attrType);

            #endregion

            #region alter vertex type with new attribute

            if(attrFor.Equals(GraphMLTokens.VERTEX))
            {
                var requestAlterVertexType = new RequestAlterVertexType(_VertexTypeName);

                var propertyPreDefinition = new PropertyPredefinition(attrName, attrType);

                propertyPreDefinition.SetDefaultValue(attrDefault);

                requestAlterVertexType.AddProperty(propertyPreDefinition);

                _GraphDB.AlterVertexType(_SecurityToken,
                    _TransactionToken,
                    requestAlterVertexType,
                    (stats, vType) => vType);
            }

            #endregion
        }
Example #8
0
        private void ProcessAddAttribute(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterVertexType_AddAttributes)myAlterCommand;

            if (command.ListOfAttributes != null && command.ListOfAttributes.Count > 0)
            {
                foreach (var aAttribute in command.ListOfAttributes)
                {
                    result.AddUnknownAttribute(GenerateUnknownAttribute(aAttribute));
                }
            }
            else
            {
                if (command.BackwardEdgeInformation != null && command.BackwardEdgeInformation.Count > 0)
                {
                    foreach (var aIncomingEdge in command.BackwardEdgeInformation)
                    {
                        result.AddIncomingEdge(GenerateAIncomingEdge(aIncomingEdge));
                    }
                }
            }
            
        }
Example #9
0
        private void ProcessAlterCommand(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            switch (myAlterCommand.AlterType)
            {
                case TypesOfAlterCmd.DropIndex:

                    ProcessDropIndex(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.AddIndex:

                    ProcessAddIndex(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.AddAttribute:

                    ProcessAddAttribute(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.DropAttribute:

                    ProcessDropAttribute(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.RenameAttribute:

                    ProcessRenameAttribute(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.RenameType:

                    ProcessRenameVertexType(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.RenameIncomingEdge:

                    ProcessRenameIncomingEdge(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.Unqiue:

                    ProcessUnique(myAlterCommand, ref result);

                    break;
                case TypesOfAlterCmd.DropUnqiue:

                    ProcessDropUnique(myAlterCommand, ref result);                    

                    break;
                case TypesOfAlterCmd.Mandatory:

                    ProcessMandatory(myAlterCommand, ref result);                    

                    break;
                case TypesOfAlterCmd.DropMandatory:

                    ProcessDropMandatory(myAlterCommand, ref result);                    

                    break;
                case TypesOfAlterCmd.ChangeComment:

                    ProcessChangeComment(myAlterCommand, ref result);                    

                    break;
                case TypesOfAlterCmd.DefineAttribute:

                    ProcessDefineAttribute(myAlterCommand, ref result);                    

                    break;
                case TypesOfAlterCmd.UndefineAttribute:

                    ProcessUndefineAttribute(myAlterCommand, ref result);                    

                    break;
                default:
                    break;
            }
        }
Example #10
0
        private RequestAlterVertexType CreateNewRequest(IGraphDB myGraphDB, GQLPluginManager myPluginManager, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            RequestAlterVertexType result = new RequestAlterVertexType(_TypeName);

            foreach (var aAlterCommand in _AlterTypeCommand)
            {
                ProcessAlterCommand(aAlterCommand, ref result);
            }

            return result;
        }
Example #11
0
        /// <summary>
        /// Checks the to be renamed attributes
        /// </summary>
        /// <param name="myAlterVertexTypeRequest"></param>
        /// <param name="vertexType"></param>
        private static void CheckToBeRenamedAttributes(RequestAlterVertexType myAlterVertexTypeRequest, IVertexType vertexType)
        {
            if (myAlterVertexTypeRequest.ToBeRenamedProperties == null)
                return;

            foreach (var aToBeRenamedAttributes in myAlterVertexTypeRequest.ToBeRenamedProperties)
            {
                if (!CheckOldName(aToBeRenamedAttributes.Key, vertexType))
                {
                    throw new InvalidAlterVertexTypeException(
                        String.Format(
                            "It is not possible to rename {0} into {1}. The to be renamed attribute does not exist.", aToBeRenamedAttributes.Key, aToBeRenamedAttributes.Value));
                }

                if (!CheckNewName(aToBeRenamedAttributes.Value, vertexType))
                {
                    throw new InvalidAlterVertexTypeException(
                        String.Format(
                            "It is not possible to rename {0} into {1}. The new attribute name already exists.", aToBeRenamedAttributes.Key, aToBeRenamedAttributes.Value));
                }
            }
        }
Example #12
0
        /// <summary>
        /// Checks if the to be removed attributes exists on this type
        /// </summary>
        /// <param name="myAlterVertexTypeRequest"></param>
        /// <param name="vertexType"></param>
        private static void CheckToBeRemovedAttributes(RequestAlterVertexType myAlterVertexTypeRequest, IVertexType vertexType)
        {
            #region properties

            var attributesOfCurrentVertexType = vertexType.GetAttributeDefinitions(false).ToList();

            if (myAlterVertexTypeRequest.ToBeRemovedProperties != null)
            {
                foreach (var aToBeDeletedAttribute in myAlterVertexTypeRequest.ToBeRemovedProperties)
                {
                    if (!attributesOfCurrentVertexType.Any(_ => _.Name == aToBeDeletedAttribute))
                    {
                        throw new VertexAttributeIsNotDefinedException(aToBeDeletedAttribute);
                    }
                }
            }

            #endregion

            #region outgoing Edges

            if (myAlterVertexTypeRequest.ToBeRemovedOutgoingEdges != null)
            {
                foreach (var aToBeDeletedAttribute in myAlterVertexTypeRequest.ToBeRemovedOutgoingEdges)
                {
                    if (!attributesOfCurrentVertexType.Any(_ => _.Name == aToBeDeletedAttribute))
                    {
                        throw new VertexAttributeIsNotDefinedException(aToBeDeletedAttribute);
                    }
                }
            }

            #endregion

            #region incoming edges

            if (myAlterVertexTypeRequest.ToBeRemovedIncomingEdges != null)
            {
                foreach (var aToBeDeletedAttribute in myAlterVertexTypeRequest.ToBeRemovedIncomingEdges)
                {
                    if (!attributesOfCurrentVertexType.Any(_ => _.Name == aToBeDeletedAttribute))
                    {
                        throw new VertexAttributeIsNotDefinedException(aToBeDeletedAttribute);
                    }
                }
            }

            #endregion
        }
Example #13
0
        public override IVertexType AlterVertexType(RequestAlterVertexType myAlterVertexTypeRequest, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            var vertexType =  _vertexTypeManager.GetVertexType(myAlterVertexTypeRequest.VertexTypeName, myTransactionToken, mySecurityToken);

            if (myAlterVertexTypeRequest.ToBeAddedUnknownAttributes != null)
            {
                var toBeConverted = myAlterVertexTypeRequest.ToBeAddedUnknownAttributes.ToArray();
                foreach (var unknown in toBeConverted)
                {
                    if (BinaryPropertyPredefinition.TypeName.Equals(unknown.AttributeType))
                    {
                        var prop = ConvertUnknownToBinaryProperty(unknown);

                        myAlterVertexTypeRequest.AddBinaryProperty(prop);
                    }
                    else if (IsBaseType(unknown.AttributeType))
                    {
                        var prop = ConvertUnknownToProperty(unknown);

                        myAlterVertexTypeRequest.AddProperty(prop);
                    }
                    else if (unknown.AttributeType.Contains(IncomingEdgePredefinition.TypeSeparator))
                    {
                        var prop = ConvertUnknownToIncomingEdge(unknown);
                        myAlterVertexTypeRequest.AddIncomingEdge(prop);
                    }
                    else
                    {
                        var prop = ConvertUnknownToOutgoingEdge(unknown);
                        myAlterVertexTypeRequest.AddOutgoingEdge(prop);
                    }
                }
                myAlterVertexTypeRequest.ResetUnknown();
            }

            if (myAlterVertexTypeRequest.ToBeRemovedUnknownAttributes != null)
            {
                foreach (var unknownProp in myAlterVertexTypeRequest.ToBeRemovedUnknownAttributes)
                {
                    var attrDef = vertexType.GetAttributeDefinition(unknownProp);
                    if (attrDef == null)
                        throw new VertexAttributeIsNotDefinedException(unknownProp);

                    switch (attrDef.Kind)
                    {
                        case AttributeType.Property:
                            myAlterVertexTypeRequest.RemoveProperty(unknownProp);
                            break;
                        case AttributeType.OutgoingEdge:
                            myAlterVertexTypeRequest.RemoveOutgoingEdge(unknownProp);
                            break;
                        case AttributeType.IncomingEdge:
                            myAlterVertexTypeRequest.RemoveIncomingEdge(unknownProp);
                            break;
                        case AttributeType.BinaryProperty:
                            myAlterVertexTypeRequest.RemoveBinaryProperty(unknownProp);
                            break;
                        default:
                            throw new Exception("The enumeration AttributeType was changed, but not this switch statement.");
                    }
                }
                myAlterVertexTypeRequest.ClearToBeRemovedUnknownAttributes();
            }

            #region checks

            CheckToBeAddedAttributes(myAlterVertexTypeRequest, vertexType);
            CheckToBeRemovedAttributes(myAlterVertexTypeRequest, vertexType);
            CheckToBeRenamedAttributes(myAlterVertexTypeRequest, vertexType);
            CheckNewVertexTypeName(myAlterVertexTypeRequest.AlteredVertexTypeName, mySecurityToken, myTransactionToken);
            CheckToBeAddedMandatory(myAlterVertexTypeRequest, vertexType);
            CheckToBeAddedUniques(myAlterVertexTypeRequest, vertexType);
            CheckToBeRemovedMandatoryAndUnique(myAlterVertexTypeRequest.ToBeRemovedMandatories, myAlterVertexTypeRequest.ToBeRemovedUniques, vertexType);
            CheckToBeAddedIndices(myAlterVertexTypeRequest.ToBeAddedIndices, vertexType);
            CheckToBeRemovedIndices(myAlterVertexTypeRequest.ToBeRemovedIndices, vertexType);

            #endregion

            return null;
        }
Example #14
0
        private static void CheckToBeAddedUniques(RequestAlterVertexType myAlterVertexTypeRequest, IVertexType vertexType)
        {
            var uniques = myAlterVertexTypeRequest.ToBeAddedUniques;
            var addProperties = myAlterVertexTypeRequest.ToBeAddedProperties;

            if (uniques == null)
                return;

            var attributes = vertexType.GetAttributeDefinitions(false).ToList();

            foreach (var aUnique in uniques)
            {
                foreach (var aAttribute in aUnique.Properties)
                {
                    if (!attributes.Any(_ => _.Name == aAttribute) && !addProperties.Any(x => x.AttributeName == aAttribute))
                    {
                        throw new AttributeDoesNotExistException(aAttribute, vertexType.Name);
                    }
                }
            }
        }
Example #15
0
        private void ProcessRenameAttribute(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_RenameAttribute)myAlterCommand;

            result.RenameAttribute(command.OldName, command.NewName);
        }
Example #16
0
        private void ProcessDropAttribute(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_DropAttributes)myAlterCommand;

            foreach (var aAttribute in command.ListOfAttributes)
            {
                result.RemoveUnknownAttribute(aAttribute);
            }
        }
Example #17
0
        private void ProcessDropIndex(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_DropIndices)myAlterCommand;

            foreach (var aIndex in command.IdxDropList)
            {
                result.RemoveIndex(aIndex.Key, aIndex.Value);
            }
        }
Example #18
0
        private void ProcessUndefineAttribute(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_UndefineAttributes)myAlterCommand;

            if (command.ListOfAttributes != null && command.ListOfAttributes.Count > 0)
            {
                foreach (var aAttribute in command.ListOfAttributes)
                {
                    result.UndefineAttribute(aAttribute);
                }
            }
        }
Example #19
0
        private void ProcessAddIndex(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_AddIndices)myAlterCommand;

            foreach (var aIndexDefinition in command.IdxDefinitionList)
            {
                result.AddIndex(GenerateIndex(aIndexDefinition));
            }
        }
Example #20
0
 public abstract IVertexType AlterVertexType(RequestAlterVertexType myAlterVertexTypeRequest, SecurityToken mySecurityToken, TransactionToken myTransactionToken);
Example #21
0
        private void ProcessChangeComment(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_ChangeComment)myAlterCommand;

            result.SetComment(command.NewComment);
        }
Example #22
0
        public static RequestAlterVertexType MakeRequestAlterVertexType(ServiceVertexType myVertexType, ServiceAlterVertexChangeset myChangeset)
        {
            var Request = new RequestAlterVertexType(myVertexType.Name);

            #region Add Attributes

            if (myChangeset.ToBeAddedProperties != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedProperties)
                {
                    Request.AddProperty(toAdd.ToPropertyPredefinition());
                }
            }

            if (myChangeset.ToBeAddedIncomingEdges != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedIncomingEdges)
                {
                    Request.AddIncomingEdge(toAdd.ToIncomingEdgePredefinition());
                }
            }

            if (myChangeset.ToBeAddedOutgoingEdges != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedOutgoingEdges)
                {
                    Request.AddOutgoingEdge(toAdd.ToOutgoingEdgePredefinition());
                }
            }

            if (myChangeset.ToBeAddedUniques != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedUniques)
                {
                    Request.AddUnique(toAdd.ToUniquePredefinition());
                }
            }

            if (myChangeset.ToBeAddedMandatories != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedMandatories)
                {
                    Request.AddMandatory(toAdd.ToMandatoryPredefinition());
                }
            }

            if (myChangeset.ToBeAddedIndices != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedIndices)
                {
                    Request.AddIndex(toAdd.ToIndexPredefinition());
                }
            }

            #endregion

            #region Remove Attributes

            if (myChangeset.ToBeRemovedProperties != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedProperties)
                {
                    Request.RemoveProperty(toDel);
                }
            }

            if (myChangeset.ToBeRemovedIncomingEdges != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedIncomingEdges)
                {
                    Request.RemoveIncomingEdge(toDel);
                }
            }

            if (myChangeset.ToBeRemovedOutgoingEdges != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedOutgoingEdges)
                {
                    Request.RemoveOutgoingEdge(toDel);
                }
            }

            if (myChangeset.ToBeRemovedUniques != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedUniques)
                {
                    Request.RemoveUnique(toDel);
                }
            }

            if (myChangeset.ToBeRemovedMandatories != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedMandatories)
                {
                    Request.RemoveMandatory(toDel);
                }
            }

            if (myChangeset.ToBeRemovedIndices != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedIndices)
                {
                    Request.RemoveIndex(toDel.Key, toDel.Value);
                }
            }

            #endregion

            #region define / undefine

            if (myChangeset.ToBeDefinedAttributes != null)
            {
                foreach (var toDefine in myChangeset.ToBeDefinedAttributes)
                {
                    Request.DefineAttribute(toDefine.ToUnknownAttributePredefinition());
                }
            }

            if (myChangeset.ToBeUndefinedAttributes != null)
            {
                foreach (var toUndefine in myChangeset.ToBeUndefinedAttributes)
                {
                    Request.UndefineAttribute(toUndefine);
                }
            }

            #endregion

            #region Rename Task

            if (myChangeset.ToBeRenamedProperties != null)
            {
                foreach (var toRename in myChangeset.ToBeRenamedProperties)
                {
                    Request.RenameAttribute(toRename.Key, toRename.Value);
                }
            }

            #endregion

            if (myChangeset.Comment != null)
                Request.SetComment(myChangeset.Comment);

            if (myChangeset.NewTypeName != null)
                Request.RenameType(myChangeset.NewTypeName);

            //todo add unknown attribute

            return Request;
        }
Example #23
0
        private void ProcessDropMandatory(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_DropMandatory)myAlterCommand;

            result.RemoveMandatory(command.DroppedMandatory);
        }
Example #24
0
        public override IVertexType AlterVertexType(RequestAlterVertexType myAlterVertexTypeRequest, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            var vertexType = GetVertexType(myAlterVertexTypeRequest.VertexTypeName, myTransactionToken, mySecurityToken);

            #region remove stuff

            CheckRemoveOutgoingEdges(myAlterVertexTypeRequest, vertexType, mySecurityToken, myTransactionToken);

            //done
            RemoveMandatoryConstraint(myAlterVertexTypeRequest.ToBeRemovedMandatories, vertexType, myTransactionToken,
                                      mySecurityToken);
            //done
            RemoveUniqueConstraint(myAlterVertexTypeRequest.ToBeRemovedUniques, vertexType, myTransactionToken,
                                      mySecurityToken);

            //done
            RemoveIndices(myAlterVertexTypeRequest.ToBeRemovedIndices, vertexType, myTransactionToken, mySecurityToken);

            //done
            RemoveAttributes(myAlterVertexTypeRequest.ToBeRemovedIncomingEdges,
                             myAlterVertexTypeRequest.ToBeRemovedOutgoingEdges,
                             myAlterVertexTypeRequest.ToBeRemovedProperties, vertexType, myTransactionToken,
                             mySecurityToken);

            #endregion

            #region add stuff

            //done
            AddAttributes(myAlterVertexTypeRequest.ToBeAddedBinaryProperties,
                          myAlterVertexTypeRequest.ToBeAddedIncomingEdges,
                          myAlterVertexTypeRequest.ToBeAddedOutgoingEdges,
                          myAlterVertexTypeRequest.ToBeAddedProperties,
                          vertexType, myTransactionToken, mySecurityToken);

            //get altered type
            vertexType = GetVertexType(myAlterVertexTypeRequest.VertexTypeName, myTransactionToken, mySecurityToken);

            //done
            AddMandatoryConstraint(myAlterVertexTypeRequest.ToBeAddedMandatories, vertexType, myTransactionToken,
                                   mySecurityToken);

            //done
            var indexDefinitions = AddUniqueConstraint(myAlterVertexTypeRequest, myTransactionToken, mySecurityToken);

            //done
            AddIndices(myAlterVertexTypeRequest.ToBeAddedIndices, vertexType, myTransactionToken, mySecurityToken);

            //done
            RenameAttributes(myAlterVertexTypeRequest.ToBeRenamedProperties, vertexType, myTransactionToken, mySecurityToken);

            #endregion

            var info = new TypeInfo();
            info.VertexInfo = new VertexInformation((long)BaseTypes.VertexType, vertexType.ID);
            ConnectVertexToUniqueIndex(info, indexDefinitions, mySecurityToken, myTransactionToken);

            #region misc

            //done
            ChangeCommentOnVertexType(vertexType, myAlterVertexTypeRequest.AlteredComment, myTransactionToken,mySecurityToken);

            //done
            RenameVertexType(vertexType, myAlterVertexTypeRequest.AlteredVertexTypeName, myTransactionToken, mySecurityToken);

            #endregion

            CleanUpTypes();

            _indexManager.RebuildIndices((long)BaseTypes.VertexType, myTransactionToken, mySecurityToken);

            return GetVertexType(vertexType.ID, myTransactionToken, mySecurityToken);
        }
Example #25
0
        private void ProcessMandatory(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_SetMandatory)myAlterCommand;

            foreach (var aMandatory in command.MandatoryAttributes)
            {
                result.AddMandatory(new MandatoryPredefinition(aMandatory));
            }
        }
Example #26
0
        private void ProcessDropUnique(AAlterTypeCommand myAlterCommand, ref RequestAlterVertexType result)
        {
            var command = (AlterType_DropUnique)myAlterCommand;

            result.RemoveUnique(command.DroppedUnique);
        }
Example #27
0
        /// <summary>
        /// Checks if the to be added attributes exist in the given vertex type or derived oness
        /// </summary>
        /// <param name="myAlterVertexTypeRequest"></param>
        /// <param name="vertexType"></param>
        private static void CheckToBeAddedAttributes(RequestAlterVertexType myAlterVertexTypeRequest, IVertexType vertexType)
        {
            foreach (var aVertexType in vertexType.GetDescendantVertexTypesAndSelf())
            {
                var attributesOfCurrentVertexType = aVertexType.GetAttributeDefinitions(false).ToList();

                #region binary properties
                if (myAlterVertexTypeRequest.ToBeAddedBinaryProperties != null)
                {
                    foreach (var aToBeAddedAttribute in myAlterVertexTypeRequest.ToBeAddedBinaryProperties)
                    {
                        if (attributesOfCurrentVertexType.Any(_ => _.Name == aToBeAddedAttribute.AttributeName))
                        {
                            throw new VertexAttributeAlreadyExistsException(aToBeAddedAttribute.AttributeName);
                        }
                    }
                }

                #endregion

                #region outgoing edges

                if (myAlterVertexTypeRequest.ToBeAddedOutgoingEdges != null)
                {
                    foreach (var aToBeAddedAttribute in myAlterVertexTypeRequest.ToBeAddedOutgoingEdges)
                    {
                        if (attributesOfCurrentVertexType.Any(_ => _.Name == aToBeAddedAttribute.AttributeName))
                        {
                            throw new VertexAttributeAlreadyExistsException(aToBeAddedAttribute.AttributeName);
                        }
                    }
                }

                #endregion

                #region Incoming edges
                if (myAlterVertexTypeRequest.ToBeAddedIncomingEdges != null)
                {
                    foreach (var aToBeAddedAttribute in myAlterVertexTypeRequest.ToBeAddedIncomingEdges)
                    {
                        if (attributesOfCurrentVertexType.Any(_ => _.Name == aToBeAddedAttribute.AttributeName))
                        {
                            throw new VertexAttributeAlreadyExistsException(aToBeAddedAttribute.AttributeName);
                        }
                    }
                }

                #endregion

                #region property

                if (myAlterVertexTypeRequest.ToBeAddedProperties != null)
                {
                    foreach (var aToBeAddedAttribute in myAlterVertexTypeRequest.ToBeAddedProperties)
                    {
                        if (attributesOfCurrentVertexType.Any(_ => _.Name == aToBeAddedAttribute.AttributeName))
                        {
                            throw new VertexAttributeAlreadyExistsException(aToBeAddedAttribute.AttributeName);
                        }
                    }
                }

                #endregion

                #region unknown attributes

                if (myAlterVertexTypeRequest.ToBeAddedUnknownAttributes != null)
                {
                    foreach (var aToBeAddedAttribute in myAlterVertexTypeRequest.ToBeAddedUnknownAttributes)
                    {
                        if (attributesOfCurrentVertexType.Any(_ => _.Name == aToBeAddedAttribute.AttributeName))
                        {
                            throw new VertexAttributeAlreadyExistsException(aToBeAddedAttribute.AttributeName);
                        }
                    }
                }

                #endregion
            }
        }