/// <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> 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 Edge GetNotResolvedBackwardEdgeReferenceAttributeValue(DBObjectStream myDBObject, TypeAttribute myTypeAttribute, EdgeKey edgeKey, EdgeList currentEdgeList, Boolean myUsingGraph, DBContext _DBContext) { IObject attrValue = null; if (myUsingGraph) { var interestingLevelKey = new LevelKey((currentEdgeList + new EdgeKey(myTypeAttribute.RelatedGraphDBTypeUUID, myTypeAttribute.UUID)).Edges, _DBContext.DBTypeManager); attrValue = new EdgeTypeSetOfReferences(_ExpressionGraph.SelectUUIDs(interestingLevelKey, myDBObject), myTypeAttribute.DBTypeUUID); } else { var attrValueException = myDBObject.GetBackwardEdges(edgeKey, _DBContext, _DBContext.DBObjectCache, myTypeAttribute.GetDBType(_DBContext.DBTypeManager)); if (attrValueException.Failed()) { throw new GraphDBException(attrValueException.IErrors); } attrValue = attrValueException.Value; } if (attrValue == null) { return null; } else if (!(attrValue is IReferenceEdge)) { throw new GraphDBException(new Error_InvalidEdgeType(attrValue.GetType(), typeof(IReferenceEdge))); } var readouts = new List<Vertex>(); var typeName = _DBContext.DBTypeManager.GetTypeByUUID(edgeKey.TypeUUID).Name; foreach (var reference in (attrValue as IReferenceEdge).GetAllReferenceIDs()) { var specialAttributes = new Dictionary<string, object>(); specialAttributes.Add(SpecialTypeAttribute_UUID.AttributeName, reference); specialAttributes.Add(SpecialTypeAttribute_TYPE.AttributeName, typeName); readouts.Add(new Vertex(specialAttributes)); } return new Edge(null, readouts, _DBContext.DBTypeManager.GetTypeAttributeByEdge(edgeKey).GetDBType(_DBContext.DBTypeManager).Name); }
/// <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.GetUndefinedAttributes(_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 }