Beispiel #1
0
 public void Open(IKeyValueDB keyValueDB, bool dispose)
 {
     if (keyValueDB == null)
     {
         throw new ArgumentNullException(nameof(keyValueDB));
     }
     _keyValueDB            = keyValueDB;
     _dispose               = dispose;
     _tableInfoResolver     = new TableInfoResolver(keyValueDB, this);
     _tablesInfo            = new TablesInfo(_tableInfoResolver);
     _relationsInfoResolver = new RelationInfoResolver(this);
     _relationsInfo         = new RelationsInfo(_relationsInfoResolver);
     _lastObjId             = 0;
     using (var tr = _keyValueDB.StartTransaction())
     {
         tr.SetKeyPrefix(AllObjectsPrefix);
         if (tr.FindLastKey())
         {
             _lastObjId = (long)new KeyValueDBKeyReader(tr).ReadVUInt64();
         }
         _tablesInfo.LoadTables(LoadTablesEnum(tr));
         _relationsInfo.LoadRelations(LoadRelationNamesEnum(tr));
         tr.SetKeyPrefix(null);
         if (tr.FindExactKey(LastDictIdKey))
         {
             _lastDictId = new ByteArrayReader(tr.GetValueAsByteArray()).ReadVUInt64();
         }
     }
 }
Beispiel #2
0
        public void Open(IKeyValueDB keyValueDB, bool dispose, DBOptions options)
        {
            _keyValueDB = keyValueDB ?? throw new ArgumentNullException(nameof(keyValueDB));
            _dispose    = dispose;
            _type2Name  = options.CustomType2NameRegistry ?? new Type2NameRegistry();
            _polymorphicTypesRegistry = new PolymorphicTypesRegistry();
            AutoRegisterTypes         = options.AutoRegisterType;
            ActualOptions             = options;
            SymmetricCipher           = options.SymmetricCipher ?? new InvalidSymmetricCipher();

            _tableInfoResolver     = new TableInfoResolver(keyValueDB, this);
            _tablesInfo            = new TablesInfo(_tableInfoResolver);
            _relationsInfoResolver = new RelationInfoResolver(this);
            _relationsInfo         = new RelationsInfo(_relationsInfoResolver);

            using var tr = _keyValueDB.StartTransaction();
            _lastObjId   = (long)tr.GetUlong(0);
            _lastDictId  = tr.GetUlong(1);
            if (_lastObjId == 0)
            {
                if (tr.FindLastKey(AllObjectsPrefix))
                {
                    _lastObjId = (long)PackUnpack.UnpackVUInt(tr.GetKey().Slice(AllObjectsPrefixLen));
                }
            }
            _tablesInfo.LoadTables(LoadTablesEnum(tr));
            _relationsInfo.LoadRelations(LoadRelationNamesEnum(tr));
            if (_lastDictId == 0)
            {
                if (tr.FindExactKey(LastDictIdKey))
                {
                    _lastDictId = PackUnpack.UnpackVUInt(tr.GetValue());
                }
            }
        }
Beispiel #3
0
        public void Open(IKeyValueDB keyValueDB, bool dispose, DBOptions options)
        {
            if (keyValueDB == null)
            {
                throw new ArgumentNullException(nameof(keyValueDB));
            }
            _keyValueDB = keyValueDB;
            _dispose    = dispose;
            _type2Name  = options.CustomType2NameRegistry ?? new Type2NameRegistry();
            _polymorphicTypesRegistry = new PolymorphicTypesRegistry();
            AutoRegisterTypes         = options.AutoRegisterType;
            ActualOptions             = options;
            _symmetricCipher          = options.SymmetricCipher ?? new InvalidSymmetricCipher();

            _tableInfoResolver     = new TableInfoResolver(keyValueDB, this);
            _tablesInfo            = new TablesInfo(_tableInfoResolver);
            _relationsInfoResolver = new RelationInfoResolver(this);
            _relationsInfo         = new RelationsInfo(_relationsInfoResolver);

            using (var tr = _keyValueDB.StartTransaction())
            {
                _lastObjId  = (long)tr.GetUlong(0);
                _lastDictId = tr.GetUlong(1);
                if (_lastObjId == 0)
                {
                    tr.SetKeyPrefix(AllObjectsPrefix);
                    if (tr.FindLastKey())
                    {
                        _lastObjId = (long)new KeyValueDBKeyReader(tr).ReadVUInt64();
                    }
                }
                _tablesInfo.LoadTables(LoadTablesEnum(tr));
                _relationsInfo.LoadRelations(LoadRelationNamesEnum(tr));
                if (_lastDictId == 0)
                {
                    tr.SetKeyPrefix(null);
                    if (tr.FindExactKey(LastDictIdKey))
                    {
                        _lastDictId = new ByteArrayReader(tr.GetValueAsByteArray()).ReadVUInt64();
                    }
                }
            }
        }
Beispiel #4
0
        public RelationInfo(uint id, string name, IRelationInfoResolver relationInfoResolver, Type interfaceType,
                            Type clientType, IInternalObjectDBTransaction tr)
        {
            _id   = id;
            _name = name;
            _relationInfoResolver     = relationInfoResolver;
            _interfaceType            = interfaceType;
            _clientType               = clientType;
            ClientRelationVersionInfo = CreateVersionInfoByReflection();
            LoadVersionInfos(tr.KeyValueDBTransaction);
            ApartFields = FindApartFields(interfaceType, ClientRelationVersionInfo);
            if (LastPersistedVersion > 0 && RelationVersionInfo.Equal(_relationVersions[LastPersistedVersion], ClientRelationVersionInfo))
            {
                _relationVersions[LastPersistedVersion] = ClientRelationVersionInfo;
                ClientTypeVersion = LastPersistedVersion;
            }
            else
            {
                ClientTypeVersion = LastPersistedVersion + 1;
                _relationVersions.Add(ClientTypeVersion, ClientRelationVersionInfo);
                var writerk = new ByteBufferWriter();
                writerk.WriteByteArrayRaw(ObjectDB.RelationVersionsPrefix);
                writerk.WriteVUInt32(_id);
                writerk.WriteVUInt32(ClientTypeVersion);
                var writerv = new ByteBufferWriter();
                ClientRelationVersionInfo.Save(writerv);
                tr.KeyValueDBTransaction.SetKeyPrefix(ByteBuffer.NewEmpty());
                tr.KeyValueDBTransaction.CreateOrUpdateKeyValue(writerk.Data, writerv.Data);

                if (LastPersistedVersion > 0)
                {
                    CheckThatPrimaryKeyHasNotChanged(name, ClientRelationVersionInfo, _relationVersions[LastPersistedVersion]);
                    UpdateSecondaryKeys(tr, ClientRelationVersionInfo, _relationVersions[LastPersistedVersion]);
                }
            }
            _typeConvertorGenerator = tr.Owner.TypeConvertorGenerator;
        }
Beispiel #5
0
 public RelationsInfo(IRelationInfoResolver relationInfoResolver)
 {
     _relationInfoResolver = relationInfoResolver;
 }
Beispiel #6
0
 public void Open(IKeyValueDB keyValueDB, bool dispose)
 {
     if (keyValueDB == null) throw new ArgumentNullException(nameof(keyValueDB));
     _keyValueDB = keyValueDB;
     _dispose = dispose;
     _tableInfoResolver = new TableInfoResolver(keyValueDB, this);
     _tablesInfo = new TablesInfo(_tableInfoResolver);
     _relationsInfoResolver = new RelationInfoResolver(this);
     _relationsInfo = new RelationsInfo(_relationsInfoResolver);
     _lastObjId = 0;
     using (var tr = _keyValueDB.StartTransaction())
     {
         tr.SetKeyPrefix(AllObjectsPrefix);
         if (tr.FindLastKey())
         {
             _lastObjId = (long)new KeyValueDBKeyReader(tr).ReadVUInt64();
         }
         _tablesInfo.LoadTables(LoadTablesEnum(tr));
         _relationsInfo.LoadRelations(LoadRelationNamesEnum(tr));
         tr.SetKeyPrefix(null);
         if (tr.FindExactKey(LastDictIdKey))
         {
             _lastDictId = new ByteArrayReader(tr.GetValueAsByteArray()).ReadVUInt64();
         }
     }
 }
Beispiel #7
0
 public RelationsInfo(IRelationInfoResolver relationInfoResolver)
 {
     _relationInfoResolver = relationInfoResolver;
 }