Beispiel #1
0
 /// <summary>
 /// This will be invoked by the BulkInsert class.
 /// </summary>
 /// <param name="myTypeManager"></param>
 /// <param name="myDBTypeStream"></param>
 /// <param name="myDBObjectStream"></param>
 /// <param name="myBulkInsert"></param>
 internal BulkInsertDBO(DBContext myDBContext, GraphDBType myDBTypeStream, DBObjectStream myDBObjectStream, BulkInsert myBulkInsert)
 {
     _DBContext = myDBContext;
     _DBTypeStream = myDBTypeStream;
     _DBObjectStream = myDBObjectStream;
     _BulkInsert = myBulkInsert;
 }
 public Warning_EdgeToNonExistingNode(DBObjectStream myStartingNode, GraphDBType myTypeOfDBO, TypeAttribute myEdge, IEnumerable<IError> myErrors)
 {
     StartingNode = myStartingNode;
     Errors = myErrors;
     Edge = myEdge;
     TypeOfDBO = myTypeOfDBO;
 }
        /// <summary>
        /// <seealso cref=" AAttributeAssignOrUpdate"/>
        /// </summary>
        public override Exceptional<IObject> GetValueForAttribute(DBObjectStream myDBObject, DBContext myDBContext, GraphDBType myGraphDBType)
        {
            if (AttributeIDChain.IsUndefinedAttribute)
            {
                return new Exceptional<IObject>(GraphDBTypeMapper.GetBaseObjectFromCSharpType(Value));
            }

            #region Simple value

            var dbType = AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager);
            if (AttributeIDChain.LastAttribute is SpecialTypeAttribute_UUID)
            {
                dbType = myDBContext.DBTypeManager.GetTypeByName(GraphDBTypeMapper.GetBaseObjectFromCSharpType(Value).ObjectName);//DBString.Name);
            }
            if (GraphDBTypeMapper.IsAValidAttributeType(dbType, AttributeAssignType, myDBContext, Value))
            {
                return new Exceptional<IObject>(GraphDBTypeMapper.GetGraphObjectFromType(AttributeAssignType, Value)); ;
            }
            else
            {
                return new Exceptional<IObject>(new Error_InvalidAttributeValue(AttributeIDChain.LastAttribute.Name, Value));
            }

            #endregion
        }
        protected Exceptional<IDictionary<String, IObject>> LoadUndefAttributes(String myName, DBContext dbContext, DBObjectStream myObjStream)
        {
            var loadExcept = myObjStream.GetUndefinedAttributePayload(dbContext.DBObjectManager);

            if (loadExcept.Failed())
                return new Exceptional<IDictionary<string, IObject>>(loadExcept);

            return new Exceptional<IDictionary<string, IObject>>(loadExcept.Value);
        }
        public override Exceptional<IObject> ExtractValue(DBObjectStream dbObjectStream, GraphDBType graphDBType, DBContext dbContext)
        {
            EdgeTypeListOfBaseObjects parentRevisions = new EdgeTypeListOfBaseObjects();

            foreach (var item in dbObjectStream.ParentRevisionIDs)
                parentRevisions.Add(new DBString(item.ToString()));

            return new Exceptional<IObject>(parentRevisions);
        }
        public override Exceptional<IObject> ExtractValue(DBObjectStream dbObjectStream, GraphDBType graphDBType, DBContext dbContext)
        {
            EdgeTypeListOfBaseObjects streams = new EdgeTypeListOfBaseObjects();

            foreach (var item in dbObjectStream.ObjectStreams)
                streams.Add(new DBString(item.Key + " " + item.Value.ToString()));

            return new Exceptional<IObject>(streams);
        }
Beispiel #7
0
        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));
            }
        }
 public override Exceptional<IObject> ExtractValue(DBObjectStream dbObjectStream, GraphDBType graphDBType, DBContext dbContext)
 {
     var myType = dbContext.DBTypeManager.GetTypeByUUID(dbObjectStream.TypeUUID);
     if (myType != null)
     {
         return new Exceptional<IObject>(new DBString(myType.Name));
     }
     else
     {
         return new Exceptional<IObject>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
     }
 }
        public override Exceptional<IObject> GetValueForAttribute(DBObjectStream aDBObject, DBContext dbContext, GraphDBType _Type)
        {
            #region ListOfDBObjects

            if (AttributeIDChain.LastAttribute.GetDBType(dbContext.DBTypeManager).IsUserDefined)
            {
                //userdefined
                //value = aSetNode.GetCorrespondigDBObjectUUIDs(aTaskNode.AttributeIDNodee, typeManager, dbObjectCache, mySessionToken);

                if (CollectionDefinition.CollectionType == CollectionType.SetOfUUIDs)
                {
                    var retVal = CollectionDefinition.TupleDefinition.GetAsUUIDEdge(dbContext, AttributeIDChain.LastAttribute);
                    if (!retVal.Success())
                    {
                        return new Exceptional<IObject>(retVal);
                    }
                    else
                    {
                        return new Exceptional<IObject>(retVal.Value);
                    }
                }
                else
                {
                    var edge = (IEdgeType)(CollectionDefinition.TupleDefinition.GetCorrespondigDBObjectUUIDAsList(_Type, dbContext, AttributeIDChain.LastAttribute.EdgeType.GetNewInstance(), AttributeIDChain.LastAttribute.GetDBType(dbContext.DBTypeManager)).Value);
                    return new Exceptional<IObject>(edge);
                }
            }
            else
            {
                //not userdefined

                var edge = GetBasicList(dbContext);
                if (edge.Failed())
                {
                    return new Exceptional<IObject>(edge);
                }

                // If the collection was declared as a SETOF insert
                if (CollectionDefinition.CollectionType == CollectionType.Set)
                {
                    edge.Value.Distinction();
                }

                return new Exceptional<IObject>(edge.Value);
            }

            #endregion
        }
        public override Exceptional<IObject> GetValueForAttribute(DBObjectStream aDBObject, DBContext dbContext, GraphDBType _Type)
        {
            #region Expression

            var validateResult = BinaryExpressionDefinition.Validate(dbContext, _Type);
            if (validateResult.Failed())
            {
                return new Exceptional<IObject>(validateResult);
            }

            var value = BinaryExpressionDefinition.SimpleExecution(aDBObject, dbContext);

            #endregion

            return new Exceptional<IObject>(value);
        }
        public Exceptional<Tuple<String, TypeAttribute, IListOrSetEdgeType>> ApplyUpdateListAttribute(AAttributeAssignOrUpdateOrRemove myAttributeUpdateOrAssign, DBContext dbContext, DBObjectStream aDBObject, GraphDBType _Type)
        {
            if (myAttributeUpdateOrAssign is AttributeAssignOrUpdateList)
            {

            }
            else if (myAttributeUpdateOrAssign is AttributeRemoveList)
            {

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

            return new Exceptional<Tuple<String, TypeAttribute, IListOrSetEdgeType>>(null as Tuple<String, TypeAttribute, IListOrSetEdgeType>);
        }
        public override Exceptional<IObject> GetValueForAttribute(DBObjectStream myDBObject, DBContext myDBContext, GraphDBType myGraphDBType)
        {
            if (AttributeIDChain.IsUndefinedAttribute)
            {
                return new Exceptional<IObject>(GraphDBTypeMapper.GetBaseObjectFromCSharpType(Value));
            }

            #region Simple value

            if (GraphDBTypeMapper.IsAValidAttributeType(AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager), AttributeAssignType, myDBContext, Value))
            {
                return new Exceptional<IObject>(GraphDBTypeMapper.GetGraphObjectFromType(AttributeAssignType, Value)); ;
            }
            else
            {
                return new Exceptional<IObject>(new Error_InvalidAttributeValue(AttributeIDChain.LastAttribute.Name, Value));
            }

            #endregion
        }
        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 undefined attributes

            //TODO: change this to a more handling thing than KeyValuePair
            var addExcept = myDBContext.DBObjectManager.AddUndefinedAttribute(UndefinedAttribute.AttributeName, UndefinedAttribute.AttributeValue, myDBObjectStream);

            if (addExcept.Failed())
            {
                return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(addExcept);
            }

            //sthChanged = true;

            attrsForResult.Add(UndefinedAttribute.AttributeName, new Tuple<TypeAttribute, IObject>(new UndefinedTypeAttribute(UndefinedAttribute.AttributeName), UndefinedAttribute.AttributeValue));

            #endregion

            return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult);
        }
        /// <summary>
        /// <seealso cref=" AAttributeAssignOrUpdateOrRemove"/>
        /// </summary>
        public override Exceptional<IObject> GetValueForAttribute(DBObjectStream myDBObject, DBContext myDBContext, GraphDBType myDBType)
        {
            #region reference

            var validationResult = AttributeIDChain.Validate(myDBContext, true, myDBType);
            if (validationResult.Failed())
            {
                return new Exceptional<IObject>(validationResult);
            }

            if (AttributeIDChain.IsUndefinedAttribute)
            {
                return new Exceptional<IObject>(new Error_InvalidReferenceAssignmentOfUndefAttr());
            }

            // if we have a Userdefined Type, than all assignments will work on this type
            if (!AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined)
            {
                //attributeType = _Type;
            }

            var value = AttributeIDChain.LastAttribute.EdgeType.GetNewInstance();

            var dbos = SetRefDefinition.GetCorrespondigDBObjects(AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager), myDBContext, AttributeIDChain.LastAttribute.GetRelatedType(myDBContext.DBTypeManager));

            foreach (var dbo in dbos)
            {
                if (dbo.Failed())
                    return new Exceptional<IObject>(dbo);

                (value as ASingleReferenceEdgeType).Set(dbo.Value.ObjectUUID, AttributeIDChain.LastAttribute.DBTypeUUID, SetRefDefinition.Parameters);
            }

            #endregion

            return new Exceptional<IObject>(value);
        }
Beispiel #15
0
 public Exceptional<Boolean> RemoveUndefinedAttribute(String myName, DBObjectStream myObject)
 {
     return myObject.RemoveUndefinedAttribute(myName, this);
 }
Beispiel #16
0
        /// <summary>
        /// Removes a DBObject.
        /// </summary>
        /// <param name="myGraphType">The Type of the DBObject that is to be removed.</param>
        /// <param name="myDBObject">The UUID of the DBObject.</param>
        public Exceptional RemoveDBObject(GraphDBType myTypeOfDBObject, DBObjectStream myDBObject, DBObjectCache myDBObjectCache, SessionSettings myToken)
        {
            #region Input exceptions

            if (myTypeOfDBObject == null)
            {
                return new Exceptional(new Error_ArgumentNullOrEmpty("myTypeOfDBObject"));
            }
            if (myDBObject == null)
            {
                return new Exceptional(new Error_ArgumentNullOrEmpty("myUUID"));
            }

            #endregion

            #region Data

            ObjectLocation myDBObjectLocation;

            #endregion

            // Get DBObject path
            myDBObjectLocation = myDBObject.ObjectLocation;

            #region remove from attributeIDX

            foreach (var anIndex in myTypeOfDBObject.GetAllAttributeIndices(false))
            {
                anIndex.Remove(myDBObject, myTypeOfDBObject, _DBContext);
            }

            #endregion

            #region remove from fs

            #region Remove DBOBJECTSTREAM

            var _RemoveObjectExceptional = _IGraphFSSession.RemoveObjectIfExists(myDBObjectLocation, DBConstants.DBOBJECTSTREAM);
            if (_RemoveObjectExceptional.Failed())
            {
                return _RemoveObjectExceptional;
            }

            #endregion

            #region Remove DBBACKWARDEDGESTREAM

            _RemoveObjectExceptional = _IGraphFSSession.RemoveObjectIfExists(myDBObjectLocation, DBConstants.DBBACKWARDEDGESTREAM);
            if (_RemoveObjectExceptional.Failed())
            {
                return _RemoveObjectExceptional;
            }

            #endregion

            #region Remove UNDEFATTRIBUTESSTREAM

            _RemoveObjectExceptional = _IGraphFSSession.RemoveObjectIfExists(myDBObjectLocation, DBConstants.UNDEFATTRIBUTESSTREAM);
            if (_RemoveObjectExceptional.Failed())
            {
                return _RemoveObjectExceptional;
            }

            #endregion

            #endregion

            return Exceptional.OK;
        }
Beispiel #17
0
        /// <summary>
        /// Flushes a DBObject to FS.
        /// </summary>
        /// <param name="myDBObject">The DBObject to be flushed.</param>
        /// <returns>True for success or otherwise false.</returns>
        public Exceptional FlushDBObject(DBObjectStream myDBObject)
        {
            #region Input validation

            if (myDBObject == null)
                return new Exceptional(new Error_ArgumentNullOrEmpty("myDBObject"));

            #endregion

            if (myDBObject.IGraphFSSessionReference == null)
                return _IGraphFSSession.StoreFSObject(myDBObject, true);

            return myDBObject.Save();
        }
 public override Exceptional<IObject> ExtractValue(DBObjectStream dbObjectStream, GraphDBType graphDBType, DBContext dbContext)
 {
     return new Exceptional<IObject>(new DBUInt64(dbObjectStream.MinNumberOfRevisions));
 }
Beispiel #19
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;
        }
Beispiel #20
0
        /// <summary>
        /// This method updates the idx corresponding to an DBObject
        /// </summary>
        /// <param name="myDBObject">The DBObject that should be updated</param>
        /// <param name="myTypeOfDBObject">The type of the DBObject</param>
        /// <param name="myToken">The SessionInfos</param>
        public override Exceptional Update(DBObjectStream myDBObject, GraphDBType myTypeOfDBObject, DBContext dbContext)
        {
            #region Get index reference

            var idxRef = GetIndexReference(dbContext.DBIndexManager);
            if (!idxRef.Success())
            {
                return new Exceptional(idxRef);
            }
            var idxRefVal = idxRef.Value;

            #endregion

            if (idxRefVal != null)
            {

                #region remove

                HashSet<IndexKey> toBeRemovedIdxKeys = new HashSet<IndexKey>();

                foreach (var aKeyValue in idxRefVal.GetIDictionary())
                {
                    aKeyValue.Value.Remove(myDBObject.ObjectUUID);
                    if (aKeyValue.Value.Count == 0)
                    {
                        toBeRemovedIdxKeys.Add(aKeyValue.Key);
                    }
                }

                foreach (var aToBeDeletedIndexKey in toBeRemovedIdxKeys)
                {
                    idxRefVal.Remove(aToBeDeletedIndexKey);
                }

                #endregion

                #region insert

                if (myDBObject.HasAtLeastOneAttribute(this.IndexKeyDefinition.IndexKeyAttributeUUIDs, myTypeOfDBObject, dbContext.SessionSettings))
                {
                    //insert
                    foreach (var aIndexKey in this.GetIndexkeysFromDBObject(myDBObject, myTypeOfDBObject, dbContext))
                    {
                        idxRefVal.Set(aIndexKey, myDBObject.ObjectUUID, IndexSetStrategy.MERGE);
                    }
                }

                #endregion

            }
            else
            {
                return new Exceptional(new Error_InvalidIndexReference(IndexName, IndexEdition));
            }

            return Exceptional.OK;
        }
Beispiel #21
0
        /// <summary>
        /// This method inserts the given DBObject into the index
        /// </summary>
        /// <param name="myDBObject">The DBObject that should be inserted</param>
        /// <param name="myIndexSetStrategy">The index merge strategy</param>
        /// <param name="myTypeOfDBObject">The type of the DBObject</param>
        /// <param name="myToken">The SessionInfos</param>
        public override Exceptional Insert(DBObjectStream myDBObject, IndexSetStrategy myIndexSetStrategy, GraphDBType myTypeOfDBObject, DBContext dbContext)
        {
            #region Get index reference

            var idxRef = GetIndexReference(dbContext.DBIndexManager);
            if (!idxRef.Success())
            {
                return new Exceptional(idxRef);
            }
            var idxRefVal = idxRef.Value;

            #endregion

            if (idxRefVal != null)
            {
                foreach (var aIndexKex in GetIndexkeysFromDBObject(myDBObject, myTypeOfDBObject, dbContext))
                {

                    #region Check for uniqueness - TODO: remove me as soon as we have a unique indexObject implementation

                    if (IsUniqueAttributeIndex)
                    {
                        if (idxRefVal.ContainsKey(aIndexKex))
                        {
                            return new Exceptional(new Error_UniqueConstrainViolation(myTypeOfDBObject.Name, IndexName));
                        }
                    }

                    #endregion

                    idxRefVal.Set(aIndexKex, myDBObject.ObjectUUID, myIndexSetStrategy);
                }
            }
            else
            {
                return new Exceptional(new Error_InvalidIndexReference(IndexName, IndexEdition));
            }

            return Exceptional.OK;
        }
 public override Exceptional<Object> ApplyTo(DBObjectStream myNewDBObject, object myValue, params object[] myOptionalParameters)
 {
     return new Exceptional<Object>(new Error_NotImplemented(new StackTrace(true)));
 }
Beispiel #23
0
 public Exceptional<Boolean> AddUndefinedAttribute(String myName, IObject myValue, DBObjectStream myObject)
 {
     return myObject.AddUndefinedAttribute(myName, myValue, this);
 }
Beispiel #24
0
 public Exceptional<Boolean> AddBackwardEdge(DBObjectStream aDBObject, TypeUUID uUIDofType, AttributeUUID uUIDofAttribute, ObjectUUID reference)
 {
     return aDBObject.AddBackwardEdge(uUIDofType, uUIDofAttribute, reference, _DBContext.DBObjectManager);
 }
Beispiel #25
0
        private Exceptional<Trinary> ObjectExistsOnFS(DBObjectStream NewDBObject)
        {
            var objectExistException = _IGraphFSSession.ObjectStreamExists(NewDBObject.ObjectLocation, DBConstants.DBOBJECTSTREAM);

            if (objectExistException.Failed())
                return new Exceptional<Trinary>(objectExistException);

            return new Exceptional<Trinary>(objectExistException.Value);
        }
Beispiel #26
0
        /// <summary>
        /// This method removes a given DBObject from the index
        /// </summary>
        /// <param name="myDBObject">The DBObject that should be removed</param>
        /// <param name="myTypeOfDBObjects">The type of the DBObject</param>
        /// <param name="myToken">The SessionInfos</param>
        public override Exceptional Remove(DBObjectStream myDBObject, GraphDBType myTypeOfDBObjects, DBContext dbContext)
        {
            #region Get index reference

            var idxRef = GetIndexReference(dbContext.DBIndexManager);
            if (!idxRef.Success())
            {
                return new Exceptional(idxRef);
            }
            var idxRefVal = idxRef.Value;

            #endregion
            if (idxRefVal != null)
            {
                foreach (var aIndexKex in GetIndexkeysFromDBObject(myDBObject, myTypeOfDBObjects, dbContext))
                {
                    idxRefVal.Remove(aIndexKex, myDBObject.ObjectUUID);
                }
            }
            else
            {
                return new Exceptional(new Error_InvalidIndexReference(IndexName, IndexEdition));
            }

            return Exceptional.OK;
        }
Beispiel #27
0
        /// <summary>
        /// Creates a new DBObject of a given GraphType inserts its UUID into all indices of the given GraphType.
        /// </summary>
        /// <param name="myGraphDBType">The GraphType of the DBObject to create</param>
        /// <param name="myDBObjectAttributes">A dictionary of attributes for the new DBObject</param>
        /// <param name="mySpecialTypeAttributes">Special values which should be set to a object</param>
        /// <param name="myCheckUniqueness">check for unique constraints</param> 
        /// <returns>The UUID of the new DBObject</returns>
        public Exceptional<DBObjectStream> CreateNewDBObjectStream(GraphDBType myGraphDBType, Dictionary<AttributeUUID, IObject> myDBObjectAttributes, Dictionary<String, IObject> myUndefAttributes, Dictionary<ASpecialTypeAttribute, Object> mySpecialTypeAttributes, SessionSettings mySessionSettings, Boolean myCheckUniqueness)
        {
            #region Input validation

            if (myGraphDBType == null)
                return new Exceptional<DBObjectStream>(new Error_ArgumentNullOrEmpty("The parameter myGraphType must not be null!"));

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

            #endregion

            #region Check uniqueness

            if (myCheckUniqueness)
            {

                var parentTypes = _DBContext.DBTypeManager.GetAllParentTypes(myGraphDBType, true, false);
                var CheckVal = _DBContext.DBIndexManager.CheckUniqueConstraint(myGraphDBType, parentTypes, myDBObjectAttributes);

                if (CheckVal.Failed())
                    return new Exceptional<DBObjectStream>(CheckVal);

            }

            #endregion

            #region Create a new DBObjectStream

            DBObjectStream        _NewDBObjectStream               = null;
            ObjectUUID            _NewObjectUUID                   = null;
            ASpecialTypeAttribute _SpecialTypeAttribute_UUID_Key   = new SpecialTypeAttribute_UUID();
            Object                _SpecialTypeAttribute_UUID_Value = null;

            #region Search for an user-defined ObjectUUID

            if (mySpecialTypeAttributes != null)
            {
                if (mySpecialTypeAttributes.TryGetValue(_SpecialTypeAttribute_UUID_Key, out _SpecialTypeAttribute_UUID_Value))
                {

                    // User-defined ObjectUUID of type UInt64
                    var _ValueAsUInt64 = _SpecialTypeAttribute_UUID_Value as UInt64?;
                    if (_ValueAsUInt64 != null)
                        _NewObjectUUID = new ObjectUUID(_ValueAsUInt64.Value);

                    // User-defined ObjectUUID of type String or anything else...
                    else
                    {

                        var _String = _SpecialTypeAttribute_UUID_Value.ToString();
                        if (_String == null || _String == "")
                            return new Exceptional<DBObjectStream>(new Error_InvalidAttributeValue(SpecialTypeAttribute_UUID.AttributeName, _String));

                        _NewObjectUUID = new ObjectUUID(_SpecialTypeAttribute_UUID_Value.ToString());

                    }

                    mySpecialTypeAttributes[_SpecialTypeAttribute_UUID_Key] = _NewObjectUUID;

                }
            }

            #endregion

            // If _NewObjectUUID == null a new one will be generated!
            _NewDBObjectStream                = new DBObjectStream(_NewObjectUUID, myGraphDBType, myDBObjectAttributes);
            _NewDBObjectStream.ObjectLocation = new ObjectLocation(_NewDBObjectStream.ObjectPath, _NewDBObjectStream.ObjectUUID.ToString());

            #endregion

            #region Check for duplicate ObjectUUIDs... maybe resolve duplicates!

            var _DBObjectStreamAlreadyExistsResult = ObjectExistsOnFS(_NewDBObjectStream);

            if (_DBObjectStreamAlreadyExistsResult.Failed())
                return new Exceptional<DBObjectStream>(_DBObjectStreamAlreadyExistsResult);

            while (_DBObjectStreamAlreadyExistsResult.Value == Trinary.TRUE)
            {

                if (_NewObjectUUID != null)
                    return new Exceptional<DBObjectStream>(new Error_DBObjectCollision(_NewDBObjectStream));

                _NewDBObjectStream                = new DBObjectStream(ObjectUUID.NewUUID, myGraphDBType, myDBObjectAttributes);
                _NewDBObjectStream.ObjectLocation = new ObjectLocation(_NewDBObjectStream.ObjectPath, _NewDBObjectStream.ObjectUUID.ToString());

                _DBObjectStreamAlreadyExistsResult = ObjectExistsOnFS(_NewDBObjectStream);

                if (_DBObjectStreamAlreadyExistsResult.Failed())
                    return new Exceptional<DBObjectStream>(_DBObjectStreamAlreadyExistsResult);

            }

            #endregion

            #region Check for ExtractSetting attributes unlike UUID

            if (mySpecialTypeAttributes != null && mySpecialTypeAttributes.Any())
            {
                foreach (var _SpecialAttribute in mySpecialTypeAttributes)
                {
                    // Skip SpecialTypeAttribute_UUID!
                    if (!(_SpecialAttribute.Key is SpecialTypeAttribute_UUID))
                    {
                        var result = _SpecialAttribute.Key.ApplyTo(_NewDBObjectStream, _SpecialAttribute.Value);
                        if (result.Failed())
                        {
                            return new Exceptional<DBObjectStream>(result);
                        }
                    }
                }
            }

            #endregion

            // Flush new DBObject
            var flushResult = FlushDBObject(_NewDBObjectStream);

            if (flushResult.Failed())
                return new Exceptional<DBObjectStream>(flushResult);

            #region Check for existing object - might be removed at some time

            //var exists = ObjectExistsOnFS(_NewDBObjectStream);

            //if (exists.Failed())
            //    return new Exceptional<DBObjectStream>(exists);

            //if (exists.Value != Trinary.TRUE)
            //{
            //    return new Exceptional<DBObjectStream>(new Error_UnknownDBError("DBObject with path " + _NewDBObjectStream.ObjectLocation + " does not exist."));
            //}

            #endregion

            #region Add UUID of the new DBObject to all indices of myGraphType

            foreach (var _GraphDBType in _DBContext.DBTypeManager.GetAllParentTypes(myGraphDBType, true, false))
            {
                foreach (var _AAttributeIndex in _GraphDBType.GetAllAttributeIndices(false))
                {
                    //Find out if the dbobject carries all necessary attributes
                    if (_NewDBObjectStream.HasAtLeastOneAttribute(_AAttributeIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs, _GraphDBType, mySessionSettings))
                    {
                        //valid dbo for idx
                        _AAttributeIndex.Insert(_NewDBObjectStream, _GraphDBType, _DBContext);
                    }
                }
            }

            #endregion

            #region add undefined attributes to the object

            if (!myUndefAttributes.IsNullOrEmpty())
            {
                foreach (var item in myUndefAttributes)
                {
                    var addExcept = _NewDBObjectStream.AddUndefinedAttribute(item.Key, item.Value, this);

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

            #endregion

            return new Exceptional<DBObjectStream>(_NewDBObjectStream);
        }
Beispiel #28
0
        /// <summary>
        /// This method checks if the current attribute index contains a DBObject
        /// </summary>
        /// <param name="myDBObject">The DBObject that should be checked</param>
        /// <param name="myTypeOfDBObject">The Type of the DBObject</param>
        /// <param name="myToken">The SessionInfos</param>
        /// <returns>A Trinary</returns>
        public override Boolean Contains(DBObjectStream myDBObject, GraphDBType myTypeOfDBObject, DBContext dbContext)
        {
            #region Get index reference

            var idxRef = GetIndexReference(dbContext.DBIndexManager);
            if (idxRef.Failed())
            {
                throw new GraphDBException(new Error_CouldNotGetIndexReference(idxRef.IErrors, IndexName, IndexEdition));
            }
            var idxRefVal = idxRef.Value;

            #endregion

            if (idxRefVal != null)
            {
                foreach (var aIndexKex in GetIndexkeysFromDBObject(myDBObject, myTypeOfDBObject, dbContext))
                {
                    if (idxRefVal.Contains(aIndexKex, myDBObject.ObjectUUID))
                    {
                        return true;
                    }
                }

                return false;
            }
            else
            {
                throw new GraphDBException(new Error_InvalidIndexReference(IndexName, IndexEdition));
            }
        }
 public override Exceptional<IObject> ExtractValue(DBObjectStream myDBObjectStream, GraphDBType myGraphDBType, DBContext myDBContext)
 {
     return new Exceptional<IObject>(new DBObjectRevisionID(myDBObjectStream.ObjectRevisionID));
 }
Beispiel #30
0
 /// <summary>
 /// This method inserts the given DBObject into the index
 /// </summary>
 /// <param name="myDBObject">The DBObject that should be inserted</param>
 /// <param name="myTypeOfDBobject">The type of the DBObject</param>
 /// <param name="myToken">The SessionInfos</param>
 public override Exceptional Insert(DBObjectStream myDBObject, GraphDBType myTypeOfDBobject, DBContext dbContext)
 {
     return Insert(myDBObject, IndexSetStrategy.MERGE, myTypeOfDBobject, dbContext);
 }