Esempio n. 1
0
        public RelationAdvancedEnumerator(
            IRelationDbManipulator manipulator, ByteBuffer prefixBytes, uint prefixFieldCount, int loaderIndex)
        {
            _prefixFieldCount = prefixFieldCount;
            _manipulator      = manipulator;
            ItemLoader        = _manipulator.RelationInfo.ItemLoaderInfos[loaderIndex];

            _ascending = true;

            _tr                    = manipulator.Transaction;
            _keyValueTr            = _tr.KeyValueDBTransaction;
            _keyValueTrProtector   = _tr.TransactionProtector;
            _prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;

            _keyBytes = prefixBytes;

            _keyValueTrProtector.Start();
            _keyValueTr.SetKeyPrefix(_keyBytes);

            _prevModificationCounter = manipulator.ModificationCounter.ModificationCounter;

            _count                 = (uint)_keyValueTr.GetKeyValueCount();
            _startPos              = _ascending ? 0 : _count - 1;
            _pos                   = 0;
            _seekNeeded            = true;
            _lengthOfNonDataPrefix = manipulator.RelationInfo.Prefix.Length;
        }
Esempio n. 2
0
 object?FindByIdOrDefaultInternal(RelationInfo.ItemLoaderInfo itemLoader, ByteBuffer keyBytes, bool throwWhenNotFound)
 {
     ResetKeyPrefix();
     if (_kvtr.Find(keyBytes) != FindResult.Exact)
     {
         if (throwWhenNotFound)
         {
             throw new BTDBException("Not found.");
         }
         return(default);
Esempio n. 3
0
        public RelationEnumerator(IInternalObjectDBTransaction tr, RelationInfo relationInfo, byte[] keyBytes,
                                  IRelationModificationCounter modificationCounter, int loaderIndex)
        {
            _transaction = tr;

            ItemLoader             = relationInfo.ItemLoaderInfos[loaderIndex];
            _keyValueTr            = _transaction.KeyValueDBTransaction;
            _prevProtectionCounter = _keyValueTr.CursorMovedCounter;

            KeyBytes             = keyBytes;
            _modificationCounter = modificationCounter;
            _pos        = 0;
            _seekNeeded = true;
            _prevModificationCounter = _modificationCounter.ModificationCounter;
        }
Esempio n. 4
0
        public RelationEnumerator(IInternalObjectDBTransaction tr, RelationInfo relationInfo, ByteBuffer keyBytes,
                                  IRelationModificationCounter modificationCounter, int loaderIndex)
        {
            RelationInfo = relationInfo;
            Transaction  = tr;

            ItemLoader             = relationInfo.ItemLoaderInfos[loaderIndex];
            _keyValueTr            = Transaction.KeyValueDBTransaction;
            _keyValueTrProtector   = Transaction.TransactionProtector;
            _prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;

            KeyBytes             = keyBytes;
            _modificationCounter = modificationCounter;
            _keyValueTrProtector.Start();
            _keyValueTr.SetKeyPrefix(KeyBytes);
            _pos        = 0;
            _seekNeeded = true;
            _prevModificationCounter = _modificationCounter.ModificationCounter;
        }
Esempio n. 5
0
        public RelationAdvancedOrderedEnumerator(IRelationDbManipulator manipulator,
                                                 ByteBuffer prefixBytes, uint prefixFieldCount,
                                                 EnumerationOrder order,
                                                 KeyProposition startKeyProposition, ByteBuffer startKeyBytes,
                                                 KeyProposition endKeyProposition, ByteBuffer endKeyBytes, bool initKeyReader, int loaderIndex)
        {
            _prefixFieldCount = prefixFieldCount;
            _manipulator      = manipulator;
            ItemLoader        = _manipulator.RelationInfo.ItemLoaderInfos[loaderIndex];
            _tr        = manipulator.Transaction;
            _ascending = order == EnumerationOrder.Ascending;

            _keyValueTr            = _tr.KeyValueDBTransaction;
            _keyValueTrProtector   = _tr.TransactionProtector;
            _prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;

            _keyBytes = prefixBytes;
            if (endKeyProposition == KeyProposition.Included)
            {
                endKeyBytes = RelationAdvancedEnumerator <TValue> .FindLastKeyWithPrefix(_keyBytes, endKeyBytes,
                                                                                         _keyValueTr, _keyValueTrProtector);
            }

            _keyValueTrProtector.Start();
            _keyValueTr.SetKeyPrefix(_keyBytes);

            long startIndex;
            long endIndex;

            if (endKeyProposition == KeyProposition.Ignored)
            {
                endIndex = _keyValueTr.GetKeyValueCount() - 1;
            }
            else
            {
                switch (_keyValueTr.Find(endKeyBytes))
                {
                case FindResult.Exact:
                    endIndex = _keyValueTr.GetKeyIndex();
                    if (endKeyProposition == KeyProposition.Excluded)
                    {
                        endIndex--;
                    }

                    break;

                case FindResult.Previous:
                    endIndex = _keyValueTr.GetKeyIndex();
                    break;

                case FindResult.Next:
                    endIndex = _keyValueTr.GetKeyIndex() - 1;
                    break;

                case FindResult.NotFound:
                    endIndex = -1;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (startKeyProposition == KeyProposition.Ignored)
            {
                startIndex = 0;
            }
            else
            {
                switch (_keyValueTr.Find(startKeyBytes))
                {
                case FindResult.Exact:
                    startIndex = _keyValueTr.GetKeyIndex();
                    if (startKeyProposition == KeyProposition.Excluded)
                    {
                        startIndex++;
                    }

                    break;

                case FindResult.Previous:
                    startIndex = _keyValueTr.GetKeyIndex() + 1;
                    break;

                case FindResult.Next:
                    startIndex = _keyValueTr.GetKeyIndex();
                    break;

                case FindResult.NotFound:
                    startIndex = 0;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _count     = (uint)Math.Max(0, endIndex - startIndex + 1);
            _startPos  = (uint)(_ascending ? startIndex : endIndex);
            _pos       = 0;
            _seekState = SeekState.Undefined;

            if (initKeyReader)
            {
                var primaryKeyFields       = manipulator.RelationInfo.ClientRelationVersionInfo.GetPrimaryKeyFields();
                var advancedEnumParamField = primaryKeyFields[(int)_prefixFieldCount];
                if (advancedEnumParamField.Handler.NeedsCtx())
                {
                    throw new BTDBException("Not supported.");
                }
                _keyReader = (Func <AbstractBufferedReader, IReaderCtx, TKey>)manipulator.RelationInfo
                             .GetSimpleLoader(new RelationInfo.SimpleLoaderType(advancedEnumParamField.Handler, typeof(TKey)));

                _lengthOfNonDataPrefix = manipulator.RelationInfo.Prefix.Length;
            }
        }
Esempio n. 6
0
        public RelationAdvancedEnumerator(
            IRelationDbManipulator manipulator,
            ByteBuffer prefixBytes, uint prefixFieldCount,
            EnumerationOrder order,
            KeyProposition startKeyProposition, ByteBuffer startKeyBytes,
            KeyProposition endKeyProposition, ByteBuffer endKeyBytes, int loaderIndex)
        {
            _prefixFieldCount = prefixFieldCount;
            _manipulator      = manipulator;
            ItemLoader        = _manipulator.RelationInfo.ItemLoaderInfos[loaderIndex];

            _ascending = order == EnumerationOrder.Ascending;

            _tr                    = manipulator.Transaction;
            _keyValueTr            = _tr.KeyValueDBTransaction;
            _keyValueTrProtector   = _tr.TransactionProtector;
            _prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;

            _keyBytes = prefixBytes;
            if (endKeyProposition == KeyProposition.Included)
            {
                endKeyBytes = FindLastKeyWithPrefix(_keyBytes, endKeyBytes, _keyValueTr, _keyValueTrProtector);
            }

            _keyValueTrProtector.Start();
            _keyValueTr.SetKeyPrefix(_keyBytes);

            _prevModificationCounter = manipulator.ModificationCounter.ModificationCounter;

            long startIndex;
            long endIndex;

            if (endKeyProposition == KeyProposition.Ignored)
            {
                endIndex = _keyValueTr.GetKeyValueCount() - 1;
            }
            else
            {
                switch (_keyValueTr.Find(endKeyBytes))
                {
                case FindResult.Exact:
                    endIndex = _keyValueTr.GetKeyIndex();
                    if (endKeyProposition == KeyProposition.Excluded)
                    {
                        endIndex--;
                    }

                    break;

                case FindResult.Previous:
                    endIndex = _keyValueTr.GetKeyIndex();
                    break;

                case FindResult.Next:
                    endIndex = _keyValueTr.GetKeyIndex() - 1;
                    break;

                case FindResult.NotFound:
                    endIndex = -1;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (startKeyProposition == KeyProposition.Ignored)
            {
                startIndex = 0;
            }
            else
            {
                switch (_keyValueTr.Find(startKeyBytes))
                {
                case FindResult.Exact:
                    startIndex = _keyValueTr.GetKeyIndex();
                    if (startKeyProposition == KeyProposition.Excluded)
                    {
                        startIndex++;
                    }

                    break;

                case FindResult.Previous:
                    startIndex = _keyValueTr.GetKeyIndex() + 1;
                    break;

                case FindResult.Next:
                    startIndex = _keyValueTr.GetKeyIndex();
                    break;

                case FindResult.NotFound:
                    startIndex = 0;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _count                 = (uint)Math.Max(0, endIndex - startIndex + 1);
            _startPos              = (uint)(_ascending ? startIndex : endIndex);
            _pos                   = 0;
            _seekNeeded            = true;
            _lengthOfNonDataPrefix = manipulator.RelationInfo.Prefix.Length;
        }