Beispiel #1
0
        public StructReadResult <T> ReadStruct <T>(string treeName, Slice key, StructureSchema <T> schema, WriteBatch writeBatch = null)
        {
            Tree tree = null;

            if (writeBatch != null && writeBatch.IsEmpty == false)
            {
                WriteBatch.InBatchValue result;
                if (writeBatch.TryGetValue(treeName, key, out result))
                {
                    if (!result.Version.HasValue)
                    {
                        tree = GetTree(treeName);
                    }

                    switch (result.OperationType)
                    {
                    case WriteBatch.BatchOperationType.AddStruct:
                        return(new StructReadResult <T>(new StructureReader <T>((Structure <T>)result.Struct, schema), result.Version.HasValue ? (ushort)(result.Version.Value + 1) : tree.ReadVersion(key)));

                    case WriteBatch.BatchOperationType.Delete:
                        return(null);
                    }
                }
            }

            if (tree == null)
            {
                tree = GetTree(treeName);
            }

            return(tree.ReadStruct(key, schema));
        }
Beispiel #2
0
        public bool Contains(string treeName, Slice key, out ushort?version, WriteBatch writeBatch = null)
        {
            if (writeBatch != null && writeBatch.IsEmpty == false)
            {
                WriteBatch.InBatchValue result;
                if (writeBatch.TryGetValue(treeName, key, out result))
                {
                    version = result.Version;

                    switch (result.OperationType)
                    {
                    case WriteBatch.BatchOperationType.Add:
                        return(true);

                    case WriteBatch.BatchOperationType.AddStruct:
                        return(true);

                    case WriteBatch.BatchOperationType.Delete:
                        return(false);

                    default:
                        throw new ArgumentOutOfRangeException(result.OperationType.ToString());
                    }
                }
            }

            var tree        = GetTree(treeName);
            var readVersion = tree.ReadVersion(key);

            var exists = readVersion > 0;

            version = exists ? (ushort?)readVersion : null;

            return(exists);
        }
Beispiel #3
0
        public ReadResult Read(string treeName, Slice key, WriteBatch writeBatch = null)
        {
            Tree tree = null;

            if (writeBatch != null && writeBatch.IsEmpty == false)
            {
                WriteBatch.InBatchValue result;
                if (writeBatch.TryGetValue(treeName, key, out result))
                {
                    if (!result.Version.HasValue)
                    {
                        tree = GetTree(treeName);
                    }

                    switch (result.OperationType)
                    {
                    case WriteBatch.BatchOperationType.Add:
                    {
                        var reader = new ValueReader(result.Stream);
                        return(new ReadResult(reader, result.Version.HasValue ? (ushort)(result.Version.Value + 1) : tree.ReadVersion(key)));
                    }

                    case WriteBatch.BatchOperationType.Delete:
                        return(null);
                    }
                }
            }

            if (tree == null)
            {
                tree = GetTree(treeName);
            }

            return(tree.Read(key));
        }
Beispiel #4
0
        public bool Contains(string treeName, Slice key, out ushort?version, WriteBatch writeBatch = null)
        {
            if (writeBatch != null)
            {
                WriteBatch.BatchOperationType operationType;
                Stream stream;
                if (writeBatch.TryGetValue(treeName, key, out stream, out version, out operationType))
                {
                    switch (operationType)
                    {
                    case WriteBatch.BatchOperationType.Add:
                        return(true);

                    case WriteBatch.BatchOperationType.Delete:
                        return(false);

                    default:
                        throw new ArgumentOutOfRangeException(operationType.ToString());
                    }
                }
            }

            var tree        = GetTree(treeName);
            var readVersion = tree.ReadVersion(Transaction, key);

            var exists = readVersion > 0;

            version = exists ? (ushort?)readVersion : null;

            return(exists);
        }
Beispiel #5
0
        public ushort ReadVersion(string treeName, Slice key, WriteBatch writeBatch = null)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("SnapshotReader");
            }
            if (writeBatch != null)
            {
                WriteBatch.InBatchValue result;
                if (writeBatch.TryGetValue(treeName, key, out result) && result.Version.HasValue)
                {
                    switch (result.OperationType)
                    {
                    case WriteBatch.BatchOperationType.Add:
                    case WriteBatch.BatchOperationType.AddStruct:
                    case WriteBatch.BatchOperationType.Delete:
                        return((ushort)(result.Version.Value + 1));
                    }
                }
            }

            var tree = GetTree(treeName);

            return(tree.ReadVersion(key));
        }
Beispiel #6
0
        public ushort ReadVersion(string treeName, Slice key, WriteBatch writeBatch = null)
        {
            if (writeBatch != null)
            {
                WriteBatch.BatchOperationType operationType;
                Stream stream;
                ushort?version;
                if (writeBatch.TryGetValue(treeName, key, out stream, out version, out operationType) && version.HasValue)
                {
                    switch (operationType)
                    {
                    case WriteBatch.BatchOperationType.Add:
                    case WriteBatch.BatchOperationType.Delete:
                        return((ushort)(version.Value + 1));
                    }
                }
            }

            var tree = GetTree(treeName);

            return(tree.ReadVersion(Transaction, key));
        }
Beispiel #7
0
        public ReadResult Read(string treeName, Slice key, WriteBatch writeBatch = null)
        {
            Tree tree = null;

            if (writeBatch != null)
            {
                WriteBatch.BatchOperationType operationType;
                Stream stream;
                ushort?version;
                if (writeBatch.TryGetValue(treeName, key, out stream, out version, out operationType))
                {
                    if (!version.HasValue)
                    {
                        tree = GetTree(treeName);
                    }

                    switch (operationType)
                    {
                    case WriteBatch.BatchOperationType.Add:
                    {
                        var reader = new ValueReader(stream);
                        return(new ReadResult(reader, version.HasValue ? (ushort)(version.Value + 1) : tree.ReadVersion(Transaction, key)));
                    }

                    case WriteBatch.BatchOperationType.Delete:
                        return(null);
                    }
                }
            }

            if (tree == null)
            {
                tree = GetTree(treeName);
            }

            return(tree.Read(Transaction, key));
        }