コード例 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_graphDBType"></param>
        /// <param name="myAttributes">Pass null if you want to delete the whole object with all attributes</param>
        /// <param name="myListOfAffectedDBObjectUUIDs"></param>
        /// <param name="_dbContext"></param>
        /// <param name="myToken"></param>
        /// <param name="myDBObjectCache"></param>
        /// <returns></returns>
        public Exceptional<IEnumerable<Vertex>> DeleteDBObjects(GraphDBType myGraphDBType, List<TypeAttribute> myAttributes, IEnumerable<Exceptional<DBObjectStream>> myListOfAffectedDBObjects)
        {
            //some stuff for queryResult
            UInt64 deletionCounter = 0;

            foreach (var aDBO in myListOfAffectedDBObjects)
            {
                if (aDBO.Failed())
                {
                    return new Exceptional<IEnumerable<Vertex>>(new Error_LoadObject(aDBO.Value.ObjectLocation));
                }

                deletionCounter++;

                if (!myAttributes.IsNullOrEmpty())
                {

                    #region Delete some defined attributes

                    foreach (var Attr in myAttributes)
                    {
                        if (Attr.GetRelatedType(_dbContext.DBTypeManager).GetMandatoryAttributesUUIDs(_dbContext.DBTypeManager).Contains(Attr.UUID))
                        {

                            #region Attribute is mandatory - set default value

                            if ((Boolean)_dbContext.DBSettingsManager.GetSetting(SettingDefaultsOnMandatory.UUID, _dbContext, TypesSettingScope.TYPE, Attr.GetRelatedType(_dbContext.DBTypeManager)).Value.Value.Value)
                            {
                                //the attribute will be removed from the dbobject --> update index
                                var removeAttributefromIdxResult = RemoveDBObjectFromIndex(aDBO.Value, Attr.UUID);

                                if (removeAttributefromIdxResult.Failed())
                                {
                                    return new Exceptional<IEnumerable<Vertex>>(removeAttributefromIdxResult);
                                }

                                var defaultExcept = SetDefaultValue(Attr, aDBO);

                                if (defaultExcept.Failed())
                                    return new Exceptional<IEnumerable<Vertex>>(defaultExcept);

                                if (!defaultExcept.Value)
                                    return new Exceptional<IEnumerable<Vertex>>(new Error_UpdateAttributeValue(Attr));

                                #region update idx

                                //--> update index
                                var updateAttributefromIdxResult = InsertDBObjectIntoIndex(aDBO.Value, Attr.UUID);

                                if (updateAttributefromIdxResult.Failed())
                                {
                                    return new Exceptional<IEnumerable<Vertex>>(updateAttributefromIdxResult);
                                }

                                #endregion
                            }
                            else
                                return new Exceptional<IEnumerable<Vertex>>(new Error_MandatoryConstraintViolation(Attr.Name));

                            #endregion

                        }
                        else
                        {
                            //the attribute will be removed from the dbobject --> update index
                            var removeAttributefromIdxResult = RemoveDBObjectFromIndex(aDBO.Value, Attr.UUID);

                            if (removeAttributefromIdxResult.Failed())
                            {
                                return new Exceptional<IEnumerable<Vertex>>(removeAttributefromIdxResult);
                            }

                            if (!aDBO.Value.RemoveAttribute(Attr.UUID))
                            {
                                return new Exceptional<IEnumerable<Vertex>>(new Error_RemoveTypeAttribute(myGraphDBType, Attr));
                            }

                        }
                    }

                    var saveResult = aDBO.Value.Save();

                    if (!saveResult.Success())
                    {
                        return new Exceptional<IEnumerable<Vertex>>(saveResult);
                    }

                    #endregion

                }
                else
                {

                    #region Remove complete DBO

                    var objID = aDBO.Value.ObjectUUID;

                    var backwardEdgeLoadExcept = _dbContext.DBObjectManager.LoadBackwardEdge(aDBO.Value.ObjectLocation);

                    if (!backwardEdgeLoadExcept.Success())
                        return new Exceptional<IEnumerable<Vertex>>(backwardEdgeLoadExcept.IErrors.First());

                    var backwarEdges = backwardEdgeLoadExcept.Value;

                    var removeResult = _dbContext.DBObjectManager.RemoveDBObject(myGraphDBType, aDBO.Value, _dbContext.DBObjectCache, _dbContext.SessionSettings);

                    if (!removeResult.Success())
                    {
                        return new Exceptional<IEnumerable<Vertex>>(removeResult);
                    }

                    if (backwarEdges != null)
                    {
                        var delEdgeRefs = DeleteObjectReferences(objID, backwarEdges);

                        if (!delEdgeRefs.Success())
                            return new Exceptional<IEnumerable<Vertex>>(delEdgeRefs.IErrors.First());
                    }

                    #endregion

                }
            }

            if (deletionCounter == 0)
            {
                var result = new Exceptional<IEnumerable<Vertex>>(new List<Vertex>());
                return result.PushIWarningT(new Warning_NoObjectsToDelete());
            }

            return new Exceptional<IEnumerable<Vertex>>(new List<Vertex>());
        }