示例#1
0
        public RelationAdvancedEnumerator(
            RelationDBManipulator <T> manipulator,
            ByteBuffer prefixBytes, uint prefixFieldCount)
        {
            _prefixFieldCount = prefixFieldCount;
            _manipulator      = manipulator;

            _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 RelationPrimaryKeyEnumerator(IInternalObjectDBTransaction tr, RelationInfo relationInfo, ByteBuffer keyBytes,
                                     RelationDBManipulator <T> manipulator)
     : base(tr, relationInfo, keyBytes, manipulator)
 {
     _manipulator = manipulator;
     _skipBytes   = ObjectDB.AllRelationsPKPrefix.Length + +PackUnpack.LengthVUInt(relationInfo.Id);
 }
示例#3
0
 public RelationSecondaryKeyEnumerator(IInternalObjectDBTransaction tr, RelationInfo relationInfo, ByteBuffer keyBytes,
                                       uint secondaryKeyIndex, uint fieldCountInKey, RelationDBManipulator <T> manipulator)
     : base(tr, relationInfo, keyBytes, manipulator)
 {
     _secondaryKeyIndex = secondaryKeyIndex;
     _fieldCountInKey   = fieldCountInKey;
     _manipulator       = manipulator;
 }
示例#4
0
 public RelationAdvancedSecondaryKeyEnumerator(
     RelationDBManipulator <T> manipulator,
     ByteBuffer prefixBytes, uint prefixFieldCount,
     uint secondaryKeyIndex)
     : base(manipulator, prefixBytes, prefixFieldCount)
 {
     _secondaryKeyIndex = secondaryKeyIndex;
 }
示例#5
0
 public RelationAdvancedSecondaryKeyEnumerator(
     RelationDBManipulator <T> manipulator,
     ByteBuffer prefixBytes, uint prefixFieldCount,
     EnumerationOrder order,
     KeyProposition startKeyProposition, ByteBuffer startKeyBytes,
     KeyProposition endKeyProposition, ByteBuffer endKeyBytes,
     uint secondaryKeyIndex)
     : base(manipulator, prefixBytes, prefixFieldCount, order,
            startKeyProposition, startKeyBytes,
            endKeyProposition, endKeyBytes)
 {
     _secondaryKeyIndex = secondaryKeyIndex;
 }
示例#6
0
        public RelationAdvancedOrderedSecondaryKeyEnumerator(RelationDBManipulator <TValue> manipulator,
                                                             ByteBuffer prefixBytes, uint prefixFieldCount, EnumerationOrder order,
                                                             KeyProposition startKeyProposition, ByteBuffer startKeyBytes,
                                                             KeyProposition endKeyProposition, ByteBuffer endKeyBytes,
                                                             uint secondaryKeyIndex)
            : base(manipulator, prefixBytes, prefixFieldCount, order,
                   startKeyProposition, startKeyBytes,
                   endKeyProposition, endKeyBytes, false)
        {
            _secondaryKeyIndex = secondaryKeyIndex;
            var secKeyFields           = manipulator.RelationInfo.ClientRelationVersionInfo.GetSecondaryKeyFields(secondaryKeyIndex);
            var advancedEnumParamField = secKeyFields.ToList()[(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)));
        }
示例#7
0
        public int RemoveByIdAdvancedParam(RelationDBManipulator <T> manipulator, ByteBuffer prefixBytes, uint prefixFieldCount,
                                           EnumerationOrder order,
                                           KeyProposition startKeyProposition, ByteBuffer startKeyBytes,
                                           KeyProposition endKeyProposition, ByteBuffer endKeyBytes)
        {
            using (var enumerator = new RelationAdvancedEnumerator <T>(manipulator, prefixBytes, prefixFieldCount,
                                                                       order, startKeyProposition, startKeyBytes, endKeyProposition, endKeyBytes))
            {
                var keysToDelete = new List <ByteBuffer>();
                while (enumerator.MoveNext())
                {
                    keysToDelete.Add(enumerator.GetKeyBytes());
                }

                foreach (var key in keysToDelete)
                {
                    RemoveById(key, true);
                }

                return(keysToDelete.Count);
            }
        }
示例#8
0
        public RelationAdvancedOrderedEnumerator(RelationDBManipulator <TValue> manipulator,
                                                 ByteBuffer prefixBytes, uint prefixFieldCount,
                                                 EnumerationOrder order,
                                                 KeyProposition startKeyProposition, ByteBuffer startKeyBytes,
                                                 KeyProposition endKeyProposition, ByteBuffer endKeyBytes, bool initKeyReader = true)
        {
            _prefixFieldCount = prefixFieldCount;
            _manipulator      = manipulator;
            _tr        = manipulator.Transaction;
            _ascending = order == EnumerationOrder.Ascending;

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

            _keyBytes = prefixBytes;
            _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.ToList()[(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;
            }
        }
示例#9
0
        public RelationAdvancedEnumerator(
            RelationDBManipulator <T> manipulator,
            ByteBuffer prefixBytes, uint prefixFieldCount,
            EnumerationOrder order,
            KeyProposition startKeyProposition, ByteBuffer startKeyBytes,
            KeyProposition endKeyProposition, ByteBuffer endKeyBytes)
        {
            _prefixFieldCount = prefixFieldCount;
            _manipulator      = manipulator;

            _ascending = order == EnumerationOrder.Ascending;

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

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

            _prevModificationCounter = manipulator.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;
        }
示例#10
0
 public RelationPrimaryKeyEnumerator(IInternalObjectDBTransaction tr, RelationInfo relationInfo, ByteBuffer keyBytes,
                                     RelationDBManipulator <T> manipulator)
     : base(tr, relationInfo, keyBytes, manipulator)
 {
     _skipBytes = relationInfo.Prefix.Length;
 }