public DBObjectMR(DBObjectStream myDBObject, GraphDBType myDBTypeStream, DBContext myTypeManager) { _ObjectUUID = myDBObject.ObjectUUID; _Attributes = new Dictionary<String, Object>(); foreach (var _Attribute in myDBTypeStream.Attributes) { _Attributes.Add(_Attribute.Value.Name, myDBObject.GetAttribute(_Attribute.Key)); } }
/// <summary> /// Creates IndexKeys from a DBObject. /// </summary> /// <param name="myDBObject">The DBObject reference for the resulting IndexKeys</param> /// <param name="myTypeOfDBObject">The Type of the DBObject</param> /// <param name="myToken">The SessionInfos</param> /// <returns>A HashSet of IndexKeys</returns> private HashSet<IndexKey> GetIndexkeysFromDBObject(DBObjectStream myDBObject, GraphDBType myTypeOfDBObject, DBContext dbContext) { HashSet<IndexKey> result = new HashSet<IndexKey>(); TypeAttribute currentAttribute; foreach (var aIndexAttributeUUID in IndexKeyDefinition.IndexKeyAttributeUUIDs) { currentAttribute = myTypeOfDBObject.GetTypeAttributeByUUID(aIndexAttributeUUID); if (!currentAttribute.GetDBType(dbContext.DBTypeManager).IsUserDefined) { #region base attribute if (myDBObject.HasAttribute(aIndexAttributeUUID, myTypeOfDBObject)) { ADBBaseObject newIndexKeyItem = null; switch (currentAttribute.KindOfType) { #region List/Set case KindsOfType.ListOfNoneReferences: case KindsOfType.SetOfNoneReferences: var helperSet = new List<ADBBaseObject>(); foreach (var aBaseObject in ((IBaseEdge)myDBObject.GetAttribute(aIndexAttributeUUID, myTypeOfDBObject, dbContext)).GetBaseObjects()) { helperSet.Add((ADBBaseObject)aBaseObject); } if (result.Count != 0) { #region update HashSet<IndexKey> helperResultSet = new HashSet<IndexKey>(); foreach (var aNewItem in helperSet) { foreach (var aReturnVal in result) { helperResultSet.Add(new IndexKey(aReturnVal, aIndexAttributeUUID, aNewItem, this.IndexKeyDefinition)); } } result = helperResultSet; #endregion } else { #region create new foreach (var aNewItem in helperSet) { result.Add(new IndexKey(aIndexAttributeUUID, aNewItem, this.IndexKeyDefinition)); } #endregion } break; #endregion #region single/special case KindsOfType.SingleReference: case KindsOfType.SingleNoneReference: case KindsOfType.SpecialAttribute: newIndexKeyItem = (ADBBaseObject)myDBObject.GetAttribute(aIndexAttributeUUID, myTypeOfDBObject, dbContext); if (result.Count != 0) { #region update foreach (var aResultItem in result) { aResultItem.AddAADBBAseObject(aIndexAttributeUUID, newIndexKeyItem); } #endregion } else { #region create new result.Add(new IndexKey(aIndexAttributeUUID, newIndexKeyItem, this.IndexKeyDefinition)); #endregion } break; #endregion #region not implemented case KindsOfType.SetOfReferences: default: throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "Currently its not implemented to insert anything else than a List/Set/Single of base types")); #endregion } } else { //add default value var defaultADBBAseObject = GraphDBTypeMapper.GetADBBaseObjectFromUUID(currentAttribute.DBTypeUUID); defaultADBBAseObject.SetValue(DBObjectInitializeType.Default); if (result.Count != 0) { #region update foreach (var aResultItem in result) { aResultItem.AddAADBBAseObject(aIndexAttributeUUID, defaultADBBAseObject); } #endregion } else { #region create new result.Add(new IndexKey(aIndexAttributeUUID, defaultADBBAseObject, this.IndexKeyDefinition)); #endregion } } #endregion } else { #region reference attribute throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); #endregion } } return result; }
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 AttributeUpdateList #region data Exceptional validateResult = AttributeIDChain.Validate(myDBContext, false); if (validateResult.Failed()) { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(validateResult); } TypeAttribute attrDef = AttributeIDChain.LastAttribute; IEdgeType elementsToBeAdded; EdgeTypeListOfBaseObjects undefAttrList; #endregion #region undefined attributes if (AttributeIDChain.IsUndefinedAttribute) { if (Assign) { undefAttrList = new EdgeTypeListOfBaseObjects(); } else { var loadExcept = LoadUndefAttributes(AttributeIDChain.UndefinedAttribute, myDBContext, myDBObjectStream); if (loadExcept.Failed()) return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(loadExcept); if (!loadExcept.Value.ContainsKey(AttributeIDChain.UndefinedAttribute)) { undefAttrList = new EdgeTypeListOfBaseObjects(); var addExcept = myDBContext.DBObjectManager.AddUndefinedAttribute(AttributeIDChain.UndefinedAttribute, undefAttrList, myDBObjectStream); if (addExcept.Failed()) return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(addExcept); } else if (!(loadExcept.Value[AttributeIDChain.UndefinedAttribute] is EdgeTypeListOfBaseObjects)) { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(new Error_InvalidAttributeKind()); } else { undefAttrList = (EdgeTypeListOfBaseObjects) loadExcept.Value[AttributeIDChain.UndefinedAttribute]; } } var elementsToBeAddedEdge = (IBaseEdge)undefAttrList.GetNewInstance(); foreach (var tuple in CollectionDefinition.TupleDefinition) { if (tuple.Value is ValueDefinition) { var elemToAdd = (tuple.Value as ValueDefinition).Value; ((EdgeTypeListOfBaseObjects)elementsToBeAddedEdge).Add(elemToAdd); undefAttrList.Add(elemToAdd); } else { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } if (CollectionDefinition.CollectionType == CollectionType.Set) undefAttrList.UnionWith(undefAttrList); var addUndefExcept = myDBContext.DBObjectManager.AddUndefinedAttribute(AttributeIDChain.UndefinedAttribute, undefAttrList, myDBObjectStream); if (addUndefExcept.Failed()) return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(addUndefExcept); attrsForResult.Add(AttributeIDChain.UndefinedAttribute, new Tuple<TypeAttribute, IObject>(AttributeIDChain.LastAttribute, elementsToBeAddedEdge)); return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(attrsForResult); } #endregion #region Validation that this is really a list if (attrDef.KindOfType == KindsOfType.SetOfReferences && CollectionDefinition.CollectionType == CollectionType.List) { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(new Error_InvalidAssignOfSet(attrDef.Name)); } #endregion if (attrDef.KindOfType == KindsOfType.ListOfNoneReferences || attrDef.KindOfType == KindsOfType.SetOfNoneReferences) { #region ListOfNoneReferences or SetOfNoneReferences - the edge is in this case IBaseEdge elementsToBeAdded = ((IEdgeType)AttributeIDChain.LastAttribute.EdgeType.GetNewInstance()); foreach (var tupleElem in CollectionDefinition.TupleDefinition) { (elementsToBeAdded as IBaseEdge).Add(GraphDBTypeMapper.GetGraphObjectFromTypeName(attrDef.GetDBType(myDBContext.DBTypeManager).Name, (tupleElem.Value as ValueDefinition).Value.Value), tupleElem.Parameters.ToArray()); } #endregion } else { #region References if (CollectionDefinition.CollectionType == CollectionType.SetOfUUIDs) { var result = CollectionDefinition.TupleDefinition.GetAsUUIDEdge(myDBContext, attrDef); if (result.Failed()) { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(result); } elementsToBeAdded = (IEdgeType)result.Value; } else { if (AttributeIDChain.LastAttribute.EdgeType == null) { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(new Error_InvalidEdgeType(AttributeIDChain.LastAttribute.GetType())); } var result = CollectionDefinition.TupleDefinition.GetCorrespondigDBObjectUUIDAsList(myGraphDBType, myDBContext, AttributeIDChain.LastAttribute.EdgeType.GetNewInstance(), AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager)); if (result.Failed()) { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(result); } elementsToBeAdded = (IEdgeType)result.Value; } #endregion } #region add elements if (elementsToBeAdded == null) { return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(new Error_UpdateAttributeNoElements(AttributeIDChain.LastAttribute)); } if (myDBObjectStream.HasAttribute(AttributeIDChain.LastAttribute.UUID, attrDef.GetRelatedType(myDBContext.DBTypeManager))) { if (Assign) { if (elementsToBeAdded is IReferenceEdge) { var oldEdge = ((IListOrSetEdgeType)myDBObjectStream.GetAttribute(AttributeIDChain.LastAttribute.UUID)); var removeRefExcept = RemoveBackwardEdgesOnReferences(this, (IReferenceEdge)oldEdge, myDBObjectStream, myDBContext); if (!removeRefExcept.Success()) { return new Exceptional<Dictionary<string,Tuple<TypeAttribute,IObject>>>(removeRefExcept.IErrors.First()); } } var alterResult = myDBObjectStream.AlterAttribute(AttributeIDChain.LastAttribute.UUID, elementsToBeAdded); if (alterResult.Failed()) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(alterResult); } } else { ((IListOrSetEdgeType)myDBObjectStream.GetAttribute(AttributeIDChain.LastAttribute.UUID)).UnionWith((IListOrSetEdgeType)elementsToBeAdded); } } else { myDBObjectStream.AddAttribute(AttributeIDChain.LastAttribute.UUID, elementsToBeAdded); } #region add backward edges if (AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined) { Dictionary<AttributeUUID, IObject> userdefinedAttributes = new Dictionary<AttributeUUID, IObject>(); userdefinedAttributes.Add(AttributeIDChain.LastAttribute.UUID, elementsToBeAdded); var omm = new ObjectManipulationManager(); var setBackEdgesExcept = omm.SetBackwardEdges(myGraphDBType, userdefinedAttributes, myDBObjectStream.ObjectUUID, myDBContext); if (setBackEdgesExcept.Failed()) return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(setBackEdgesExcept); } #endregion attrsForResult.Add(AttributeIDChain.LastAttribute.Name, new Tuple<TypeAttribute, IObject>(AttributeIDChain.LastAttribute, elementsToBeAdded)); return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult); #endregion #endregion }
private IEnumerable<Exceptional<DBObjectStream>> GetReferenceObjects(DBObjectStream myStartingDBObject, TypeAttribute interestingAttributeEdge, GraphDBType myStartingDBObjectType, DBTypeManager myDBTypeManager) { if (interestingAttributeEdge.GetDBType(myDBTypeManager).IsUserDefined || interestingAttributeEdge.IsBackwardEdge) { switch (interestingAttributeEdge.KindOfType) { case KindsOfType.SingleReference: yield return LoadDBObjectStream(interestingAttributeEdge.GetDBType(myDBTypeManager), ((ASingleReferenceEdgeType)myStartingDBObject.GetAttribute(interestingAttributeEdge.UUID)).GetUUID()); break; case KindsOfType.SetOfReferences: if (interestingAttributeEdge.IsBackwardEdge) { //get backwardEdge var beStream = LoadDBBackwardEdgeStream(myStartingDBObjectType, myStartingDBObject.ObjectUUID); if (beStream.Failed()) { throw new GraphDBException(new Error_ExpressionGraphInternal(null, String.Format("Error while trying to get BackwardEdge of the DBObject: \"{0}\"", myStartingDBObject.ToString()))); } if (beStream.Value.ContainsBackwardEdge(interestingAttributeEdge.BackwardEdgeDefinition)) { foreach (var aBackwardEdgeObject in LoadListOfDBObjectStreams(interestingAttributeEdge.BackwardEdgeDefinition.TypeUUID, beStream.Value.GetBackwardEdgeUUIDs(interestingAttributeEdge.BackwardEdgeDefinition))) { yield return aBackwardEdgeObject; } } } else { foreach (var aDBOStream in LoadListOfDBObjectStreams(interestingAttributeEdge.GetDBType(myDBTypeManager), ((ASetOfReferencesEdgeType)myStartingDBObject.GetAttribute(interestingAttributeEdge.UUID)).GetAllReferenceIDs())) { yield return aDBOStream; } } break; case KindsOfType.SetOfNoneReferences: case KindsOfType.ListOfNoneReferences: default: throw new GraphDBException(new Error_ExpressionGraphInternal(new System.Diagnostics.StackTrace(true), String.Format("The attribute \"{0}\" has an invalid KindOfType \"{1}\"!", interestingAttributeEdge.Name, interestingAttributeEdge.KindOfType.ToString()))); } } else { throw new GraphDBException(new Error_ExpressionGraphInternal(new System.Diagnostics.StackTrace(true), String.Format("The attribute \"{0}\" is no reference attribute.", interestingAttributeEdge.Name))); } yield break; }
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 AttributeRemoveList #region data Exceptional validateResult = AttributeIDChain.Validate(myDBContext, false); if (validateResult.Failed()) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(validateResult); } ASetOfReferencesEdgeType _elementsToBeRemoved; EdgeTypeListOfBaseObjects undefAttrList; #endregion #region undefined attributes if (AttributeIDChain.IsUndefinedAttribute) { var loadExcept = LoadUndefAttributes(AttributeName, myDBContext, myDBObjectStream); if (loadExcept.Failed()) return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(loadExcept); if (!loadExcept.Value.ContainsKey(AttributeName)) { attrsForResult.Add(AttributeName, new Tuple<TypeAttribute, IObject>(AttributeIDChain.LastAttribute, null)); return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult); } if (!(loadExcept.Value[AttributeName] is EdgeTypeListOfBaseObjects)) return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(new Error_InvalidAttributeKind()); undefAttrList = (EdgeTypeListOfBaseObjects)loadExcept.Value[AttributeName]; foreach (var tuple in TupleDefinition) { undefAttrList.Remove((tuple.Value as ValueDefinition).Value); } myDBContext.DBObjectManager.AddUndefinedAttribute(AttributeName, undefAttrList, myDBObjectStream); attrsForResult.Add(AttributeName, new Tuple<TypeAttribute, IObject>(AttributeIDChain.LastAttribute, null)); return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult); } #endregion #region get elements if (AttributeIDChain.LastAttribute.EdgeType == null) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(new Error_InvalidEdgeType(AttributeIDChain.LastAttribute.GetType())); } var elements = TupleDefinition.GetCorrespondigDBObjectUUIDAsList(myGraphDBType, myDBContext, AttributeIDChain.LastAttribute.EdgeType.GetNewInstance(), AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager)); if(!elements.Success()) { return new Exceptional<Dictionary<string,Tuple<TypeAttribute,IObject>>>(elements); } _elementsToBeRemoved = (ASetOfReferencesEdgeType)elements.Value; #endregion #region remove elements from list if (_elementsToBeRemoved == null) { return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(new Error_UpdateAttributeNoElements(AttributeIDChain.LastAttribute)); } if (myDBObjectStream.HasAttribute(AttributeIDChain.LastAttribute.UUID, AttributeIDChain.LastAttribute.GetRelatedType(myDBContext.DBTypeManager))) { ASetOfReferencesEdgeType edge = (ASetOfReferencesEdgeType)myDBObjectStream.GetAttribute(AttributeIDChain.LastAttribute.UUID); foreach (var aUUID in (_elementsToBeRemoved as ASetOfReferencesEdgeType).GetAllReferenceIDs()) { edge.RemoveUUID(aUUID); } #region remove backward edges if (AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined) { Dictionary<AttributeUUID, object> userdefinedAttributes = new Dictionary<AttributeUUID, object>(); userdefinedAttributes.Add(AttributeIDChain.LastAttribute.UUID, _elementsToBeRemoved); RemoveBackwardEdges(myGraphDBType.UUID, userdefinedAttributes, myDBObjectStream.ObjectUUID, myDBContext); } #endregion attrsForResult.Add(AttributeIDChain.LastAttribute.Name, new Tuple<TypeAttribute, IObject>(AttributeIDChain.LastAttribute, edge)); return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult); } #endregion #endregion return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult); }
internal Exceptional<Tuple<String, TypeAttribute, IObject>> ApplyAssignAttribute(AAttributeAssignOrUpdate myAAttributeAssign, DBContext myDBContext, DBObjectStream myDBObject, GraphDBType myGraphDBType) { System.Diagnostics.Debug.Assert(myAAttributeAssign != null); //get value for assignement var aValue = myAAttributeAssign.GetValueForAttribute(myDBObject, myDBContext, myGraphDBType); if (aValue.Failed()) { return new Exceptional<Tuple<String, TypeAttribute, IObject>>(aValue); } object oldValue = null; IObject newValue = aValue.Value; if (myDBObject.HasAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, myGraphDBType)) { #region Update the value because it already exists oldValue = myDBObject.GetAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute, myGraphDBType, myDBContext).Value; switch (myAAttributeAssign.AttributeIDChain.LastAttribute.KindOfType) { case KindsOfType.SetOfReferences: var typeOfCollection = ((AttributeAssignOrUpdateList)myAAttributeAssign).CollectionDefinition.CollectionType; if (typeOfCollection == CollectionType.List) return new Exceptional<Tuple<String, TypeAttribute, IObject>>(new Error_InvalidAssignOfSet(myAAttributeAssign.AttributeIDChain.LastAttribute.Name)); var removeRefExcept = RemoveBackwardEdgesOnReferences(myAAttributeAssign, (IReferenceEdge)oldValue, myDBObject, myDBContext); if (!removeRefExcept.Success()) return new Exceptional<Tuple<String, TypeAttribute, IObject>>(removeRefExcept.IErrors.First()); newValue = (ASetOfReferencesEdgeType)newValue; break; case KindsOfType.SetOfNoneReferences: case KindsOfType.ListOfNoneReferences: newValue = (IBaseEdge)newValue; break; case KindsOfType.SingleNoneReference: if (!(oldValue as ADBBaseObject).IsValidValue((newValue as ADBBaseObject).Value)) { return new Exceptional<Tuple<string, TypeAttribute, IObject>>(new Error_DataTypeDoesNotMatch((oldValue as ADBBaseObject).ObjectName, (newValue as ADBBaseObject).ObjectName)); } newValue = (oldValue as ADBBaseObject).Clone((newValue as ADBBaseObject).Value); break; case KindsOfType.SingleReference: if (newValue is ASingleReferenceEdgeType) { removeRefExcept = RemoveBackwardEdgesOnReferences(myAAttributeAssign, (IReferenceEdge)oldValue, myDBObject, myDBContext); if (!removeRefExcept.Success()) return new Exceptional<Tuple<String, TypeAttribute, IObject>>(removeRefExcept.IErrors.First()); ((ASingleReferenceEdgeType)oldValue).Merge((ASingleReferenceEdgeType)newValue); newValue = (ASingleReferenceEdgeType)oldValue; } break; case KindsOfType.SpecialAttribute: // Special attributes can't be updated currently if ((newValue as DBString) != null && (newValue as DBString).CompareTo(oldValue) == 0) { return new Exceptional<Tuple<string, GraphDB.TypeManagement.TypeAttribute, GraphDB.TypeManagement.IObject>>(new Tuple<string, GraphDB.TypeManagement.TypeAttribute, GraphDB.TypeManagement.IObject>(myAAttributeAssign.AttributeIDChain.LastAttribute.Name, myAAttributeAssign.AttributeIDChain.LastAttribute, newValue as IObject)); } else { return new Exceptional<Tuple<String, TypeAttribute, IObject>>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } break; default: return new Exceptional<Tuple<String, TypeAttribute, IObject>>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } #endregion } var alterExcept = myDBObject.AlterAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, newValue); if (alterExcept.Failed()) return new Exceptional<Tuple<string, TypeAttribute, IObject>>(alterExcept); if (!alterExcept.Value) { myDBObject.AddAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, newValue); } #region add backward edges if (myAAttributeAssign.AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined) { Dictionary<AttributeUUID, IObject> userdefinedAttributes = new Dictionary<AttributeUUID, IObject>(); userdefinedAttributes.Add(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, newValue); var omm = new ObjectManipulationManager(myDBContext, myGraphDBType); var setBackEdges = omm.SetBackwardEdges(userdefinedAttributes, myDBObject.ObjectUUID); if (setBackEdges.Failed()) return new Exceptional<Tuple<string, TypeAttribute, IObject>>(setBackEdges); } #endregion return new Exceptional<Tuple<String, TypeAttribute, IObject>>(new Tuple<String, TypeAttribute, IObject>(myAAttributeAssign.AttributeIDChain.LastAttribute.Name, myAAttributeAssign.AttributeIDChain.LastAttribute, newValue)); }
private IObject GetDbos(IDChainDefinition myIDChainDefinition, DBObjectStream myDBObjectStream, DBContext dbContext, SessionSettings mySessionToken, DBObjectCache dbObjectCache) { if (myIDChainDefinition.LastAttribute.IsBackwardEdge) { var contBackwardExcept = myDBObjectStream.ContainsBackwardEdge(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition, dbContext, dbObjectCache, myIDChainDefinition.LastAttribute.GetRelatedType(dbContext.DBTypeManager)); if (contBackwardExcept.Failed()) throw new GraphDBException(contBackwardExcept.IErrors); if (contBackwardExcept.Value) { var beStream = dbObjectCache.LoadDBBackwardEdgeStream(myIDChainDefinition.LastType, myDBObjectStream.ObjectUUID).Value; if (beStream.ContainsBackwardEdge(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition)) return beStream.GetBackwardEdges(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition); else return null; } else { return null; } } else { if (myIDChainDefinition.LastAttribute.KindOfType == KindsOfType.SpecialAttribute) { return myDBObjectStream.GetAttribute(myIDChainDefinition.LastAttribute.UUID, myIDChainDefinition.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext); } else { return myDBObjectStream.GetAttribute(myIDChainDefinition.LastAttribute.UUID); } } }
/// <summary> /// Extracts the attribute from <paramref name="myDBObject"/>. /// </summary> /// <param name="myType"></param> /// <param name="myTypeAttribute"></param> /// <param name="myDBObject"></param> /// <param name="myLevelKey"></param> /// <returns></returns> private Object GetAttributeValue(GraphDBType myType, TypeAttribute myTypeAttribute, DBObjectStream myDBObject, EdgeList myLevelKey) { if (myTypeAttribute.TypeCharacteristics.IsBackwardEdge) { #region IsBackwardEdge EdgeKey edgeKey = myTypeAttribute.BackwardEdgeDefinition; var contBackwardExcept = myDBObject.ContainsBackwardEdge(edgeKey, _DBContext, _DBContext.DBObjectCache, myType); if (contBackwardExcept.Failed()) throw new GraphDBException(contBackwardExcept.IErrors); if (contBackwardExcept.Value) { var getBackwardExcept = myDBObject.GetBackwardEdges(edgeKey, _DBContext, _DBContext.DBObjectCache, myTypeAttribute.GetDBType(_DBContext.DBTypeManager)); if (getBackwardExcept.Failed()) throw new GraphDBException(getBackwardExcept.IErrors); return getBackwardExcept.Value; } #endregion } else if (myDBObject.HasAttribute(myTypeAttribute.UUID, myType)) { #region ELSE (!IsBackwardEdge) return myDBObject.GetAttribute(myTypeAttribute.UUID, myType, _DBContext); #endregion } return null; }
/// <summary> /// Get the attribute value of <paramref name="myTypeAttribute"/> and calls GetNotResolvedReferenceEdgeAttributeValue with the edge /// </summary> /// <param name="myDBObjectStream"></param> /// <param name="myTypeAttribute"></param> /// <param name="myGraphDBType"></param> /// <param name="myCurrentEdgeList"></param> /// <param name="myUsingGraph"></param> /// <param name="myDBContext"></param> /// <returns></returns> private Edge GetNotResolvedReferenceAttributeValue(DBObjectStream myDBObjectStream, TypeAttribute myTypeAttribute, GraphDBType myGraphDBType, EdgeList myCurrentEdgeList, Boolean myUsingGraph, DBContext myDBContext) { IObject attrValue = null; if (myUsingGraph) { var interestingLevelKey = new LevelKey((myCurrentEdgeList + new EdgeKey(myGraphDBType.UUID, myTypeAttribute.UUID)).Edges, myDBContext.DBTypeManager); var interestingUUIDs = _ExpressionGraph.SelectUUIDs(interestingLevelKey, myDBObjectStream); attrValue = ((IReferenceEdge)myDBObjectStream.GetAttribute(myTypeAttribute.UUID, myGraphDBType, myDBContext)).GetNewInstance(interestingUUIDs, myGraphDBType.UUID); } else { attrValue = myDBObjectStream.GetAttribute(myTypeAttribute.UUID, myGraphDBType, myDBContext); } if (attrValue == null) { return null; } var typeName = myTypeAttribute.GetDBType(myDBContext.DBTypeManager).Name; return GetNotResolvedReferenceEdgeAttributeValue(attrValue as IReferenceEdge, myTypeAttribute.GetDBType(myDBContext.DBTypeManager), myDBContext); }
/// <summary> Gets an attribute value - references will be resolved. </summary> /// /// <remarks> Stefan, 16.04.2010. </remarks> /// /// <param name="myType"> Type. </param> /// <param name="myTypeAttribute"> my type attribute. </param> /// <param name="myDBObject"> my database object. </param> /// <param name="myDepth"> Depth of my. </param> /// <param name="myLevelKey"> my level key. </param> /// <param name="reference"> The reference. </param> /// <param name="myUsingGraph"> true to my using graph. </param> /// <param name="attributeValue"> [out] The attribute value. </param> /// /// <returns> true if it succeeds, false if the DBO does not have the attribute. </returns> private Boolean GetAttributeValueAndResolve(GraphDBType myType, SelectionElement mySelectionelement, DBObjectStream myDBObject, Int64 myDepth, EdgeList myLevelKey, String reference, Boolean myUsingGraph, out Object attributeValue, String myUndefAttrName = null) { var typeAttribute = mySelectionelement.Element; if (typeAttribute.TypeCharacteristics.IsBackwardEdge) { #region IsBackwardEdge EdgeKey edgeKey = typeAttribute.BackwardEdgeDefinition; var contBackwardExcept = myDBObject.ContainsBackwardEdge(edgeKey, _DBContext, _DBContext.DBObjectCache, myType); if (contBackwardExcept.Failed()) throw new GraphDBException(contBackwardExcept.IErrors); if (contBackwardExcept.Value) { if (myDepth > 0) { var dbos = myDBObject.GetBackwardEdges(edgeKey, _DBContext, _DBContext.DBObjectCache, typeAttribute.GetDBType(_DBContext.DBTypeManager)); if (dbos.Failed()) throw new GraphDBException(dbos.IErrors); if (dbos.Value != null) { attributeValue = ResolveAttributeValue(typeAttribute, dbos.Value, myDepth, myLevelKey, myDBObject, reference, myUsingGraph); return true; } } else { attributeValue = GetNotResolvedBackwardEdgeReferenceAttributeValue(myDBObject, typeAttribute, edgeKey, myLevelKey, myUsingGraph, _DBContext); return true; } } #endregion } else if (myDBObject.HasAttribute(typeAttribute, _DBContext)) { #region SelectValueAssignment - kind of static assignment of selected attribute if (mySelectionelement.SelectValueAssignment != null && mySelectionelement.SelectValueAssignment.ValueAssignmentType == SelectValueAssignment.ValueAssignmentTypes.Always) { // Currently the prior add SelectionElement verifies that TermDefinition is always a ValueDefinition - if others will become valid this must be changed! attributeValue = (mySelectionelement.SelectValueAssignment.TermDefinition as ValueDefinition).Value.Value; return true; } #endregion #region ELSE (!IsBackwardEdge) #region not a reference attribute value if (!typeAttribute.IsUserDefinedType(_DBContext.DBTypeManager)) { var attrVal = myDBObject.GetAttribute(typeAttribute, myType, _DBContext); if (attrVal.Failed()) { throw new GraphDBException(attrVal.IErrors); } // currently, we do not want to return a ADBBaseObject but the real value if (attrVal.Value is ADBBaseObject) attributeValue = (attrVal.Value as ADBBaseObject).GetReadoutValue(); else if (attrVal.Value is IBaseEdge) attributeValue = (attrVal.Value as IBaseEdge).GetReadoutValues(); else attributeValue = attrVal.Value; return true; } #endregion #region ELSE Reference attribute value else { if (myDepth > 0) { var attrValue = myDBObject.GetAttribute(typeAttribute.UUID, myType, _DBContext); attributeValue = ResolveAttributeValue(typeAttribute, attrValue, myDepth, myLevelKey, myDBObject, reference, myUsingGraph); return true; } else { attributeValue = GetNotResolvedReferenceAttributeValue(myDBObject, typeAttribute, myType, myLevelKey, myUsingGraph, _DBContext); return true; } } #endregion #endregion } else if (mySelectionelement.SelectValueAssignment != null) { // Currently the prior add SelectionElement verifies that TermDefinition is always a ValueDefinition - if others will become valid this must be changed! attributeValue = (mySelectionelement.SelectValueAssignment.TermDefinition as ValueDefinition).Value.Value; return true; } attributeValue = null; return false; }
private IEnumerable<ObjectUUID> GetUUIDsForAttribute(DBObjectStream currentDBObject, TypeAttribute interestingAttribute, GraphDBType myCurrentDBObjectType) { switch (interestingAttribute.KindOfType) { case KindsOfType.SingleReference: yield return ((ASingleReferenceEdgeType)currentDBObject.GetAttribute(interestingAttribute.UUID)).GetUUID(); break; case KindsOfType.SetOfReferences: if (interestingAttribute.IsBackwardEdge) { //get backwardEdge var beStream = _DBObjectCache.LoadDBBackwardEdgeStream(myCurrentDBObjectType, currentDBObject.ObjectUUID); if (beStream.Failed()) { throw new GraphDBException(new Error_CouldNotLoadBackwardEdge(currentDBObject, interestingAttribute, beStream.IErrors)); } if (beStream.Value.ContainsBackwardEdge(interestingAttribute.BackwardEdgeDefinition)) { foreach (var aBackwardEdgeUUID in beStream.Value.GetBackwardEdgeUUIDs(interestingAttribute.BackwardEdgeDefinition)) { yield return aBackwardEdgeUUID; } } } else { foreach (var aObjectUUID in ((ASetOfReferencesEdgeType)currentDBObject.GetAttribute(interestingAttribute.UUID)).GetAllReferenceIDs()) { yield return aObjectUUID; } } break; case KindsOfType.SetOfNoneReferences: case KindsOfType.ListOfNoneReferences: case KindsOfType.SingleNoneReference: default: throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace())); } }
private ValueDefinition GetAtomValue(IDChainDefinition iDNode, DBObjectStream aDBObject, DBContext dbContext) { return new ValueDefinition(GraphDBTypeMapper.ConvertGraph2CSharp(iDNode.LastAttribute.GetDBType(dbContext.DBTypeManager).Name), aDBObject.GetAttribute(iDNode.LastAttribute.UUID, iDNode.LastType, dbContext)); }
/// <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); }