예제 #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;
        }
예제 #2
0
        public RelationEnumerator(IInternalObjectDBTransaction tr, RelationInfo relationInfo, ByteBuffer keyBytes)
        {
            RelationInfo = relationInfo;
            _tr          = tr;

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

            KeyBytes = keyBytes;
            _keyValueTr.SetKeyPrefix(KeyBytes);
            _pos        = 0;
            _seekNeeded = true;
            _prevModificationCounter = relationInfo.ModificationCounter;
        }
예제 #3
0
 public ODBDictionary(IInternalObjectDBTransaction tr, ODBDictionaryConfiguration config, ulong id)
 {
     _tr           = tr;
     _keyHandler   = config.KeyHandler;
     _valueHandler = config.ValueHandler;
     _id           = id;
     GeneratePrefix();
     _keyReader           = (Func <AbstractBufferedReader, IReaderCtx, TKey>)config.KeyReader;
     _keyWriter           = (Action <TKey, AbstractBufferedWriter, IWriterCtx>)config.KeyWriter;
     _valueReader         = (Func <AbstractBufferedReader, IReaderCtx, TValue>)config.ValueReader;
     _valueWriter         = (Action <TValue, AbstractBufferedWriter, IWriterCtx>)config.ValueWriter;
     _keyValueTr          = _tr.KeyValueDBTransaction;
     _keyValueTrProtector = _tr.TransactionProtector;
     _count = -1;
 }
예제 #4
0
        public ODBSet(IInternalObjectDBTransaction tr, ODBDictionaryConfiguration config, ulong id)
        {
            _tr         = tr;
            _keyHandler = config.KeyHandler;
            _id         = id;
            var o = ObjectDB.AllDictionariesPrefix.Length;

            _prefix = new byte[o + PackUnpack.LengthVUInt(_id)];
            Array.Copy(ObjectDB.AllDictionariesPrefix, _prefix, o);
            PackUnpack.PackVUInt(_prefix, ref o, _id);
            _keyReader           = ((Func <AbstractBufferedReader, IReaderCtx, TKey>)config.KeyReader) !;
            _keyWriter           = ((Action <TKey, AbstractBufferedWriter, IWriterCtx>)config.KeyWriter) !;
            _keyValueTr          = _tr.KeyValueDBTransaction;
            _keyValueTrProtector = _tr.TransactionProtector;
            _count = -1;
        }
예제 #5
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;
        }
예제 #6
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;
            }
        }
예제 #7
0
        internal static ByteBuffer FindLastKeyWithPrefix(ByteBuffer keyBytes, ByteBuffer endKeyBytes,
                                                         IKeyValueDBTransaction keyValueTr, KeyValueDBTransactionProtector keyValueTrProtector)
        {
            var buffer = ByteBuffer.NewEmpty();

            buffer = buffer.ResizingAppend(keyBytes).ResizingAppend(endKeyBytes);
            keyValueTrProtector.Start();
            keyValueTr.SetKeyPrefix(buffer);
            if (!keyValueTr.FindLastKey())
            {
                return(endKeyBytes);
            }
            var key = keyValueTr.GetKeyIncludingPrefix();

            return(key.Slice(keyBytes.Length));
        }
예제 #8
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;
        }
예제 #9
0
            public AdvancedEnumerator(ODBSet <TKey> owner, AdvancedEnumeratorParam <TKey> param)
            {
                _owner = owner;
                _keyValueTrProtector = _owner._keyValueTrProtector;
                _keyValueTr          = _owner._keyValueTr;
                _ascending           = param.Order == EnumerationOrder.Ascending;
                _keyValueTrProtector.Start();
                _prevModificationCounter = _owner._modificationCounter;
                _prevProtectionCounter   = _keyValueTrProtector.ProtectionCounter;
                _keyValueTr.SetKeyPrefix(_owner._prefix);
                long startIndex;
                long endIndex;

                if (param.EndProposition == KeyProposition.Ignored)
                {
                    endIndex = _keyValueTr.GetKeyValueCount() - 1;
                }
                else
                {
                    var keyBytes = _owner.KeyToByteArray(param.End);
                    switch (_keyValueTr.Find(keyBytes))
                    {
                    case FindResult.Exact:
                        endIndex = _keyValueTr.GetKeyIndex();
                        if (param.EndProposition == 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 (param.StartProposition == KeyProposition.Ignored)
                {
                    startIndex = 0;
                }
                else
                {
                    var keyBytes = _owner.KeyToByteArray(param.Start);
                    switch (_keyValueTr.Find(keyBytes))
                    {
                    case FindResult.Exact:
                        startIndex = _keyValueTr.GetKeyIndex();
                        if (param.StartProposition == 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;
            }
예제 #10
0
 internal KeyValueDBValueProtectedWriter(IKeyValueDBTransaction transaction, KeyValueDBTransactionProtector protector)
     : base(transaction)
 {
     _protector = protector;
 }
 internal KeyValueDBValueProtectedWriter(IKeyValueDBTransaction transaction, KeyValueDBTransactionProtector protector)
     : base(transaction)
 {
     _protector = protector;
 }