/// <param name="objectWriter"> The object writer </param> /// <param name="objectReader"> The object reader </param> /// <param name="currentIdBlock">Current Id block data </param> public IdManager(IObjectWriter objectWriter, IObjectReader objectReader, CurrentIdBlockInfo currentIdBlock) { _objectWriter = objectWriter; _objectReader = objectReader; _currentBlockIdPosition = currentIdBlock.CurrentIdBlockPosition; _currentBlockIdNumber = currentIdBlock.CurrentIdBlockNumber; _maxId = new ObjectOID((long)currentIdBlock.CurrentIdBlockNumber * StorageEngineConstant.NbIdsPerBlock); _nextId = new ObjectOID(currentIdBlock.CurrentIdBlockMaxOid.ObjectId + 1); _lastIds = new OID[IdBufferSize]; for (var i = 0; i < IdBufferSize; i++) _lastIds[i] = StorageEngineConstant.NullObjectId; _lastIdPositions = new long[IdBufferSize]; _lastIdIndex = 0; }
public void ReadDatabaseHeader() { var version = ReadDatabaseVersion(); StorageEngineConstant.CheckDbVersionCompatibility(version); var databaseIdsArray = new long[4]; databaseIdsArray[0] = _fsi.ReadLong(); databaseIdsArray[1] = _fsi.ReadLong(); databaseIdsArray[2] = _fsi.ReadLong(); databaseIdsArray[3] = _fsi.ReadLong(); IDatabaseId databaseId = new DatabaseId(databaseIdsArray); var nbClasses = ReadNumberOfClasses(); var firstClassPosition = ReadFirstClassOid(); if (nbClasses < 0) { throw new CorruptedDatabaseException( NDatabaseError.NegativeClassNumberInHeader.AddParameter(nbClasses).AddParameter(firstClassPosition)); } ReadLastOdbCloseStatus(); ReadDatabaseCharacterEncoding(); var currentBlockPosition = _fsi.ReadLong(); // Gets the current id block number _fsi.SetReadPosition(currentBlockPosition + StorageEngineConstant.BlockIdOffsetForBlockNumber); var currentBlockIdNumber = _fsi.ReadInt(); var blockMaxId = OIDFactory.BuildObjectOID(_fsi.ReadLong()); _storageEngine.SetDatabaseId(databaseId); var currentBlockInfo = new CurrentIdBlockInfo { CurrentIdBlockPosition = currentBlockPosition, CurrentIdBlockNumber = currentBlockIdNumber, CurrentIdBlockMaxOid = blockMaxId }; _storageEngine.SetCurrentIdBlockInfos(currentBlockInfo); }
/// <summary> /// Creates the header of the file /// </summary> /// <param name="storageEngine">Storage engine </param> /// <param name="creationDate"> The creation date </param> public void CreateEmptyDatabaseHeader(IStorageEngine storageEngine, long creationDate) { WriteVersion(); WriteDatabaseId(storageEngine, creationDate); WriteNumberOfClasses(0, false); WriteFirstClassInfoOID(StorageEngineConstant.NullObjectId, false); WriteLastOdbCloseStatus(false, false); WriteDatabaseCharacterEncoding(); // This is the position of the first block id. But it will always contain the position of the current id block FileSystemInterface.WriteLong(StorageEngineConstant.DatabaseHeaderFirstIdBlockPosition, false); // current id block position // Write an empty id block WriteIdBlock(-1, StorageEngineConstant.IdBlockSize, BlockStatus.BlockNotFull, 1, -1, false); Flush(); var currentBlockInfo = new CurrentIdBlockInfo { CurrentIdBlockPosition = StorageEngineConstant.DatabaseHeaderFirstIdBlockPosition, CurrentIdBlockNumber = 1, CurrentIdBlockMaxOid = OIDFactory.BuildObjectOID(0) }; storageEngine.SetCurrentIdBlockInfos(currentBlockInfo); }