예제 #1
0
 public KeyValue GetLessThanOrEqualKey(KeyValue keyValue, LockBias lockBias = LockBias.None, bool overwrite = false)
 {
     if (_positionBlock == null)
     {
         throw new InvalidOperationException();
     }
     if (keyValue == null)
     {
         throw new ArgumentNullException();
     }
     if (!overwrite)
     {
         keyValue = keyValue.DeepCopy();
     }
     _nativeOperator.GetLessThanOrEqualKey(_positionBlock, keyValue.KeyBuffer, keyValue.Key.KeyNumber, lockBias);
     keyValue.ComplementCount = 0;
     return(keyValue);
 }
예제 #2
0
        public TRecord GetLessThanOrEqual(KeyValue keyValue, LockBias lockBias = LockBias.None, bool overwrite = false)
        {
            if (_positionBlock == null)
            {
                throw new InvalidOperationException();
            }
            if (keyValue == null)
            {
                throw new ArgumentNullException();
            }
            if (!overwrite)
            {
                keyValue = keyValue.DeepCopy();
            }
            var record = this.CreateRecord();

            _nativeOperator.GetLessThanOrEqual(_positionBlock, record.DataBuffer, keyValue.KeyBuffer, keyValue.Key.KeyNumber, lockBias);
            keyValue.ComplementCount = 0;
            return(record);
        }
예제 #3
0
        IEnumerable <TRecord> OperateExtended(Operation operation, KeyValue keyValue, FilterAnd filter, bool skipCurrentPosition, int limit, LockBias lockBias, ushort rejectCount, bool overwrite = false)
        {
            if (_positionBlock == null)
            {
                throw new InvalidOperationException();
            }
            if (filter != null && !filter.Check(this.RecordInfo))
            {
                throw new ArgumentException();
            }
            if (keyValue != null && !overwrite)
            {
                keyValue = keyValue.DeepCopy();
            }
            var useLimit = limit > 0;

            rejectCount = rejectCount == 0 ? this.RecordInfo.RejectCount : rejectCount;
            var isFirst      = true;
            var bufferLength = Config.MaxBufferLength - Config.ExtendedOperationBufferMargin;

            for (; ;)
            {
                var dataBufferLength = (ushort)(filter == null ? 16 : filter.Length + 16);
                Array.Copy(BitConverter.GetBytes(dataBufferLength), 0, this.TemporaryBuffer, 0, 2);
                Array.Copy(Encoding.ASCII.GetBytes(!isFirst || skipCurrentPosition ? "EG" : "UC"), 0, this.TemporaryBuffer, 2, 2);
                isFirst             = false;
                skipCurrentPosition = true;
                Array.Copy(BitConverter.GetBytes(rejectCount), 0, this.TemporaryBuffer, 4, 2);
                Array.Copy(BitConverter.GetBytes(filter == null ? 0 : filter.Count), 0, this.TemporaryBuffer, 6, 2);
                if (filter != null)
                {
                    filter.SetDataBuffer(this.TemporaryBuffer);
                }
                var position = (ushort)(filter == null ? 8 : filter.Length + 8);
                var count    = (ushort)(bufferLength / (this.RecordInfo.DataBufferCapacity + 6));
                if (useLimit && count > limit)
                {
                    count = (ushort)limit;
                }
                if (count == 0)
                {
                    throw new InvalidOperationException();
                }
                Array.Copy(BitConverter.GetBytes(count), 0, this.TemporaryBuffer, position, 2);
                position += 2;
                Array.Copy(BitConverter.GetBytes((ushort)(1)), 0, this.TemporaryBuffer, position, 2);
                position += 2;
                Array.Copy(BitConverter.GetBytes(this.RecordInfo.DataBufferCapacity), 0, this.TemporaryBuffer, position, 2);
                position += 2;
                Array.Copy(BitConverter.GetBytes((ushort)(0)), 0, this.TemporaryBuffer, position, 2);
                var isBreak = false;
                try {
                    if (keyValue == null)
                    {
                        _nativeOperator.Operate(operation, _positionBlock, this.TemporaryBuffer, null, (sbyte)0, (ushort)lockBias);
                    }
                    else
                    {
                        _nativeOperator.Operate(operation, _positionBlock, this.TemporaryBuffer, keyValue.KeyBuffer, keyValue.Key.KeyNumber, (ushort)lockBias);
                    }
                } catch (OperationException e) {
                    if (e.StatusCode == 9 || e.StatusCode == 64)
                    {
                        isBreak = true;
                    }
                    else if (e.StatusCode != 60)
                    {
                        throw;
                    }
                }
                if (keyValue != null)
                {
                    keyValue.ComplementCount = 0;
                }

                count    = BitConverter.ToUInt16(this.TemporaryBuffer, 0);
                position = 2;
                ushort  length;
                TRecord record;
                for (var i = 0; i < count; i++)
                {
                    length = BitConverter.ToUInt16(this.TemporaryBuffer, position);
                    record = this.CreateRecord();
                    Array.Copy(this.TemporaryBuffer, position + 6, record.DataBuffer, 0, this.RecordInfo.DataBufferCapacity);
                    record.HasPhysicalPosition = true;
                    record.PhysicalPosition    = BitConverter.ToUInt32(this.TemporaryBuffer, position + 2);
                    yield return(record);

                    position += (ushort)(length + 6);
                }
                if (isBreak)
                {
                    yield break;
                }
                if (useLimit)
                {
                    limit -= count;
                    if (limit <= 0)
                    {
                        yield break;
                    }
                }
            }
        }