Exemplo n.º 1
0
        public bool RemoveById(ByteBuffer keyBytes, bool throwWhenNotFound)
        {
            StartWorkingWithPK();
            if (_transaction.KeyValueDBTransaction.Find(keyBytes) != FindResult.Exact)
            {
                if (throwWhenNotFound)
                {
                    throw new BTDBException("Not found record to delete.");
                }
                return(false);
            }
            var valueBytes = _transaction.KeyValueDBTransaction.GetValue();

            _transaction.KeyValueDBTransaction.EraseCurrent();

            if (_hasSecondaryIndexes)
            {
                RemoveSecondaryIndexes(keyBytes, valueBytes);
            }

            _relationInfo.FreeContent(_transaction, valueBytes);

            _modificationCounter.MarkModification();
            return(true);
        }
Exemplo n.º 2
0
        public bool RemoveById(ByteBuffer keyBytes, bool throwWhenNotFound)
        {
            if (HasSecondaryIndexes)
            {
                var obj = FindByIdOrDefault(keyBytes, throwWhenNotFound);
                if (obj != null)
                {
                    RemoveSecondaryIndexes(obj);
                }
            }

            var prevProtectionCounter = _transaction.TransactionProtector.ProtectionCounter;

            StartWorkingWithPK();
            if (_transaction.KeyValueDBTransaction.Find(keyBytes) != FindResult.Exact)
            {
                if (throwWhenNotFound)
                {
                    throw new BTDBException("Not found record to delete.");
                }
                return(false);
            }

            var valueBytes = _transaction.KeyValueDBTransaction.GetValue();

            _relationInfo.FreeContent(_transaction, valueBytes);
            if (_transaction.TransactionProtector.WasInterupted(prevProtectionCounter))
            {
                StartWorkingWithPK();
                _transaction.KeyValueDBTransaction.Find(keyBytes);
            }

            _transaction.KeyValueDBTransaction.EraseCurrent();
            _relationInfo.MarkModification();
            return(true);
        }