Ejemplo n.º 1
0
  void configureNewFile() {

    blockSize(configImpl().blockSize());
    _fileHeader = FileHeader.newCurrentFileHeader();
    setRegularEndAddress(_fileHeader.length());

    newSystemData(configImpl().freespaceSystem(), configImpl().idSystemType());
    systemData().converterVersion(Converter.VERSION);
    createStringIO(_systemData.stringEncoding());
    createIdSystem();

    initializeClassMetadataRepository();
    initalizeWeakReferenceSupport();

    generateNewIdentity();

    AbstractFreespaceManager blockedFreespaceManager = AbstractFreespaceManager.createNew(this);
    installFreespaceManager(blockedFreespaceManager);

    initNewClassCollection();
    initializeEssentialClasses();

    _fileHeader.initNew(this);

    blockedFreespaceManager.start(0);
  }
Ejemplo n.º 2
0
  void readThis() throws OldFormatException {
    newSystemData(AbstractFreespaceManager.FM_LEGACY_RAM, StandardIdSystemFactory.LEGACY);
    blockSizeReadFromFile(1);

    _fileHeader = FileHeader.read(this);

    if (config().generateCommitTimestamps().isUnspecified()) {
      config().generateCommitTimestamps(_systemData.idToTimestampIndexId() != 0);
    }

    createStringIO(_systemData.stringEncoding());

    createIdSystem();

    initializeClassMetadataRepository();
    initalizeWeakReferenceSupport();

    setNextTimeStampId(systemData().lastTimeStampID());

    classCollection().setID(_systemData.classCollectionID());
    classCollection().read(systemTransaction());

    Converter.convert(new ConversionStage.ClassCollectionAvailableStage(this));

    _fileHeader.readIdentity(this);

    if (_config.isReadOnly()) {
      return;
    }

    if (!configImpl().commitRecoveryDisabled()) {
      _fileHeader.completeInterruptedTransaction(this);
    }

    FreespaceManager blockedFreespaceManager =
        AbstractFreespaceManager.createNew(this, _systemData.freespaceSystem());

    installFreespaceManager(blockedFreespaceManager);

    blockedFreespaceManager.read(this, _systemData.inMemoryFreespaceSlot());
    blockedFreespaceManager.start(_systemData.bTreeFreespaceId());

    _fileHeader = _fileHeader.convert(this);

    if (freespaceMigrationRequired(blockedFreespaceManager)) {
      migrateFreespace(blockedFreespaceManager);
    }

    writeHeader(true, false);

    if (Converter.convert(new ConversionStage.SystemUpStage(this))) {
      _systemData.converterVersion(Converter.VERSION);
      _fileHeader.writeVariablePart(this);
      transaction().commit();
    }
  }
Ejemplo n.º 3
0
  public void writeHeader(boolean startFileLockingThread, boolean shuttingDown) {
    if (shuttingDown) {
      _freespaceManager.write(this);
      _freespaceManager = null;
    }

    StatefulBuffer writer = createStatefulBuffer(systemTransaction(), 0, _fileHeader.length());

    _fileHeader.writeFixedPart(this, startFileLockingThread, shuttingDown, writer, blockSize());

    if (shuttingDown) {
      ensureLastSlotWritten();
    }
    syncFiles();
  }
Ejemplo n.º 4
0
  public void setIdentity(Db4oDatabase identity) {
    synchronized (lock()) {
      _systemData.identity(identity);

      // The dirty TimeStampIdGenerator triggers writing of
      // the variable part of the systemdata. We need to
      // make it dirty here, so the new identity is persisted:
      _timeStampIdGenerator.generate();

      _fileHeader.writeVariablePart(this);
    }
  }
Ejemplo n.º 5
0
  private void migrateFreespace(FreespaceManager oldFreespaceManager) {

    FreespaceManager newFreespaceManager =
        AbstractFreespaceManager.createNew(this, configImpl().freespaceSystem());
    newFreespaceManager.start(0);

    systemData().freespaceSystem(configImpl().freespaceSystem());

    installFreespaceManager(newFreespaceManager);

    AbstractFreespaceManager.migrate(oldFreespaceManager, newFreespaceManager);
    _fileHeader.writeVariablePart(this);
  }
Ejemplo n.º 6
0
 public Runnable commitHook() {
   _systemData.lastTimeStampID(_timeStampIdGenerator.last());
   return _fileHeader.commit(false);
 }
Ejemplo n.º 7
0
 public final void writeTransactionPointer(int pointer) {
   _fileHeader.writeTransactionPointer(systemTransaction(), pointer);
 }