private void Initialize()
        {
            int idToTimestampIndexId = _container.SystemData().IdToTimestampIndexId();
            int timestampToIdIndexId = _container.SystemData().TimestampToIdIndexId();

            _idToTimestamp = new BTree(_container.SystemTransaction(), idToTimestampIndexId,
                                       new CommitTimestampSupport.TimestampEntryById());
            _timestampToId = new BTree(_container.SystemTransaction(), timestampToIdIndexId,
                                       new CommitTimestampSupport.IdEntryByTimestamp());
            if (idToTimestampIndexId != _idToTimestamp.GetID())
            {
                StoreBtreesIds();
            }
            EventRegistryFactory.ForObjectContainer(_container).Committing += new System.EventHandler <Db4objects.Db4o.Events.CommitEventArgs>
                                                                                  (new _IEventListener4_69(this).OnEvent);
        }
		public override void WriteFixedPart(LocalObjectContainer file, bool startFileLockingThread
			, bool shuttingDown, StatefulBuffer writer, int blockSize)
		{
			SystemData systemData = file.SystemData();
			writer.Append(Signature);
			writer.WriteByte(Version());
			writer.WriteInt((int)TimeToWrite(_timerFileLock.OpenTime(), shuttingDown));
			writer.WriteLong(TimeToWrite(_timerFileLock.OpenTime(), shuttingDown));
			writer.WriteLong(TimeToWrite(Runtime.CurrentTimeMillis(), shuttingDown));
			writer.WriteInt(blockSize);
			writer.WriteInt(systemData.ClassCollectionID());
			writer.WriteByte(systemData.IdSystemType());
			writer.WriteInt(((FileHeaderVariablePart2)_variablePart).Address());
			writer.WriteInt(((FileHeaderVariablePart2)_variablePart).Length());
			writer.WriteInt(_transactionPointerAddress);
			writer.Write();
			if (shuttingDown)
			{
				WriteVariablePart(file, true);
			}
			else
			{
				file.SyncFiles();
			}
			if (startFileLockingThread)
			{
				file.ThreadPool().Start("db4o lock thread", _timerFileLock);
			}
		}
        private void EnsureIndex(Transaction transaction)
        {
            if (null == transaction)
            {
                throw new ArgumentNullException();
            }
            if (null != base.GetIndex(transaction))
            {
                return;
            }
            LocalObjectContainer file = ((LocalObjectContainer)transaction.Container());
            SystemData           sd   = file.SystemData();

            if (sd == null)
            {
                // too early, in new file, try again later.
                return;
            }
            InitIndex(transaction, sd.UuidIndexId());
            if (sd.UuidIndexId() == 0)
            {
                sd.UuidIndexId(base.GetIndex(transaction).GetID());
                file.GetFileHeader().WriteVariablePart(file);
            }
        }
		public BTreeFreespaceManager(LocalObjectContainer file, IProcedure4 slotFreedCallback
			, int discardLimit) : base(slotFreedCallback, discardLimit)
		{
			_file = file;
			_delegate = new InMemoryFreespaceManager(slotFreedCallback, discardLimit);
			_idSystem = file.SystemData().FreespaceIdSystem();
		}
Beispiel #5
0
		protected override void Read(LocalObjectContainer file, ByteArrayBuffer reader)
		{
			NewTimerFileLock(file);
			OldEncryptionOff(file);
			CheckThreadFileLock(file, reader);
			reader.Seek(TransactionPointerOffset);
			file.SystemData().TransactionPointer1(reader.ReadInt());
			file.SystemData().TransactionPointer2(reader.ReadInt());
			reader.Seek(BlocksizeOffset);
			file.BlockSizeReadFromFile(reader.ReadInt());
			SystemData systemData = file.SystemData();
			systemData.ClassCollectionID(reader.ReadInt());
			reader.ReadInt();
			// was freespace ID, can no longer be read
			_variablePart = CreateVariablePart(file);
			int variablePartId = reader.ReadInt();
			_variablePart.Read(variablePartId, 0);
		}
		public static IIdSystem NewInstance(LocalObjectContainer localContainer)
		{
			SystemData systemData = localContainer.SystemData();
			byte idSystemType = systemData.IdSystemType();
			switch (idSystemType)
			{
				case Legacy:
				{
					return new PointerBasedIdSystem(localContainer);
				}

				case PointerBased:
				{
					return new PointerBasedIdSystem(localContainer);
				}

				case StackedBtree:
				{
					InMemoryIdSystem inMemoryIdSystem = new InMemoryIdSystem(localContainer);
					BTreeIdSystem bTreeIdSystem = new BTreeIdSystem(localContainer, inMemoryIdSystem);
					systemData.FreespaceIdSystem(bTreeIdSystem.FreespaceIdSystem());
					return new BTreeIdSystem(localContainer, bTreeIdSystem);
				}

				case SingleBtree:
				{
					InMemoryIdSystem smallInMemoryIdSystem = new InMemoryIdSystem(localContainer);
					BTreeIdSystem smallBTreeIdSystem = new BTreeIdSystem(localContainer, smallInMemoryIdSystem
						);
					systemData.FreespaceIdSystem(smallBTreeIdSystem.FreespaceIdSystem());
					return smallBTreeIdSystem;
				}

				case InMemory:
				{
					return new InMemoryIdSystem(localContainer);
				}

				case Custom:
				{
					IIdSystemFactory customIdSystemFactory = localContainer.ConfigImpl.CustomIdSystemFactory
						();
					if (customIdSystemFactory == null)
					{
						throw new Db4oFatalException("Custom IdSystem configured but no factory was found. See IdSystemConfiguration#useCustomSystem()"
							);
					}
					return customIdSystemFactory.NewInstance(localContainer);
				}

				default:
				{
					return new PointerBasedIdSystem(localContainer);
					break;
				}
			}
		}
		protected override void Read(LocalObjectContainer container, ByteArrayBuffer reader
			)
		{
			NewTimerFileLock(container);
			OldEncryptionOff(container);
			CheckThreadFileLock(container, reader);
			reader.Seek(BlocksizeOffset);
			container.BlockSizeReadFromFile(reader.ReadInt());
			SystemData systemData = container.SystemData();
			systemData.ClassCollectionID(reader.ReadInt());
			container.SystemData().IdSystemType(reader.ReadByte());
			_variablePart = CreateVariablePart(container);
			int variablePartAddress = reader.ReadInt();
			int variablePartLength = reader.ReadInt();
			_variablePart.Read(variablePartAddress, variablePartLength);
			_transactionPointerAddress = reader.ReadInt();
			if (_transactionPointerAddress != 0)
			{
				ByteArrayBuffer buffer = new ByteArrayBuffer(TransactionPointerLength);
				buffer.Read(container, _transactionPointerAddress, 0);
				systemData.TransactionPointer1(buffer.ReadInt());
				systemData.TransactionPointer2(buffer.ReadInt());
			}
		}
Beispiel #8
0
		public override void CompleteInterruptedTransaction(LocalObjectContainer container
			)
		{
			SystemData systemData = container.SystemData();
			container.IdSystem().CompleteInterruptedTransaction(systemData.TransactionPointer1
				(), systemData.TransactionPointer2());
		}
		public override void Write(LocalObjectContainer container)
		{
			Slot slot = container.AllocateSlot(MarshalledLength());
			while (slot.Length() < MarshalledLength())
			{
				// This can happen if DatabaseGrowthSize is configured.
				// Allocating a slot may produce an additional entry
				// in this FreespaceManager.
				container.Free(slot);
				slot = container.AllocateSlot(MarshalledLength());
			}
			ByteArrayBuffer buffer = new ByteArrayBuffer(slot.Length());
			TreeInt.Write(buffer, (TreeInt)_freeBySize);
			container.WriteEncrypt(buffer, slot.Address(), 0);
			container.SystemData().InMemoryFreespaceSlot(slot);
		}
		public static Db4objects.Db4o.Internal.Freespace.AbstractFreespaceManager CreateNew
			(LocalObjectContainer file)
		{
			return CreateNew(file, file.SystemData().FreespaceSystem());
		}
		public override void Write(LocalObjectContainer container)
		{
			try
			{
				BeginDelegation();
				_delegate.Write(container);
				container.SystemData().BTreeFreespaceId(_idArray.GetID());
			}
			finally
			{
				EndDelegation();
			}
		}