/// <summary> /// Execute the renaming of the backwardedge of a given type. /// </summary> /// <param name="myDBContext"></param> /// <param name="myGraphDBType"></param> /// <returns></returns> public override Exceptional Execute(DBContext myDBContext, GraphDBType myGraphDBType) { TypeAttribute Attribute = myGraphDBType.GetTypeAttributeByName(OldName); if (Attribute == null) { return new Exceptional(new Error_AttributeIsNotDefined(OldName)); } return myGraphDBType.RenameBackwardedge(Attribute, NewName, myDBContext.DBTypeManager); }
/// <summary> /// Executes the removal of certain myAttributes. /// <seealso cref=" AAlterTypeCommand"/> /// </summary> public override Exceptional Execute(DBContext myDBContext, GraphDBType myGraphDBType) { Exceptional result = new Exceptional(); foreach (String aAttributeName in _ListOfAttributes) { var attr = myGraphDBType.GetTypeAttributeByName(aAttributeName); if (attr != null) { var idxs = new List<Indices.AAttributeIndex>(myGraphDBType.GetAttributeIndices(myDBContext, attr.UUID)); foreach (var item in idxs) { var remIdxResult = myGraphDBType.RemoveIndex(item.IndexName, item.IndexEdition, myDBContext); if (remIdxResult.Failed()) { result.PushIExceptional(remIdxResult); } } } else { result.PushIError(new Error_AttributeIsNotDefined(aAttributeName)); return result; } //Hack: remove myAttributes in DBObjects var aTempResult = myDBContext.DBTypeManager.RemoveAttributeFromType(myGraphDBType.Name, aAttributeName, myDBContext.DBTypeManager); if (aTempResult.Failed()) { result.PushIExceptional(aTempResult); return result; } } return result; }
/// <summary> /// Creates a new DBObject of a given GraphType inserts its UUID into all indices of the given GraphType. /// </summary> /// <param name="myGraphDBType">The GraphType of the DBObject to create</param> /// <param name="myDBObjectAttributes">A dictionary of attributes for the new DBObject</param> /// <param name="myExtractSettings">Special values which should be set to a object</param> /// <returns>The UUID of the new DBObject</returns> public Exceptional<DBObjectStream> CreateNewDBObject(GraphDBType myGraphDBType, Dictionary<String, IObject> myDBObjectAttributes, Dictionary<String, IObject> myUndefAttributes, Dictionary<ASpecialTypeAttribute, Object> mySpecialTypeAttributes, SessionSettings mySessionSettings, Boolean myCheckUniqueness) { Dictionary<AttributeUUID, IObject> _attrs = myDBObjectAttributes.ToDictionary(key => myGraphDBType.GetTypeAttributeByName(key.Key).UUID, value => value.Value); return CreateNewDBObjectStream(myGraphDBType, _attrs, myUndefAttributes, mySpecialTypeAttributes, mySessionSettings, myCheckUniqueness); }
public Exceptional<Boolean> RenameAttributeOfType(GraphDBType myType, String oldName, String newName) { #region INPUT EXCEPTIONS if (myType == null) { return new Exceptional<Boolean>(new Error_ArgumentNullOrEmpty("myType")); } if (String.IsNullOrEmpty(oldName)) { return new Exceptional<Boolean>(new Error_ArgumentNullOrEmpty("oldName)")); } if (String.IsNullOrEmpty(newName)) { return new Exceptional<Boolean>(new Error_ArgumentNullOrEmpty("newName")); } #endregion #region Data TypeAttribute typeAttribute = null; #endregion #region rename attribute of type typeAttribute = myType.GetTypeAttributeByName(oldName); if (typeAttribute != null) { Exceptional<Boolean> Result = myType.RenameAttribute(typeAttribute.UUID, newName); if (Result.Failed()) return new Exceptional<Boolean>(Result); var FlushExcept = FlushType(myType); if (FlushExcept.Failed()) { Result = myType.RenameAttribute(typeAttribute.UUID, oldName); if (Result.Failed()) return new Exceptional<Boolean>(Result); return new Exceptional<Boolean>(FlushExcept); } } else { return new Exceptional<Boolean>(new Error_AttributeIsNotDefined(myType.Name, oldName)); } #endregion return new Exceptional<Boolean>(true); }
/// <summary> /// Adds myAttributes to a certain graphDBType. /// </summary> /// <param name="myGraphDBType">The type that should be added some myAttributes.</param> /// <param name="myDBContext">The DBContext.</param> /// <returns>A Exceptional.</returns> public override Exceptional Execute(DBContext myDBContext, GraphDBType myGraphDBType) { #region check type for myAttributes foreach (var aAttributeDefinition in _ListOfAttributes) { if (myGraphDBType.GetTypeAttributeByName(aAttributeDefinition.AttributeName) != null) { var aError = new Error_AttributeAlreadyExists(aAttributeDefinition.AttributeName); return new Exceptional(aError); } } #endregion #region add myAttributes foreach (var aAttributeDefinition in _ListOfAttributes) { var typeAttributeExceptional = aAttributeDefinition.CreateTypeAttribute(myDBContext); if (typeAttributeExceptional.Failed()) { return typeAttributeExceptional; } var typeAttribute = typeAttributeExceptional.Value; try { var theType = myDBContext.DBTypeManager.GetTypeByName(aAttributeDefinition.AttributeType.Name); typeAttribute.DBTypeUUID = theType.UUID; typeAttribute.RelatedGraphDBTypeUUID = myGraphDBType.UUID; #region EdgeType if (typeAttribute.EdgeType == null) // should never happen - delete me! { #region we had not defined a special EdgeType - for single reference attributes we need to set the EdgeTypeSingle NOW! if (typeAttribute.KindOfType == KindsOfType.SingleReference) typeAttribute.EdgeType = new EdgeTypeSingleReference(null, theType.UUID); if (typeAttribute.KindOfType == KindsOfType.ListOfNoneReferences) typeAttribute.EdgeType = new EdgeTypeListOfBaseObjects(); if (typeAttribute.KindOfType == KindsOfType.SetOfReferences || typeAttribute.KindOfType == KindsOfType.SetOfNoneReferences) typeAttribute.EdgeType = new EdgeTypeSetOfReferences(null, theType.UUID); #endregion } #endregion var aTempResult = myDBContext.DBTypeManager.AddAttributeToType(myGraphDBType, typeAttribute); if (!aTempResult.Success()) { return aTempResult; } } catch (Exception e) { var aError = new Error_UnknownDBError(e); return new Exceptional(aError); } } #endregion #region add BackwardEdges if (_BackwardEdgeInformation != null) { foreach (var beDef in _BackwardEdgeInformation) { //GraphDBType edgeType = typeManager.GetTypeByName(tuple.TypeName); //TypeAttribute edgeAttribute = edgeType.GetTypeAttributeByName(tuple.TypeAttributeName); var typeAttribute = myDBContext.DBTypeManager.CreateBackwardEdgeAttribute(beDef, myGraphDBType); if (typeAttribute.Failed()) { return new Exceptional(typeAttribute); } // TODO: go through all DB Objects of the _TypeName and change the implicit backward edge type to the new ta.EdgeType // if the DBObject has one! try { var aTempResult = myDBContext.DBTypeManager.AddAttributeToType(myGraphDBType, typeAttribute.Value); if (aTempResult.Failed()) { return aTempResult; } } catch (Exception e) { return new Exceptional(new Error_UnknownDBError(e)); } } } #endregion return Exceptional.OK; }
public override Exceptional Execute(DBContext dbContext, GraphDBType graphDBType) { var listOfTypeAttrs = new List<TypeAttribute>(); var retExcept = new Exceptional(); foreach (var attr in _ListOfAttributes) { var typeAttr = graphDBType.GetTypeAttributeByName(attr); if (typeAttr == null) { return new Exceptional(new Error_AttributeIsNotDefined(attr)); } var attrType = dbContext.DBTypeManager.GetTypeByUUID(typeAttr.DBTypeUUID); if (attrType == null) return new Exceptional(new Error_TypeDoesNotExist("")); if (attrType.IsUserDefined) return new Exceptional(new Error_InvalidReferenceAssignmentOfUndefAttr()); listOfTypeAttrs.Add(typeAttr); } var dbobjects = dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(graphDBType, dbContext.DBTypeManager), dbContext); foreach (var item in dbobjects) { if (!item.Success()) { retExcept.PushIExceptional(item); } else { foreach (var attr in listOfTypeAttrs) { if (item.Value.HasAttribute(attr.UUID, graphDBType)) { var attrVal = item.Value.GetAttribute(attr.UUID); var addExcept = item.Value.AddUndefinedAttribute(attr.Name, attrVal, dbContext.DBObjectManager); if (!addExcept.Success()) retExcept.PushIExceptional(addExcept); item.Value.RemoveAttribute(attr.UUID); var saveExcept = dbContext.DBObjectManager.FlushDBObject(item.Value); if (!saveExcept.Success()) retExcept.PushIExceptional(saveExcept); } } } } var indices = graphDBType.GetAllAttributeIndices(); List<AAttributeIndex> idxToDelete = new List<AAttributeIndex>(); //remove attributes from type foreach (var attr in listOfTypeAttrs) { foreach (var item in indices) { var index = item.IndexKeyDefinition.IndexKeyAttributeUUIDs.Find(idx => idx == attr.UUID); if (index != null && item.IndexKeyDefinition.IndexKeyAttributeUUIDs.Count == 1) { idxToDelete.Add(item); } } //remove indices foreach (var idx in idxToDelete) { var remExcept = graphDBType.RemoveIndex(idx.IndexName, idx.IndexEdition, dbContext.DBTypeManager); if (!remExcept.Success()) { retExcept.PushIExceptional(remExcept); } } idxToDelete.Clear(); graphDBType.RemoveAttribute(attr.UUID); var flushExcept = dbContext.DBTypeManager.FlushType(graphDBType); if (!flushExcept.Success()) { retExcept.PushIExceptional(flushExcept); } } return retExcept; }
/// <summary> /// <seealso cref=" AAttributeAssignOrUpdateOrRemove"/> /// </summary> public override Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>> Update(DBContext myDBContext, DBObjectStream myDBObjectStream, GraphDBType myGraphDBType) { Dictionary<String, Tuple<TypeAttribute, IObject>> attrsForResult = new Dictionary<String, Tuple<TypeAttribute, IObject>>(); #region AttributeRemove #region divide remove list in undefined and defined attributes var undefAttrsExcept = myDBObjectStream.GetUndefinedAttributePayload(myDBContext.DBObjectManager); if (undefAttrsExcept.Failed()) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(undefAttrsExcept); } var undefAttrsOfObject = undefAttrsExcept.Value; var undefAttrsToRemove = ToBeRemovedAttributes.Where(item => undefAttrsOfObject.ContainsKey(item)).ToList(); List<String> defAttrsToRemove = new List<String>(); List<String> unknowAttrs = new List<String>(); foreach (var item in ToBeRemovedAttributes.Where(item => !undefAttrsOfObject.ContainsKey(item)).ToList()) { if (myGraphDBType.GetTypeAttributeByName(item) != null) defAttrsToRemove.Add(item); else unknowAttrs.Add(item); } #endregion #region remove undefined attributes if (!unknowAttrs.IsNullOrEmpty()) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(new Error_InvalidUndefinedAttributes(unknowAttrs)); } foreach (var aAttribute in undefAttrsToRemove) { var removeExcept = myDBContext.DBObjectManager.RemoveUndefinedAttribute(aAttribute, myDBObjectStream); if (removeExcept.Failed()) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(removeExcept); } attrsForResult.Add(aAttribute, new Tuple<TypeAttribute, IObject>(new UndefinedTypeAttribute(aAttribute), null)); } //if (!undefAttrsToRemove.IsNullOrEmpty()) // sthChanged = true; #endregion #region RemoveAttribute var applyRemoveResult = ApplyRemoveAttribute(defAttrsToRemove, myDBContext, myDBObjectStream, myGraphDBType); if (applyRemoveResult.Failed()) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(applyRemoveResult); } if (applyRemoveResult.Value.Count > 0) { //sthChanged = true; #region Add to queryResult foreach (var attr in applyRemoveResult.Value) { attrsForResult.Add(attr.Name, new Tuple<TypeAttribute, IObject>(attr, null)); } #endregion } #endregion #endregion return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult); }
/// <summary> /// Execute the remove of attributes /// </summary> /// <param name="myAttrsToRemove">The list of attributes to remove</param> /// <param name="myDBContext">The db context</param> /// <param name="myDBDBObject">The db object from which the attributes should be deleted</param> /// <param name="myGraphDBType">The type of the db object</param> /// <returns>The list of removed attributes</returns> private Exceptional<List<TypeAttribute>> ApplyRemoveAttribute(List<string> myAttrsToRemove, DBContext myDBContext, DBObjectStream myDBDBObject, GraphDBType myGraphDBType) { #region data List<TypeAttribute> removedAttributes = new List<TypeAttribute>(); #endregion var MandatoryTypeAttrib = myGraphDBType.GetMandatoryAttributesUUIDs(myDBContext.DBTypeManager); foreach (String aAttribute in myAttrsToRemove) { TypeAttribute typeAttribute = myGraphDBType.GetTypeAttributeByName(aAttribute); if (myDBDBObject.HasAttribute(typeAttribute.UUID, myGraphDBType)) { if (!MandatoryTypeAttrib.Contains(typeAttribute.UUID)) { #region remove backward edges if (typeAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined) { var userdefinedAttributes = new Dictionary<AttributeUUID, object>(); userdefinedAttributes.Add(typeAttribute.UUID, myDBDBObject.GetAttribute(typeAttribute.UUID)); RemoveBackwardEdges(myGraphDBType.UUID, userdefinedAttributes, myDBDBObject.ObjectUUID, myDBContext); } #endregion myDBDBObject.RemoveAttribute(typeAttribute.UUID); removedAttributes.Add(typeAttribute); } else { return new Exceptional<List<TypeAttribute>>(new Error_MandatoryConstraintViolation("Error in update statement. The attribute \"" + typeAttribute.Name + "\" is mandatory and can not be removed.")); } } } return new Exceptional<List<TypeAttribute>>(removedAttributes); }