Esempio n. 1
0
        /// <summary>
        /// Initializes the type manager. This method may only be called once, else it throws an TypeInitializationException.
        /// </summary>
        /// <param name="myIGraphFSSession">The myIGraphFS, on which the database is stored.</param>
        /// <param name="myDatabaseLocation">The databases root path in the myIGraphFS.</param>
        public Exceptional Init(IGraphFSSession myIGraphFSSession, ObjectLocation myDatabaseLocation, Boolean myRebuildIndices)
        {
            #region Input validation

            if (myIGraphFSSession == null)
                return new Exceptional<bool>(new Error_ArgumentNullOrEmpty("The parameter myIGraphFS must not be null!"));

            if (myDatabaseLocation == null)
                return new Exceptional<bool>(new Error_ArgumentNullOrEmpty("The parameter myDatabaseLocation must not be null!"));

            //ToDo: Find a better way to check this!
            if (_BasicTypes.ContainsKey(DBBaseObject.UUID))
                return new Exceptional<bool>(new Error_UnknownDBError("The TypeManager had already been initialized!"));

            #endregion

            var objectDirectoryShards = UInt16.Parse(_DBContext.GraphAppSettings.Get<ObjectsDirectoryShardsSetting>());

            #region DBObject - The base of all database types
            // DBObject is a child of DBBaseObject

            var typeDBBaseObject = new GraphDBType(DBBaseObject.UUID, myDatabaseLocation, DBBaseObject.Name, null, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "The base of all database types", DBConstants.ObjectDirectoryShards);
            _SystemTypes.Add(typeDBBaseObject.UUID, typeDBBaseObject);

            #endregion

            #region DBReference - The base of all user defined database types
            // DBObject is a child of DBBaseObject

            // == DBObject!
            var typeDBReference = new GraphDBType(DBReference.UUID, myDatabaseLocation, DBReference.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "The base of all user defined database types", DBConstants.ObjectDirectoryShards);

            #region DBVertex

            var typeDBVertex = new GraphDBType(DBVertex.UUID, myDatabaseLocation, DBVertex.Name, DBReference.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "The base of all user defined database vertices", DBConstants.ObjectDirectoryShards);
            _SystemTypes.Add(typeDBVertex.UUID, typeDBVertex);

            #endregion

            #region UUID special Attribute

            var specialTypeAttribute_UUID = new SpecialTypeAttribute_UUID() { DBTypeUUID = DBReference.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_UUID, this, false);
            _GUIDTypeAttribute = specialTypeAttribute_UUID;

            #endregion

            #region CreationTime special attribute

            var specialTypeAttribute_CrTime = new SpecialTypeAttribute_CREATIONTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_CrTime, this, false);

            #endregion

            #region DeletionTime special attribute

            var specialTypeAttribute_DelTime = new SpecialTypeAttribute_DELETIONTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_DelTime, this, false);

            #endregion

            #region Edition special attribute

            var specialTypeAttribute_Edition = new SpecialTypeAttribute_EDITION() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_Edition, this, false);

            #endregion

            #region Editions special attribute

            var specialTypeAttribute_Editions = new SpecialTypeAttribute_EDITIONS() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_Editions, this, false);

            #endregion

            #region LastAccessTime special attribute

            var specialTypeAttribute_AcTime = new SpecialTypeAttribute_LASTACCESSTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_AcTime, this, false);

            #endregion

            #region LastModificationTime special attribute

            var specialTypeAttribute_LastModTime = new SpecialTypeAttribute_LASTMODIFICATIONTIME() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_LastModTime, this, false);

            #endregion

            #region TypeName special Attribute

            var specialTypeAttribute_TYPE = new SpecialTypeAttribute_TYPE() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_TYPE, this, false);

            #endregion

            #region REVISION special Attribute

            var specialTypeAttribute_REVISION = new SpecialTypeAttribute_REVISION() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_REVISION, this, false);

            #endregion

            #region REVISIONS special Attribute

            var specialTypeAttribute_REVISIONS = new SpecialTypeAttribute_REVISIONS() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_REVISIONS, this, false);

            #endregion

            #region STREAMS special Attribute

            var specialTypeAttribute_STREAMS = new SpecialTypeAttribute_STREAMS() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_STREAMS, this, false);

            #endregion

            #region NUMBER OF REVISIONS Attribute

            var specialTypeAttribute_NUMBEROFREVISIONS = new SpecialTypeAttribute_NUMBEROFREVISIONS() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_NUMBEROFREVISIONS, this, false);

            #endregion

            #region NUMBER OF COPIES

            var specialTypeAttribute_NUMBEROFCOPIES = new SpecialTypeAttribute_NUMBEROFCOPIES() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_NUMBEROFCOPIES, this, false);

            #endregion

            #region PARENT REVISION IDs

            var specialTypeAttribute_PARENTREVISIONIDs = new SpecialTypeAttribute_PARENTREVISIONS() { DBTypeUUID = DBString.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_PARENTREVISIONIDs, this, false);

            #endregion

            #region MAX REVISION AGE

            var specialTypeAttribute_MAXREVISIONAGE = new SpecialTypeAttribute_MAXREVISIONAGE() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_MAXREVISIONAGE, this, false);

            #endregion

            #region MIN NUMBER OF REVISIONS

            var specialTypeAttribute_MINNUMBEROFREVISIONS = new SpecialTypeAttribute_MINNUMBEROFREVISIONS() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_MINNUMBEROFREVISIONS, this, false);

            #endregion

            #region MAX NUMBER OF REVISIONS

            var specialTypeAttribute_MAXNUMBEROFREVISIONS = new SpecialTypeAttribute_MAXNUMBEROFREVISIONS() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_MAXNUMBEROFREVISIONS, this, false);

            #endregion

            #region MAX NUMBER OF COPIES

            var specialTypeAttribute_MAXNUMBEROFCOPIES = new SpecialTypeAttribute_MAXNUMBEROFCOPIES() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_MAXNUMBEROFCOPIES, this, false);

            #endregion

            #region MIN NUMBER OF COPIES

            var specialTypeAttribute_MINNUMBEROFCOPIES = new SpecialTypeAttribute_MINNUMBEROFCOPIES() { DBTypeUUID = DBUInt64.UUID, RelatedGraphDBTypeUUID = typeDBReference.UUID, KindOfType = KindsOfType.SpecialAttribute };
            typeDBReference.AddAttribute(specialTypeAttribute_MINNUMBEROFCOPIES, this, false);

            #endregion

            foreach (var attr in typeDBReference.Attributes)
            {
                typeDBVertex.AddAttribute(attr.Value, this, false);
            }

            _SystemTypes.Add(typeDBReference.UUID, typeDBReference);

            #endregion

            #region DBEdge

            var typeDBEdge = new GraphDBType(new TypeUUID(DBConstants.DBEdgeID), myDatabaseLocation, DBConstants.DBEdgeName, DBReference.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "The base of all user defined database edges", DBConstants.ObjectDirectoryShards);

            _SystemTypes.Add(typeDBEdge.UUID, typeDBEdge);

            #endregion

            #region Build-in basic database types
            // These are children of DBBaseObject

            _BasicTypes.Add(DBBoolean.UUID, new GraphDBType(DBBoolean.UUID, new ObjectLocation(myDatabaseLocation), DBBoolean.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));
            _BasicTypes.Add(DBDateTime.UUID, new GraphDBType(DBDateTime.UUID, new ObjectLocation(myDatabaseLocation), DBDateTime.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));
            _BasicTypes.Add(DBDouble.UUID, new GraphDBType(DBDouble.UUID, new ObjectLocation(myDatabaseLocation), DBDouble.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));
            _BasicTypes.Add(DBInt64.UUID, new GraphDBType(DBInt64.UUID, new ObjectLocation(myDatabaseLocation), DBInt64.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));
            _BasicTypes.Add(DBInt32.UUID, new GraphDBType(DBInt32.UUID, new ObjectLocation(myDatabaseLocation), DBInt32.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));
            _BasicTypes.Add(DBUInt64.UUID, new GraphDBType(DBUInt64.UUID, new ObjectLocation(myDatabaseLocation), DBUInt64.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));
            _BasicTypes.Add(DBString.UUID, new GraphDBType(DBString.UUID, new ObjectLocation(myDatabaseLocation), DBString.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));

            _BasicTypes.Add(DBBackwardEdgeType.UUID, new GraphDBType(DBBackwardEdgeType.UUID, new ObjectLocation(myDatabaseLocation), DBBackwardEdgeType.Name, DBBaseObject.UUID, new Dictionary<AttributeUUID, TypeAttribute>(), false, false, "", DBConstants.ObjectDirectoryShards));

            #endregion

            foreach (var _GraphDBType in _SystemTypes.Values)
                _TypesNameLookUpTable.Add(_GraphDBType.Name, _GraphDBType);

            foreach (var _GraphDBType in _BasicTypes.Values)
                _TypesNameLookUpTable.Add(_GraphDBType.Name, _GraphDBType);

            return LoadUserDefinedDatabaseTypes(myRebuildIndices);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a readout based on the passed <paramref name="attributes"/>, <paramref name="undefinedAttributes"/>, <paramref name="specialTypeAttributes"/> which are all optional
        /// </summary>
        /// <param name="myDBObjectStreamExceptional"></param>
        /// <param name="attributes"></param>
        /// <param name="undefinedAttributes"></param>
        /// <param name="specialTypeAttributes"></param>
        /// <returns></returns>
        private Exceptional<Vertex> GetManipulationResultSet(DBContext myDBContext, Exceptional<DBObjectStream> myDBObjectStreamExceptional, GraphDBType myGraphDBType, Dictionary<TypeAndAttributeDefinition, IObject> attributes = null, Dictionary<String, IObject> undefinedAttributes = null, Dictionary<ASpecialTypeAttribute, Object> specialTypeAttributes = null)
        {
            Vertex _Vertex = null;

            #region Return inserted attributes

            #region attributes

            if (!attributes.IsNullOrEmpty())
            {
                _Vertex = new Vertex(attributes.ToDictionary(key => key.Key.Definition.Name, value => value.Value.GetReadoutValue()));
            }
            else
            {
                _Vertex = new Vertex();
            }

            #endregion

            #region UndefinedAttributes

            if (!undefinedAttributes.IsNullOrEmpty())
            {

                foreach (var undefAttr in undefinedAttributes)
                {
                    _Vertex.AddAttribute(undefAttr.Key, undefAttr.Value.GetReadoutValue());
                }

            }

            #endregion

            #region SpecialTypeAttributes

            if (!specialTypeAttributes.IsNullOrEmpty())
            {

                foreach (var specAttr in specialTypeAttributes)
                {
                    _Vertex.AddAttribute(specAttr.Key.Name, specAttr.Value);
                }

            }

            #endregion

            #region UUID

            if (!_Vertex.HasAttribute(SpecialTypeAttribute_UUID.AttributeName))
            {

                var extractedValue = new SpecialTypeAttribute_UUID().ExtractValue(myDBObjectStreamExceptional.Value, myGraphDBType, myDBContext);

                if (extractedValue.Failed())
                {
                    return new Exceptional<Vertex>(extractedValue);
                }

                _Vertex.AddAttribute(SpecialTypeAttribute_UUID.AttributeName, extractedValue.Value.GetReadoutValue());

            }

            #endregion

            #region REVISION

            if (!_Vertex.HasAttribute(SpecialTypeAttribute_REVISION.AttributeName)) // If it was updated by SpecialTypeAttributes we do not need to add them again
            {

                var extractedValue = new SpecialTypeAttribute_REVISION().ExtractValue(myDBObjectStreamExceptional.Value, myGraphDBType, myDBContext);
                if (extractedValue.Failed())
                {
                    return new Exceptional<Vertex>(extractedValue);
                }
                _Vertex.AddAttribute(SpecialTypeAttribute_REVISION.AttributeName, extractedValue.Value.GetReadoutValue());

            }

            #endregion

            #endregion

            return new Exceptional<Vertex>(_Vertex);
        }