예제 #1
0
        public override Exceptional<IObject> Aggregate(AAttributeIndex attributeIndex, GraphDBType graphDBType, DBContext dbContext)
        {
            if (attributeIndex is UUIDIndex)
            {
                return new Exceptional<IObject>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "Aggregating attribute UUID is not implemented!"));
            }
            else
            {
                var indexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(attributeIndex.IndexRelatedTypeUUID);

                // HACK: rewrite as soon as we have real attribute index keys
                if (attributeIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs.Count != 1)
                {
                    return new Exceptional<IObject>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                }

                var typeAttr = graphDBType.GetTypeAttributeByUUID(attributeIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs.First());
                ADBBaseObject oneVal = typeAttr.GetADBBaseObjectType(dbContext.DBTypeManager);

                return new Exceptional<IObject>(attributeIndex.GetKeyValues(indexRelatedType, dbContext).AsParallel().Select(kv =>
                {
                    var mul = oneVal.Clone(kv.Key);
                    mul.Mul(oneVal.Clone(kv.Value.Count()));
                    return mul;

                }).Aggregate(oneVal.Clone(), (elem, result) => { result.Add(elem); return result; }));
            }
        }
예제 #2
0
        /// <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;
        }
예제 #3
0
        private Exceptional<ResultType> AddAttributeToDBObject(GraphDBType myTypeOfDBObject, ObjectUUID myUUID, AttributeUUID myAttributeUUID, IObject myAttributeValue)
        {
            //myGraphType is needed due to correctness concerning the attribute name

            #region Input exceptions

            if ((myTypeOfDBObject == null) || (myUUID == null) || (myAttributeUUID == null) || (myAttributeValue == null))
            {
                throw new ArgumentNullException();
            }

            #endregion

            #region Check GraphType for new Attribute

            TypeAttribute typeAttribute = myTypeOfDBObject.GetTypeAttributeByUUID(myAttributeUUID);

            if (typeAttribute == null)
            {
                //Todo: add notification here (the user has to be informed about the detailed circumstances)

                GraphDBError aError = new Error_AttributeIsNotDefined(myTypeOfDBObject.Name, myAttributeUUID.ToString());

                return new Exceptional<ResultType>(aError);
            }

            #endregion

            #region Data

            var objectLocation = new ObjectLocation(myTypeOfDBObject.ObjectLocation, DBConstants.DBObjectsLocation, myUUID.ToString());
            Exceptional<DBObjectStream> aNewDBObject;
            Exceptional<ResultType> result = new Exceptional<ResultType>();

            #endregion

            #region add attribute

            aNewDBObject = _DBContext.DBObjectManager.LoadDBObject(myTypeOfDBObject, myUUID);

            if (aNewDBObject.Failed())
            {
                result.PushIError(new Error_LoadObject(aNewDBObject.Value.ObjectLocation));
                return result;
            }

            result = aNewDBObject.Value.AddAttribute(typeAttribute.UUID, myAttributeValue);

            if (result.Failed())
                return result;

            try
            {
                _DBContext.DBObjectManager.FlushDBObject(aNewDBObject.Value);
            }
            catch (Exception ex)
            {
                result.PushIError(new Error_FlushObject(aNewDBObject.Value.ObjectLocation, ex));
                aNewDBObject.Value.RemoveAttribute(typeAttribute.UUID);
            }

            #endregion

            return result;
        }
예제 #4
0
        public AttributeIndex(string indexName, IndexKeyDefinition idxKey, GraphDBType correspondingType, string indexType = null, string indexEdition = DBConstants.DEFAULTINDEX)
        {
            IndexName          = indexName;
            IndexEdition       = indexEdition;
            IndexKeyDefinition = idxKey;
            IndexRelatedTypeUUID = correspondingType.UUID;

            if (indexEdition == null)
            {
                IndexEdition = DBConstants.DEFAULTINDEX;
            }
            else
            {
                IndexEdition = indexEdition;
            }

            if (String.IsNullOrEmpty(indexType))
            {
                IndexType = VersionedHashIndexObject.Name;
            }
            else
            {
                IndexType = indexType;
            }

            #region Workaround for current IndexOperation of InOperator - just follow the IsListOfBaseObjectsIndex property

            // better approach, use a special index key for a set of base objects
            if (idxKey.IndexKeyAttributeUUIDs.Any(a =>
            {
                var typeAttr = correspondingType.GetTypeAttributeByUUID(a);
                if (typeAttr != null && (typeAttr.EdgeType is IBaseEdge))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }))
            {
                IsListOfBaseObjectsIndex = true;
            }
            else
            {
                IsListOfBaseObjectsIndex = false;
            }

            #endregion

            FileSystemLocation = (correspondingType.ObjectLocation + "Indices") + (IndexName + "#" + IndexEdition);
        }
예제 #5
0
        internal Exceptional SetBackwardEdges(GraphDBType aType, Dictionary<AttributeUUID, IObject> userdefinedAttributes, ObjectUUID reference, DBContext dbContext)
        {
            var returnVal = new Exceptional();

            #region process attributes

            foreach (var aUserDefinedAttribute in userdefinedAttributes)
            {
                #region Data

                GraphDBType     typeOFAttribute     = null;
                TypeAttribute   attributesOfType    = null;

                #endregion

                #region get GraphType of Attribute

                //attributesOfType = aType.Attributes[aUserDefinedAttribute.Key];
                attributesOfType = aType.GetTypeAttributeByUUID(aUserDefinedAttribute.Key);

                typeOFAttribute = dbContext.DBTypeManager.GetTypeByUUID(attributesOfType.DBTypeUUID);

                #endregion

                /* The DBO independent version */
                var beEdge = new EdgeKey(aType.UUID, attributesOfType.UUID);

                var runMT = DBConstants.RunMT;
                runMT = false;
                if (runMT)
                {

                    #region The parallel version

                    /**/
                    /* The parallel version */
                    Parallel.ForEach(((IReferenceEdge)aUserDefinedAttribute.Value).GetAllReferenceIDs(), (uuid) =>
                    {
                        var addExcept = dbContext.DBObjectManager.AddBackwardEdge(uuid, attributesOfType.DBTypeUUID, beEdge, reference);

                        if (!addExcept.Success())
                        {
                            returnVal.PushIExceptional(addExcept);
                        }
                    });

                    if (!returnVal.Success())
                    {
                        return returnVal;
                    }
                    /**/

                    #endregion

                }
                else
                {

                    #region Single thread

                    foreach (var uuid in ((IReferenceEdge)aUserDefinedAttribute.Value).GetAllReferenceIDs())
                    {
                        var addExcept = dbContext.DBObjectManager.AddBackwardEdge(uuid, attributesOfType.DBTypeUUID, beEdge, reference);

                        if (addExcept.Failed())
                        {
                            return new Exceptional(addExcept);
                        }
                    }

                    #endregion

                }
            }

            #endregion

            return Exceptional.OK;
        }
예제 #6
0
        private Exceptional AddMandatoryAttributes(DBContext myDBContext, GraphDBType myGraphDBType, ManipulationAttributes myManipulationAttributes)
        {
            Boolean mandatoryDefaults = (Boolean)myDBContext.DBSettingsManager.GetSettingValue((new SettingDefaultsOnMandatory()).ID, myDBContext, TypesSettingScope.TYPE, myGraphDBType).Value.Value;
            TypeAttribute typeAttr = null;
            GraphDBType typeOfAttr = null;
            var typeMandatoryAttribs = myGraphDBType.GetMandatoryAttributesUUIDs(myDBContext.DBTypeManager);

            if ((myManipulationAttributes.MandatoryAttributes.Count < typeMandatoryAttribs.Count()) && !mandatoryDefaults)
                return new Exceptional(new Error_MandatoryConstraintViolation(myGraphDBType.Name));

            foreach (var attrib in typeMandatoryAttribs)
            {
                if (!myManipulationAttributes.MandatoryAttributes.Contains(attrib))
                {
                    //if we have mandatory attributes in type but not in the current statement and USE_DEFAULTS_ON_MANDATORY is true then do this
                    if (mandatoryDefaults)
                    {
                        typeAttr = myGraphDBType.GetTypeAttributeByUUID(attrib);

                        if (typeAttr == null)
                            return new Exceptional(new Error_AttributeIsNotDefined(myGraphDBType.Name, typeAttr.Name));

                        typeOfAttr = myDBContext.DBTypeManager.GetTypeByUUID(typeAttr.DBTypeUUID);

                        IObject defaultValue = typeAttr.DefaultValue;

                        if (defaultValue == null)
                            defaultValue = typeAttr.GetDefaultValue(myDBContext);

                        myManipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(typeAttr, typeOfAttr), defaultValue);
                    }
                    else
                    {
                        return new Exceptional(new Error_MandatoryConstraintViolation("Attribute \"" + myGraphDBType.GetTypeAttributeByUUID(attrib).Name + "\" of Type \"" + myGraphDBType.Name + "\" is mandatory."));
                    }
                }
            }

            return Exceptional.OK;
        }
예제 #7
0
        public override Exceptional Initialize(DBContext myDBContext, string indexName, IndexKeyDefinition idxKey, GraphDBType correspondingType, string indexEdition = DBConstants.DEFAULTINDEX)
        {
            IndexName = indexName;
            IndexEdition = indexEdition;
            IndexKeyDefinition = idxKey;
            IndexRelatedTypeUUID = correspondingType.UUID;
            AttributeIdxShards = Convert.ToUInt16(myDBContext.GraphAppSettings.Get<AttributeIdxShardsSetting>());

            _keyCount = 0;
            _valueCount = 0;

            if (indexEdition == null)
            {
                IndexEdition = DBConstants.DEFAULTINDEX;
            }
            else
            {
                IndexEdition = indexEdition;
            }

            _IsUUIDIndex = idxKey.IndexKeyAttributeUUIDs.Count == 1 && idxKey.IndexKeyAttributeUUIDs[0].Equals(myDBContext.DBTypeManager.GetUUIDTypeAttribute().UUID);

            #region Workaround for current IndexOperation of InOperator - just follow the IsListOfBaseObjectsIndex property

            // better approach, use a special index key for a set of base objects
            if (idxKey.IndexKeyAttributeUUIDs.Any(a =>
            {
                var typeAttr = correspondingType.GetTypeAttributeByUUID(a);
                if (typeAttr != null && (typeAttr.EdgeType is IBaseEdge))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }))
            {
                IsListOfBaseObjectsIndex = true;
            }
            else
            {
                IsListOfBaseObjectsIndex = false;
            }

            #endregion

            FileSystemLocation = (correspondingType.ObjectLocation + "Indices") + (IndexName + "#" + IndexEdition);

            return Exceptional.OK;
        }
예제 #8
0
        /// <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
        
        }
예제 #9
0
        private IndexKey GenerateIndexKeyForUniqueConstraint(Dictionary<AttributeUUID, IObject> toBeCheckedForUniqueConstraint, IndexKeyDefinition myIndexKeyDefinition, GraphDBType myType)
        {
            var payload = new Dictionary<AttributeUUID, ADBBaseObject>();
            TypeAttribute currentAttribute;

            foreach (var aUnique in myIndexKeyDefinition.IndexKeyAttributeUUIDs)
            {
                currentAttribute = myType.GetTypeAttributeByUUID(aUnique);

                if (!currentAttribute.GetDBType(_DBContext.DBTypeManager).IsUserDefined)
                {
                    #region base attribute

                    if (toBeCheckedForUniqueConstraint.ContainsKey(aUnique))
                    {
                        switch (currentAttribute.KindOfType)
                        {
                            #region List/Set

                            case KindsOfType.ListOfNoneReferences:
                            case KindsOfType.SetOfNoneReferences:

                                throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "Unique idx on list of base attributes is not implemented."));

                            #endregion

                            #region single/special

                            case KindsOfType.SpecialAttribute:
                            case KindsOfType.SingleNoneReference:
                            case KindsOfType.SingleReference:

                                payload.Add(aUnique, (ADBBaseObject)toBeCheckedForUniqueConstraint[aUnique]);

                                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
                    {
                        //create default adbbaseobject

                        var defaultADBBAseObject = GraphDBTypeMapper.GetADBBaseObjectFromUUID(currentAttribute.DBTypeUUID);
                        defaultADBBAseObject.SetValue(DBObjectInitializeType.Default);

                        payload.Add(aUnique, defaultADBBAseObject);
                    }

                    #endregion
                }
                else
                {
                    #region reference attribute

                    throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));

                    #endregion
                }
            }

            return new IndexKey(payload, myIndexKeyDefinition);
        }
예제 #10
0
        public string GetUniqueIndexName(List<AttributeUUID> UniqueIDs, GraphDBType aType)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(DBConstants.IndexKeyPrefix + DBConstants.IndexKeySeperator + DBConstants.UNIQUEATTRIBUTESINDEX);

            foreach (var AttrID in UniqueIDs)
            {
                sb.Append("_" + aType.GetTypeAttributeByUUID(AttrID).Name);
            }

            return sb.ToString();
        }
예제 #11
0
        private Exceptional<String> CreateGraphDMLforDBObjectDefinedAttributes(DumpFormats myDumpFormat, IDictionary<AttributeUUID, IObject> myAttributes, GraphDBType myGraphDBType, DBObjectStream myDBObjectStream, DBContext myDBContext)
        {
            var stringBuilder = new StringBuilder();
            var delimiter = ", ";

            foreach (var attribute in myAttributes)
            {

                if (attribute.Value == null)
                {
                    continue;
                }

                var typeAttribute = myGraphDBType.GetTypeAttributeByUUID(attribute.Key);

                #region Reference attributes

                if (typeAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined)
                {

                    #region IReferenceEdge

                    if (attribute.Value is ASetOfReferencesEdgeType)
                    {

                        #region Create edge GDML

                        stringBuilder.Append(String.Concat(typeAttribute.Name, " = ", S_SETOFUUIDS.ToUpperString(), " ", S_BRACKET_LEFT));

                        //myEdgeBuilder.Append(String.Concat(typeAttribute.Name, " = ", S_SETOF.ToUpperString(), " ", S_BRACKET_LEFT));

                        #region Create an assignment content - if edge does not contain any elements create an empty one

                        if ((attribute.Value as ASetOfReferencesEdgeType).GetAllReferenceIDs().CountIsGreater(0))
                        {

                            if (attribute.Value is ASetOfReferencesWithInfoEdgeType)
                            {

                                #region Create attribute assignments

                                foreach (var val in (attribute.Value as ASetOfReferencesWithInfoEdgeType).GetAllReferenceIDsWeighted())
                                {
                                    stringBuilder.Append(String.Concat("'", val.Item1.ToString(), "'"));
                                    if (val.Item2 != null)
                                    {
                                        stringBuilder.Append(String.Concat(S_colon, S_BRACKET_LEFT, CreateGraphDMLforADBBaseObject(myDumpFormat, val.Item2), S_BRACKET_RIGHT));
                                    }
                                    stringBuilder.Append(delimiter);
                                }
                                stringBuilder.RemoveSuffix(delimiter);

                                #endregion

                            }
                            else
                            {

                                #region Create an assignment content - if edge does not contain any elements create an empty one

                                if ((attribute.Value as ASetOfReferencesEdgeType).GetAllReferenceIDs().CountIsGreater(0))
                                {

                                    #region Create attribute assignments

                                    foreach (var val in (attribute.Value as ASetOfReferencesEdgeType).GetAllReferenceIDs())
                                    {
                                        stringBuilder.Append(String.Concat("'", val.ToString(), "'"));
                                        stringBuilder.Append(delimiter);
                                    }
                                    stringBuilder.RemoveSuffix(delimiter);

                                    #endregion

                                }

                                #endregion

                            }

                        }

                        #endregion

                        stringBuilder.Append(S_BRACKET_RIGHT);

                        #endregion

                    }

                    #endregion

                    #region SingleReference

                    else if (typeAttribute.KindOfType == KindsOfType.SingleReference)
                    {
                        stringBuilder.Append(String.Concat(typeAttribute.Name, " = ", S_REFUUID.ToUpperString(), " ", S_BRACKET_LEFT));
                        stringBuilder.Append(String.Concat("'", (attribute.Value as ASingleReferenceEdgeType).GetUUID().ToString(), "'"));
                        stringBuilder.Append(S_BRACKET_RIGHT);
                    }

                    #endregion

                    else
                    {
                        return new Exceptional<String>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                    }

                    stringBuilder.Append(delimiter);

                }

                #endregion

                #region NonReference attributes

                else
                {

                    #region ListOfNoneReferences

                    if (typeAttribute.KindOfType == KindsOfType.ListOfNoneReferences)
                    {
                        stringBuilder.Append(String.Concat(typeAttribute.Name, " = ", S_LISTOF.ToUpperString(), " ", S_BRACKET_LEFT));
                        foreach (var val in (attribute.Value as IBaseEdge))
                        {
                            stringBuilder.Append(CreateGraphDMLforADBBaseObject(myDumpFormat, val as ADBBaseObject) + delimiter);
                        }
                        stringBuilder.RemoveSuffix(delimiter);
                        stringBuilder.Append(S_BRACKET_RIGHT);
                    }

                    #endregion

                    #region SetOfNoneReferences

                    else if (typeAttribute.KindOfType == KindsOfType.SetOfNoneReferences)
                    {
                        stringBuilder.Append(String.Concat(typeAttribute.Name, " = ", S_SETOF.ToUpperString(), " ", S_BRACKET_LEFT));
                        foreach (var val in (attribute.Value as IBaseEdge))
                        {
                            stringBuilder.Append(CreateGraphDMLforADBBaseObject(myDumpFormat, val as ADBBaseObject) + delimiter);
                        }
                        stringBuilder.RemoveSuffix(delimiter);
                        stringBuilder.Append(S_BRACKET_RIGHT);

                    }

                    #endregion

                    #region SpecialAttribute

                    else if (typeAttribute.KindOfType == KindsOfType.SpecialAttribute)
                    {
                        throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                    }

                    #endregion

                    #region Single value

                    else
                    {
                        stringBuilder.Append(String.Concat(typeAttribute.Name, " = ", CreateGraphDMLforADBBaseObject(myDumpFormat, attribute.Value as ADBBaseObject)));
                    }

                    #endregion

                    stringBuilder.Append(delimiter);

                }

                #endregion

            }

            return new Exceptional<String>(stringBuilder.ToString());
        }
예제 #12
0
        /// <summary>
        /// Add just the Attribute names
        /// </summary>
        /// <param name="myDumpFormat"></param>
        /// <param name="typeAttribute"></param>
        /// <param name="indent"></param>
        /// <param name="indentWidth"></param>
        /// <returns></returns>
        private String CreateGraphDDLOfAttributeUUIDs(DumpFormats myDumpFormat, IEnumerable<AttributeUUID> myAttributes, GraphDBType myGraphDBType)
        {
            var stringBuilder = new StringBuilder();
            var delimiter = ", ";

            foreach (var _Attribute in myAttributes)
            {
                stringBuilder.Append(myGraphDBType.GetTypeAttributeByUUID(_Attribute).Name);
                stringBuilder.Append(delimiter);
            }

            if (stringBuilder.Length > delimiter.Length)
            {
                stringBuilder.Remove(stringBuilder.Length - delimiter.Length, 2);
            }

            return stringBuilder.ToString();
        }
예제 #13
0
        /// <summary>
        /// Generate an output for an type with the attributes of the types and all parent types
        /// </summary>         
        /// <param name="myGraphDBType">The db type</param>
        /// <param name="myDBContext">The db context</param>
        /// <param name="myDepth">If depth == 0 only the type basic attributes will be returned</param>
        private Vertex GenerateOutput(DBContext myDBContext, GraphDBType myGraphDBType, Int32 myDepth = 0)
        {
            var retVal = new Vertex();

            if (myGraphDBType.ParentTypeUUID != null)

            retVal.AddAttribute("UUID",        myGraphDBType.UUID);
            retVal.AddAttribute("TYPE",        myGraphDBType.GetType().Name);
            retVal.AddAttribute("Name",        myGraphDBType.Name);
            retVal.AddAttribute("Comment",     myGraphDBType.Comment);

            if (myDepth > 0)
            {

                retVal.AddAttribute("Properties", new Edge(retVal, GeneratePropertiesOutput(myGraphDBType, myDBContext,
                    myGraphDBType.Attributes.Where(a => !(a.Value.EdgeType is IReferenceEdge)).Select(kv => kv.Value)))
                {
                    EdgeTypeName = "Property"
                });

                retVal.AddAttribute("Edges", new Edge(retVal, GenerateEdgesOutput(myGraphDBType, myDBContext, myGraphDBType.Attributes.Where(a => (a.Value.EdgeType is IReferenceEdge) && !a.Value.IsBackwardEdge).Select(kv => kv.Value)))
                {
                    EdgeTypeName = "Edge"
                });

                retVal.AddAttribute("BackwardEdges", new Edge(retVal, GenerateEdgesOutput(myGraphDBType, myDBContext, myGraphDBType.Attributes.Where(a => (a.Value.EdgeType is IReferenceEdge) && a.Value.IsBackwardEdge).Select(kv => kv.Value)))
                {
                    EdgeTypeName = "Edge"
                });

                retVal.AddAttribute("UniqueAttributes", new Edge(retVal, GeneratePropertiesOutput(myGraphDBType, myDBContext,
                    myGraphDBType.GetUniqueAttributes().Select(a => myGraphDBType.GetTypeAttributeByUUID(a))))
                {
                    EdgeTypeName = "Unique"
                });

                retVal.AddAttribute("MandatoryAttributes", new Edge(retVal, GeneratePropertiesOutput(myGraphDBType, myDBContext,
                    myGraphDBType.GetMandatoryAttributes().Select(a => myGraphDBType.GetTypeAttributeByUUID(a))))
                {
                    EdgeTypeName = "Mandatory"
                });

                retVal.AddAttribute("Indices", new Edge(retVal, GenerateIndicesOutput(myGraphDBType, myDBContext))
                {
                    EdgeTypeName = "Index"
                });

                if (myGraphDBType.ParentTypeUUID != null)
                {
                    var _ParentType = myDBContext.DBTypeManager.GetTypeByUUID(myGraphDBType.ParentTypeUUID);
                    retVal.AddAttribute("Extends", new Edge(retVal, GenerateOutput(myDBContext, _ParentType, myDepth - 1))
                    {
                        EdgeTypeName = "VertexType"
                    });
                }

            }

            return retVal;
        }