Beispiel #1
0
        uint ReadRelationVersions(uint relationIndex, string name, Dictionary <uint, RelationVersionInfo> relationVersions)
        {
            uint lastPersistedVersion = 0;
            var  relationInfoResolver = new RelationInfoResolver((ObjectDB)_tr.Owner);

            var writer = new ByteBufferWriter();

            writer.WriteByteArrayRaw(ObjectDB.RelationVersionsPrefix);
            writer.WriteVUInt32(relationIndex);
            _trkv.SetKeyPrefix(writer.Data);
            if (!_trkv.FindFirstKey())
            {
                return(lastPersistedVersion);
            }
            var keyReader   = new KeyValueDBKeyReader(_trkv);
            var valueReader = new KeyValueDBValueReader(_trkv);

            do
            {
                keyReader.Restart();
                valueReader.Restart();
                lastPersistedVersion = keyReader.ReadVUInt32();
                var relationVersionInfo = RelationVersionInfo.LoadUnresolved(valueReader, name);
                relationVersionInfo.ResolveFieldHandlers(relationInfoResolver.FieldHandlerFactory);
                relationVersions[lastPersistedVersion] = relationVersionInfo;
            } while (_trkv.FindNextKey());

            return(lastPersistedVersion);
        }
Beispiel #2
0
        void LoadVersionInfos(IKeyValueDBTransaction tr)
        {
            LastPersistedVersion = 0;
            var writer = new ByteBufferWriter();

            writer.WriteByteArrayRaw(ObjectDB.RelationVersionsPrefix);
            writer.WriteVUInt32(_id);
            tr.SetKeyPrefix(writer.Data);
            if (!tr.FindFirstKey())
            {
                return;
            }
            var keyReader   = new KeyValueDBKeyReader(tr);
            var valueReader = new KeyValueDBValueReader(tr);

            do
            {
                keyReader.Restart();
                valueReader.Restart();
                LastPersistedVersion = keyReader.ReadVUInt32();
                var relationVersionInfo = RelationVersionInfo.Load(valueReader,
                                                                   _relationInfoResolver.FieldHandlerFactory, _name);
                _relationVersions[LastPersistedVersion] = relationVersionInfo;
            } while (tr.FindNextKey());
        }
Beispiel #3
0
        public void Iterate(bool sortTableByNameAsc = false)
        {
            LoadTableNamesDict();
            LoadRelationNamesDict();
            MarkLastDictId();
            _trkv.SetKeyPrefixUnsafe(ObjectDB.TableSingletonsPrefix);
            var keyReader   = new KeyValueDBKeyReader(_trkv);
            var valueReader = new KeyValueDBValueReader(_trkv);

            _singletons = new Dictionary <uint, ulong>();
            while (_trkv.FindNextKey())
            {
                keyReader.Restart();
                valueReader.Restart();
                _singletons.Add(keyReader.ReadVUInt32(), valueReader.ReadVUInt64());
            }

            if (sortTableByNameAsc)
            {
                _singletons = _singletons.OrderBy(item =>
                {
                    string name;
                    return(_tableId2Name.TryGetValue(item.Key, out name) ? name : string.Empty);
                }).ToDictionary(item => item.Key, item => item.Value);
            }

            foreach (var singleton in _singletons)
            {
                string name;
                if (_visitor != null &&
                    !_visitor.VisitSingleton(singleton.Key,
                                             _tableId2Name.TryGetValue(singleton.Key, out name) ? name : null, singleton.Value))
                {
                    continue;
                }
                MarkTableName(singleton.Key);
                _trkv.SetKeyPrefixUnsafe(ObjectDB.TableSingletonsPrefix);
                if (_trkv.Find(Vuint2ByteBuffer(singleton.Key)) == FindResult.Exact)
                {
                    _fastVisitor.MarkCurrentKeyAsUsed(_trkv);
                }
                IterateOid(singleton.Value);
            }
            foreach (var relation in _relationId2Name)
            {
                if (_visitor != null && !_visitor.StartRelation(relation.Value))
                {
                    continue;
                }
                MarkRelationName(relation.Key);
                IterateRelation(relation.Key, relation.Value);
                if (_visitor != null)
                {
                    _visitor.EndRelation();
                }
            }
        }
Beispiel #4
0
        static IEnumerable <string> LoadTablesEnum(IKeyValueDBTransaction tr)
        {
            tr.SetKeyPrefix(TableNamesPrefix);
            var valueReader = new KeyValueDBValueReader(tr);

            while (tr.Enumerate())
            {
                valueReader.Restart();
                yield return(valueReader.ReadString());
            }
        }
Beispiel #5
0
        internal static IEnumerable <KeyValuePair <uint, string> > LoadRelationNamesEnum(IKeyValueDBTransaction tr)
        {
            tr.SetKeyPrefixUnsafe(RelationNamesPrefix);
            var keyReader   = new KeyValueDBKeyReader(tr);
            var valueReader = new KeyValueDBValueReader(tr);

            while (tr.FindNextKey())
            {
                keyReader.Restart();
                valueReader.Restart();
                yield return(new KeyValuePair <uint, string>(valueReader.ReadVUInt32(), keyReader.ReadString()));
            }
        }
Beispiel #6
0
 public IEnumerable <UnseenKey> UnseenKeys()
 {
     using (var trkv = _keyValueDb.StartReadOnlyTransaction())
     {
         foreach (var prefix in SupportedKeySpaces())
         {
             trkv.SetKeyPrefixUnsafe(prefix);
             if (!trkv.FindFirstKey())
             {
                 continue;
             }
             var reader = new KeyValueDBValueReader(trkv);
             do
             {
                 reader.Restart();
                 yield return(new UnseenKey
                 {
                     Key = Merge(prefix, trkv.GetKeyAsByteArray()),
                     ValueSize = reader.ReadVUInt32()
                 });
             } while (trkv.FindNextKey());
         }
     }
 }
Beispiel #7
0
 static IEnumerable<string> LoadTablesEnum(IKeyValueDBTransaction tr)
 {
     tr.SetKeyPrefix(TableNamesPrefix);
     var valueReader = new KeyValueDBValueReader(tr);
     while (tr.Enumerate())
     {
         valueReader.Restart();
         yield return valueReader.ReadString();
     }
 }