Exemplo n.º 1
0
        /// <exception cref="Db4objects.Db4o.Ext.OldFormatException"></exception>
        /// <exception cref="Db4objects.Db4o.Ext.DatabaseReadOnlyException"></exception>
        protected sealed override void OpenImpl()
        {
            Config4Impl configImpl = ConfigImpl;
            IStorage    storage    = configImpl.Storage;
            bool        isNew      = !storage.Exists(FileName());

            if (isNew)
            {
                LogMsg(14, FileName());
                CheckReadOnly();
                _handlers.OldEncryptionOff();
            }
            bool readOnly = configImpl.IsReadOnly();
            bool lockFile = Debug4.lockFile && configImpl.LockFile() && (!readOnly);

            if (NeedsLockFileThread())
            {
                IBin fileBin = storage.Open(new BinConfiguration(FileName(), false, 0, false, configImpl
                                                                 .BlockSize()));
                IBin synchronizedBin = new SynchronizedBin(fileBin);
                _file = new BlockAwareBin(synchronizedBin);
            }
            else
            {
                IBin bin = storage.Open(new BinConfiguration(FileName(), lockFile, 0, readOnly, configImpl
                                                             .BlockSize()));
                if (configImpl.AsynchronousSync())
                {
                    bin = new ThreadedSyncBin(bin);
                }
                _file = new BlockAwareBin(bin);
            }
            if (isNew)
            {
                ConfigureNewFile();
                if (configImpl.ReservedStorageSpace() > 0)
                {
                    Reserve(configImpl.ReservedStorageSpace());
                }
                CommitTransaction();
                WriteHeader(true, false);
            }
            else
            {
                ReadThis();
            }
        }