Example #1
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;
        }
Example #2
0
        private void SetIndexKeyAndValue(IVersionedIndexObject<IndexKey, ObjectUUID> currentIdxShardValue, IndexKey aIndexKex, ObjectUUID objectUUID, IndexSetStrategy myIndexSetStrategy)
        {
            UInt64 previousKeyCount = currentIdxShardValue.KeyCount();

            currentIdxShardValue.Set(aIndexKex, objectUUID, myIndexSetStrategy);

            UInt64 afterKeyCount = currentIdxShardValue.KeyCount();

            if (afterKeyCount > previousKeyCount)
            {
                //so there is one more key...
                IncreaseKeyCount();
            }

            IncreaseValueCount(1UL);
        }
Example #3
0
 public abstract Exceptional Insert(DBObjectStream myDBObject, IndexSetStrategy myIndexSetStrategy, GraphDBType myTypeOfDBObject, DBContext dbContext);
Example #4
0
        public Exceptional<ResultType> RebuildIndex(String myIndexName, String myIndexEdition, GraphDBType myDBTypeStream, IndexSetStrategy myIndexSetStrategy)
        {
            var objectLocation = new ObjectLocation(myDBTypeStream.ObjectLocation, DBConstants.DBObjectsLocation);
            IEnumerable<String> allDBOLocations = null;

            try
            {
                allDBOLocations = _DBContext.DBObjectManager.GetAllStreamsRecursive(objectLocation, DBConstants.DBOBJECTSTREAM);
            }
            catch (Exception e)
            {
                return new Exceptional<ResultType>(new Error_RebuildIndexFailed(myIndexName, myIndexEdition, e.Message));

            }

            try
            {

                var index = myDBTypeStream.GetAttributeIndex(myIndexName, myIndexEdition);

                index.ClearAndRemoveFromDisc(this);

                    foreach (var loc in allDBOLocations)
                    {
                        var dbo = _DBContext.DBObjectManager.LoadDBObject(new ObjectLocation(myDBTypeStream.ObjectLocation, DBConstants.DBObjectsLocation, _DBContext.DBObjectManager.GetDBObjectStreamShard(myDBTypeStream, new ObjectUUID(loc)), loc));

                        if (dbo.Failed())
                        {
                            return new Exceptional<ResultType>(dbo);
                        }

                        if (!dbo.Value.ObjectLocation.Contains(loc))
                        {
                            //NLOG: temporarily commented
                            ////_Logger.Error("Could not found the correct DBObject for Location " + loc + " the ObjectUUID is now " + dbo.Value.ObjectUUID.ToString());
                        }
                        else
                        {
                            if (dbo.Value.HasAtLeastOneAttribute(index.IndexKeyDefinition.IndexKeyAttributeUUIDs, myDBTypeStream, null))
                            {
                                var insertResult = index.Insert(dbo.Value, myIndexSetStrategy, myDBTypeStream, _DBContext);
                                if (!insertResult.Success())
                                {
                                    return new Exceptional<ResultType>(insertResult);
                                }
                            }
                        }

                }
            }
            catch (GraphDBException pe)
            {
                var _Exceptional = new Exceptional<ResultType>();
                foreach (var _ex in pe.GraphDBErrors)
                    _Exceptional.PushIError(_ex);
                return _Exceptional;
            }
            catch (GraphFSException_IndexKeyAlreadyExist)
            {
                //NLOG: temporarily commented
                ////_Logger.ErrorException("GraphFSException_IndexKeyAlreadyExist", ikae);
                return new Exceptional<ResultType>(new Error_UniqueConstrainViolation(myDBTypeStream.Name, myIndexName));
            }
            catch
            {
                return new Exceptional<ResultType>(new Error_IndexDoesNotExist(myIndexName, myIndexEdition));
            }

            return new Exceptional<ResultType>(ResultType.Successful);
        }
Example #5
0
        /// <summary>
        /// <seealso cref=" IAtributeIndex"/>
        /// </summary>        
        public override Exceptional Insert(DBObjectStream myDBObject, IndexSetStrategy myIndexSetStrategy, GraphDBType myTypeOfDBObject, DBContext myDBContext)
        {
            foreach (var aIndexKex in GetIndexkeysFromDBObject(myDBObject, myTypeOfDBObject, myDBContext))
            {
                #region get the shard

                //get the actual shard
                var currentIdxShard = GetIndexReference(myDBContext.DBIndexManager, myDBContext.DBIndexManager.GetIndexShardID(aIndexKex, this.AttributeIdxShards));

                if (!currentIdxShard.Success())
                {
                    return new Exceptional(currentIdxShard);
                }
                var currentIdxShardValue = currentIdxShard.Value;

                #endregion

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

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

                #endregion

                SetIndexKeyAndValue(currentIdxShardValue, aIndexKex, myDBObject.ObjectUUID, myIndexSetStrategy);
            }

            return Exceptional.OK;
        }
Example #6
0
        private void SetIndexKeyAndValue(IndexKey myIndexKey, ObjectUUID objectUUID, IndexSetStrategy myIndexSetStrategy)
        {
            HashSet<ObjectUUID> value = null;

            var valueCount = 1UL;

            if (!_indexDatastructure.TryGetValue(myIndexKey, out value))
            {
                //so there is one more key...
                IncreaseKeyCount();
                IncreaseValueCount(valueCount);
            }
            else
            {
                if (!value.Contains(objectUUID))
                {
                    IncreaseValueCount(valueCount);
                }
            }

            _indexDatastructure.Set(myIndexKey, objectUUID, myIndexSetStrategy);
            this.Save();
        }
Example #7
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)
        {
            //do not insert anything, just update the number of objects

            lock (_lockObject)
            {
                _numberOfObjects++;
            }

            return new Exceptional();
        }
Example #8
0
        /// <summary>
        /// <seealso cref=" IAtributeIndex"/>
        /// </summary>        
        public override Exceptional Insert(DBObjectStream myDBObject, IndexSetStrategy myIndexSetStrategy, GraphDBType myTypeOfDBObject, DBContext myDBContext)
        {
            VerifyIndexDatastructure(myDBContext, myTypeOfDBObject);

            System.Diagnostics.Debug.Assert(_indexDatastructure != null);

            var result = GetIndexkeysFromDBObject(myDBObject, myTypeOfDBObject, myDBContext);
            if (result.Failed())
            {
                return result;
            }

            foreach (var aIndexKex in result.Value)
            {
                #region Check for uniqueness - TODO: remove me as soon as we have a unique indexObject implementation

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

                #endregion

                SetIndexKeyAndValue(aIndexKex, myDBObject.ObjectUUID, myIndexSetStrategy);
            }

            return Exceptional.OK;
        }
Example #9
0
        public Exceptional<ResultType> RebuildIndex(String myIndexName, String myIndexEdition, GraphDBType myDBTypeStream, IndexSetStrategy myIndexSetStrategy)
        {
            var objectLocation = new ObjectLocation(myDBTypeStream.ObjectLocation, DBConstants.DBObjectsLocation);
            var allDBOLocations = _IGraphFSSession.GetFilteredDirectoryListing(objectLocation, null, null, null, new List<String>(new String[] { DBConstants.DBOBJECTSTREAM }), null, null, null, null, null, null);

            if (allDBOLocations.Failed() && allDBOLocations.IErrors.First().GetType() != typeof(GraphFSError_ObjectLocatorNotFound))
                return new Exceptional<ResultType>(allDBOLocations);

            try
            {

                var index = myDBTypeStream.GetAttributeIndex(myIndexName, myIndexEdition);

                index.ClearAndRemoveFromDisc(this);

                if (allDBOLocations.Value != null)
                {
                    foreach (var loc in allDBOLocations.Value)
                    {
                        var dbo = _DBContext.DBObjectManager.LoadDBObject(new ObjectLocation(myDBTypeStream.ObjectLocation, DBConstants.DBObjectsLocation, loc));

                        if (dbo.Failed())
                        {
                            return new Exceptional<ResultType>(dbo);
                        }

                        if (!dbo.Value.ObjectLocation.Contains(loc))
                        {
                            //NLOG: temporarily commented
                            ////_Logger.Error("Could not found the correct DBObject for Location " + loc + " the ObjectUUID is now " + dbo.Value.ObjectUUID.ToString());
                        }
                        else
                        {
                            if (dbo.Value.HasAtLeastOneAttribute(index.IndexKeyDefinition.IndexKeyAttributeUUIDs, myDBTypeStream, null))
                            {
                                var insertResult = index.Insert(dbo.Value, myIndexSetStrategy, myDBTypeStream, _DBContext);
                                if (!insertResult.Success())
                                {
                                    return new Exceptional<ResultType>(insertResult);
                                }
                            }
                        }
                    }
                }
            }
            catch (GraphDBException pe)
            {
                var _Exceptional = new Exceptional<ResultType>();
                foreach (var _ex in pe.GraphDBErrors)
                    _Exceptional.PushIError(_ex);
                return _Exceptional;
            }
            catch (GraphFSException_IndexKeyAlreadyExist)
            {
                //NLOG: temporarily commented
                ////_Logger.ErrorException("GraphFSException_IndexKeyAlreadyExist", ikae);
                return new Exceptional<ResultType>(new Error_UniqueConstrainViolation(myDBTypeStream.Name, myIndexName));
            }
            catch
            {
                return new Exceptional<ResultType>(new Error_IndexDoesNotExist(myIndexName, myIndexEdition));
            }

            return new Exceptional<ResultType>(ResultType.Successful);
        }
Example #10
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)
 {
     return new Exceptional(new Error_InvalidIndexOperation(IndexName, "Insert"));
 }
Example #11
0
 private void SetIndexKeyAndValue(IndexKey aIndexKey, ObjectUUID objectUUID, IndexSetStrategy indexSetStrategy)
 {
     HashSet<ObjectUUID> values = null;
     if (_Index.TryGetValue(aIndexKey, out values))
     {
         if (indexSetStrategy == IndexSetStrategy.MERGE)
         {
             values.Add(objectUUID);
             return;
         }
     }
     _Index[aIndexKey] = new HashSet<ObjectUUID>() { objectUUID };
 }
Example #12
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)
 {
     lock (_lockObject)
     {
         _KeyCount++;
         return this.Save();
     }
 }