protected Exceptional<IDictionary<String, IObject>> LoadUndefAttributes(String myName, DBContext dbContext, DBObjectStream myObjStream) { var loadExcept = myObjStream.GetUndefinedAttributePayload(dbContext.DBObjectManager); if (loadExcept.Failed()) return new Exceptional<IDictionary<string, IObject>>(loadExcept); return new Exceptional<IDictionary<string, IObject>>(loadExcept.Value); }
/// <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); }
private Exceptional<String> CreateGraphDMLforDBObject(DumpFormats myDumpFormat, DBContext myDBContext, GraphDBType myGraphDBType, DBObjectStream myDBObjectStream) { var stringBuilder = new StringBuilder(); var delimiter = ", "; stringBuilder.Append(String.Concat(S_INSERT.ToUpperString(), " ", S_INTO.ToUpperString(), " ", myGraphDBType.Name, " ", S_VALUES.ToUpperString(), " ", S_BRACKET_LEFT)); stringBuilder.Append(String.Concat(S_UUID.ToUpperString(), " = '", myDBObjectStream.ObjectUUID.ToString(), "'", delimiter)); #region CreateGraphDMLforDBODefinedAttributes var defAttrsDML = CreateGraphDMLforDBObjectDefinedAttributes(myDumpFormat, myDBObjectStream.GetAttributes(), myGraphDBType, myDBObjectStream, myDBContext); if (!defAttrsDML.Success()) { return defAttrsDML; } stringBuilder.Append(defAttrsDML.Value); #endregion #region CreateGDMLforDBOUnDefinedAttributes var undefAttrs = myDBObjectStream.GetUndefinedAttributePayload(myDBContext.DBObjectManager); if (!undefAttrs.Success()) { return new Exceptional<String>(undefAttrs); } if (undefAttrs.Value.Count > 0) { Exceptional<String> undefAttrsDML = CreateGraphDMLforDBObjectUndefinedAttributes(myDumpFormat, undefAttrs.Value, myGraphDBType, myDBObjectStream); if (!undefAttrsDML.Success()) { return undefAttrsDML; } stringBuilder.Append(undefAttrsDML.Value); } #endregion stringBuilder.RemoveSuffix(delimiter); stringBuilder.Append(S_BRACKET_RIGHT); return new Exceptional<String>(stringBuilder.ToString()); }
/// <summary> /// This will add all attributes of <paramref name="myDBObject"/> to the <paramref name="myAttributes"/> reference. Reference attributes will be resolved to the <paramref name="myDepth"/> /// </summary> /// <param name="myAttributes"></param> /// <param name="myType"></param> /// <param name="myDBObject"></param> /// <param name="myDepth"></param> /// <param name="myEdgeList"></param> /// <param name="myReference"></param> /// <param name="myUsingGraph"></param> /// <param name="mySelType"></param> /// <param name="myTypeID"></param> private void AddAttributesByDBO(ref Dictionary<String, Object> myAttributes, GraphDBType myType, DBObjectStream myDBObject, Int64 myDepth, EdgeList myEdgeList, String myReference, Boolean myUsingGraph, TypesOfSelect mySelType, TypeUUID myTypeID = null) { #region Get all attributes which are stored at the DBO foreach (var attr in myDBObject.GetAttributes()) { #region Check whether the attribute is still exist in the type - if not, continue var typeAttr = myType.GetTypeAttributeByUUID(attr.Key); if (typeAttr == null) { continue; } #endregion #region Only attributes of the selected myTypeID (TypesOfSelect.Ad) if (mySelType == TypesOfSelect.Ad) { if (myTypeID != typeAttr.GetDBType(_DBContext.DBTypeManager).UUID) { continue; } } #endregion if (attr.Value is ADBBaseObject) { #region Single base object if (mySelType != TypesOfSelect.Minus && mySelType != TypesOfSelect.Gt && mySelType != TypesOfSelect.Lt) { myAttributes.Add(typeAttr.Name, (attr.Value as ADBBaseObject).GetReadoutValue()); } #endregion } else if (attr.Value is IBaseEdge) { #region List of base objects if (mySelType != TypesOfSelect.Minus && mySelType != TypesOfSelect.Gt && mySelType != TypesOfSelect.Lt) { myAttributes.Add(typeAttr.Name, (attr.Value as IBaseEdge).GetReadoutValues()); } #endregion } else if (attr.Value is IReferenceEdge) { #region Reference edge if (mySelType == TypesOfSelect.Minus || mySelType == TypesOfSelect.Asterisk || mySelType == TypesOfSelect.Ad || mySelType == TypesOfSelect.Gt) { // Since we can define special depth (via setting) for attributes we need to check them now myDepth = GetDepth(-1, myDepth, myType, typeAttr); if ((myDepth > 0)) { myAttributes.Add(typeAttr.Name, ResolveAttributeValue(typeAttr, attr.Value, myDepth, myEdgeList, myDBObject, myReference, myUsingGraph)); } else { myAttributes.Add(typeAttr.Name, GetNotResolvedReferenceAttributeValue(myDBObject, typeAttr, myType, myEdgeList, myUsingGraph, _DBContext)); } } #endregion } else { throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } #endregion #region Get all backwardEdge attributes if (mySelType == TypesOfSelect.Minus || mySelType == TypesOfSelect.Asterisk || mySelType == TypesOfSelect.Ad || mySelType == TypesOfSelect.Lt) { foreach (var beAttr in GetBackwardEdgeAttributes(myType)) { if (myDepth > 0) { if (mySelType == TypesOfSelect.Ad) { if (beAttr.BackwardEdgeDefinition.TypeUUID != myTypeID) { continue; } } var bes = myDBObject.GetBackwardEdges(beAttr.BackwardEdgeDefinition, _DBContext, _DBContext.DBObjectCache, beAttr.GetDBType(_DBContext.DBTypeManager)); if (bes.Failed()) throw new GraphDBException(bes.IErrors); if (bes.Value != null) // otherwise the DBO does not have any myAttributes.Add(beAttr.Name, ResolveAttributeValue(beAttr, bes.Value, myDepth, myEdgeList, myDBObject, myReference, myUsingGraph)); } else { if (mySelType == TypesOfSelect.Ad) { if (beAttr.BackwardEdgeDefinition.TypeUUID != myTypeID) { continue; } } var notResolvedBEs = GetNotResolvedBackwardEdgeReferenceAttributeValue(myDBObject, beAttr, beAttr.BackwardEdgeDefinition, myEdgeList, myUsingGraph, _DBContext); if (notResolvedBEs != null) { myAttributes.Add(beAttr.Name, notResolvedBEs); } } } } #endregion #region Get all undefined attributes from DBO if (mySelType == TypesOfSelect.Asterisk || mySelType == TypesOfSelect.Rhomb) { var undefAttrException = myDBObject.GetUndefinedAttributePayload(_DBContext.DBObjectManager); if (undefAttrException.Failed()) throw new GraphDBException(undefAttrException.IErrors); foreach (var undefAttr in undefAttrException.Value) myAttributes.Add(undefAttr.Key, undefAttr.Value.GetReadoutValue()); } #endregion #region Add special attributes if (mySelType == TypesOfSelect.Asterisk) { foreach (var specialAttr in GetSpecialAttributes(myType)) { if (!myAttributes.ContainsKey(specialAttr.Name)) { var result = (specialAttr as ASpecialTypeAttribute).ExtractValue(myDBObject, myType, _DBContext); if (result.Failed()) { throw new GraphDBException(result.IErrors); } myAttributes.Add(specialAttr.Name, result.Value.GetReadoutValue()); } } } #endregion }