Beispiel #1
0
        internal bool UpdateKey(TKey key, Guid transaction)
        {
            Guid existing;

            if (_trxModifiedKeys.TryGetValue(key, out existing) && existing != transaction)
            {
                return(false);
            }
            var rr = Read(key, transaction);

            if (null != rr && CompareEq.Equals(key, rr.Address.Key))
            {
                return(true);
            }

            _trxOperations.GetOrAdd(transaction, new ConcurrentList <SdsCommand <TKey> >()).Add(new SdsCommand <TKey>
            {
                Key      = key,
                Position =
                    null == rr
                                                                                                             ? -1
                                                                                                             : rr.
                    Address
                    .
                    Position,
                Size =
                    null == rr
                                                                                                             ? 0
                                                                                                             : rr.
                    Address
                    .Size,
                TableId = Id,
                Code    =
                    CommandCode.Put
            });

            if (existing != transaction)
            {
                _trxModifiedKeys.TryAdd(key, transaction);
            }

            return(true);
        }
Beispiel #2
0
        internal ReadInfo <TKey> Read(TKey key, Guid transaction)
        {
            byte[] data;

            Guid modified;

            if (_trxModifiedKeys.TryGetValue(key, out modified) && modified == transaction)
            {
                var comm = _trxOperations.GetOrAdd(transaction, new ConcurrentList <SdsCommand <TKey> >())
                           .LastOrDefault(x => CompareEq.Equals(x.Key, key));

                if (null != comm)
                {
                    if (comm.Code == CommandCode.Put)
                    {
                        var eTag = Guid.Empty;
                        data = ReadData(comm, eTag);
                        return(new ReadInfo <TKey>
                        {
                            Address =
                                new StoreAddress <TKey>
                            {
                                Key = comm.Key, Position = comm.Position, Size = comm.Size
                            },
                            GetData = delegate
                            {
                                var etag = Guid.Empty;
                                var retval = data ?? (data = ReadData(comm, etag));
                                return retval;
                            },
                            ETag = eTag
                        });
                    }
                    return(null);
                }
            }

            return(StoreRead(key));
        }