public static void AssertEmpty(Transaction transaction, BTree tree)
		{
			ExpectingVisitor visitor = new ExpectingVisitor(new object[0]);
			tree.TraverseKeys(transaction, visitor);
			visitor.AssertExpectations();
			Assert.AreEqual(0, tree.Size(transaction));
		}
示例#2
0
 /// <exception cref="System.Exception"></exception>
 private BTree CycleIntKeys(BTree btree)
 {
     AddKeys(btree);
     ExpectKeys(btree, _sortedKeys);
     btree.Commit(Trans());
     ExpectKeys(btree, _sortedKeys);
     RemoveKeys(btree);
     ExpectKeys(btree, _keysOnRemoval);
     btree.Rollback(Trans());
     ExpectKeys(btree, _sortedKeys);
     var id = btree.GetID();
     Reopen();
     btree = BTreeAssert.CreateIntKeyBTree(Container(), id, BtreeNodeSize);
     ExpectKeys(btree, _sortedKeys);
     RemoveKeys(btree);
     ExpectKeys(btree, _keysOnRemoval);
     btree.Commit(Trans());
     ExpectKeys(btree, _keysOnRemoval);
     // remove all but 1
     for (var i = 1; i < _keysOnRemoval.Length; i++)
     {
         btree.Remove(Trans(), _keysOnRemoval[i]);
     }
     ExpectKeys(btree, _one);
     btree.Commit(Trans());
     ExpectKeys(btree, _one);
     btree.Remove(Trans(), 1);
     btree.Rollback(Trans());
     ExpectKeys(btree, _one);
     btree.Remove(Trans(), 1);
     btree.Commit(Trans());
     ExpectKeys(btree, _none);
     return btree;
 }
示例#3
0
		public override object Commit(Transaction trans, BTree btree, BTreeNode node)
		{
			if (_transaction == trans)
			{
				return GetObject();
			}
			return this;
		}
示例#4
0
		public override object Rollback(Transaction trans, BTree btree)
		{
			if (_transaction == trans)
			{
				return RolledBack(btree);
			}
			return this;
		}
示例#5
0
		private void CreateBTreeIndex(ObjectContainerBase stream, int btreeID)
		{
			if (stream.IsClient)
			{
				return;
			}
			_btreeIndex = ((LocalObjectContainer)stream).CreateBTreeClassIndex(btreeID);
			_btreeIndex.SetRemoveListener(new _IVisitor4_61(this));
		}
		private void CreateBTrees(int addressID, int lengthID)
		{
			BTreeConfiguration config = new BTreeConfiguration(_idSystem, SlotChangeFactory.FreeSpace
				, 64, false);
			_slotsByAddress = new BTree(Transaction(), config, addressID, new AddressKeySlotHandler
				());
			_slotsByLength = new BTree(Transaction(), config, lengthID, new LengthKeySlotHandler
				());
		}
示例#7
0
 public BigSet(LocalObjectContainer db)
 {
     if (db == null)
     {
         return;
     }
     _transaction = db.Transaction;
     _bTree       = BTreeManager().NewBTree();
 }
示例#8
0
		public BTreeNode(BTree btree, int count, bool isLeaf, int parentID, int previousID
			, int nextID)
		{
			_btree = btree;
			_parentID = parentID;
			_previousID = previousID;
			_nextID = nextID;
			_count = count;
			_isLeaf = isLeaf;
			PrepareArrays();
		}
示例#9
0
        public virtual void Read(IReadContext context)
        {
            int id = context.ReadInt();

            if (_bTree != null)
            {
                AssertCurrentBTreeId(id);
                return;
            }
            _transaction = context.Transaction();
            _bTree       = BTreeManager().ProduceBTree(id);
        }
示例#10
0
		public BTreeRangeSingle(Db4objects.Db4o.Internal.Transaction transaction, BTree btree
			, BTreePointer first, BTreePointer end)
		{
			if (transaction == null || btree == null)
			{
				throw new ArgumentNullException();
			}
			_transaction = transaction;
			_btree = btree;
			_first = first;
			_end = end;
		}
		internal BTreeNodeSearchResult(Transaction transaction, BTree btree, BTreePointer
			 pointer, bool foundMatch)
		{
			if (null == transaction || null == btree)
			{
				throw new ArgumentNullException();
			}
			_transaction = transaction;
			_btree = btree;
			_pointer = pointer;
			_foundMatch = foundMatch;
		}
示例#12
0
		public static void AssertSingleElement(Transaction trans, BTree btree, object element
			)
		{
			Assert.AreEqual(1, btree.Size(trans));
			IBTreeRange result = btree.SearchRange(trans, element);
			ExpectingVisitor expectingVisitor = new ExpectingVisitor(new object[] { element }
				);
			BTreeAssert.TraverseKeys(result, expectingVisitor);
			expectingVisitor.AssertExpectations();
			expectingVisitor = new ExpectingVisitor(new object[] { element });
			btree.TraverseKeys(trans, expectingVisitor);
			expectingVisitor.AssertExpectations();
		}
		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);
		}
示例#14
0
		public virtual void Convert(LocalObjectContainer container, int classIndexId, BTree
			 bTree)
		{
			Transaction trans = container.SystemTransaction();
			ByteArrayBuffer reader = container.ReadBufferById(trans, classIndexId);
			if (reader == null)
			{
				return;
			}
			int entries = reader.ReadInt();
			for (int i = 0; i < entries; i++)
			{
				bTree.Add(trans, reader.ReadInt());
			}
		}
示例#15
0
		private void ExpectKeysSearch(BTree btree, int[] values)
		{
			int lastValue = int.MinValue;
			for (int i = 0; i < values.Length; i++)
			{
				if (values[i] != lastValue)
				{
					ExpectingVisitor expectingVisitor = ExpectingVisitor.CreateExpectingVisitor(values
						[i], IntArrays4.Occurences(values, values[i]));
					IBTreeRange range = FieldIndexKeySearch(Trans(), btree, values[i]);
					BTreeAssert.TraverseKeys(range, new _IVisitor4_62(expectingVisitor));
					expectingVisitor.AssertExpectations();
					lastValue = values[i];
				}
			}
		}
示例#16
0
		private void ExpectKeysSearch(Transaction trans, BTree btree, int[] keys)
		{
			int lastValue = int.MinValue;
			for (int i = 0; i < keys.Length; i++)
			{
				if (keys[i] != lastValue)
				{
					ExpectingVisitor expectingVisitor = ExpectingVisitor.CreateExpectingVisitor(keys[
						i], IntArrays4.Occurences(keys, keys[i]));
					IBTreeRange range = btree.SearchRange(trans, keys[i]);
					BTreeAssert.TraverseKeys(range, expectingVisitor);
					expectingVisitor.AssertExpectations();
					lastValue = keys[i];
				}
			}
		}
示例#17
0
		public override object Commit(Transaction trans, BTree btree, BTreeNode node)
		{
			Db4objects.Db4o.Internal.Btree.BTreeUpdate patch = (Db4objects.Db4o.Internal.Btree.BTreeUpdate
				)ForTransaction(trans);
			if (patch is BTreeCancelledRemoval)
			{
				object obj = patch.GetCommittedObject();
				ApplyKeyChange(obj);
			}
			else
			{
				if (patch is BTreeRemove)
				{
					RemovedBy(trans, btree, node);
					patch.Committed(btree);
					return No4.Instance;
				}
			}
			return InternalCommit(trans, btree);
		}
示例#18
0
 private void Initialize()
 {
     var idToTimestampIndexId = _container.SystemData().IdToTimestampIndexId();
     var timestampToIdIndexId = _container.SystemData().TimestampToIdIndexId();
     if (_container.Config().IsReadOnly())
     {
         if (idToTimestampIndexId == 0)
         {
             return;
         }
     }
     _idToTimestamp = new BTree(_container.SystemTransaction(), idToTimestampIndexId,
         new TimestampEntryById());
     _timestampToId = new BTree(_container.SystemTransaction(), timestampToIdIndexId,
         new IdEntryByTimestamp());
     if (idToTimestampIndexId != _idToTimestamp.GetID())
     {
         StoreBtreesIds();
     }
     EventRegistryFactory.ForObjectContainer(_container).Committing += new _IEventListener4_65(this).OnEvent;
 }
示例#19
0
		/// <exception cref="System.Exception"></exception>
		private BTree CycleIntKeys(BTree btree, int[] values)
		{
			for (int i = 0; i < values.Length; i++)
			{
				btree.Add(Trans(), values[i]);
			}
			ExpectKeysSearch(Trans(), btree, values);
			btree.Commit(Trans());
			int id = btree.GetID();
			Container().Commit(Trans());
			Reopen();
			btree = BTreeAssert.CreateIntKeyBTree(Container(), id, BtreeNodeSize);
			ExpectKeysSearch(Trans(), btree, values);
			for (int i = 0; i < values.Length; i++)
			{
				btree.Remove(Trans(), values[i]);
			}
			BTreeAssert.AssertEmpty(Trans(), btree);
			btree.Commit(Trans());
			BTreeAssert.AssertEmpty(Trans(), btree);
			return btree;
		}
示例#20
0
 protected abstract void Committed(BTree btree);
示例#21
0
		public static int[] NewBTreeNodeSizedArray(BTree btree, int value)
		{
			return IntArrays4.Fill(new int[FillSize(btree)], value);
		}
		internal BTreeNodeSearchResult(Transaction trans, ByteArrayBuffer nodeReader, BTree
			 btree, BTreeNode node, int cursor, bool foundMatch) : this(trans, btree, PointerOrNull
			(trans, nodeReader, node, cursor), foundMatch)
		{
		}
示例#23
0
		public static void AssertKeys(Transaction transaction, BTree btree, int[] keys)
		{
			ExpectingVisitor visitor = ExpectingVisitor.CreateExpectingVisitor(keys);
			btree.TraverseKeys(transaction, visitor);
			visitor.AssertExpectations();
		}
示例#24
0
		public static void DumpKeys(Transaction trans, BTree tree)
		{
			tree.TraverseKeys(trans, new _IVisitor4_37());
		}
		private void InitializeExisting(int persistentArrayId)
		{
			_persistentState = new PersistentIntegerArray(SlotChangeFactory.IdSystem, _transactionalIdSystem
				, persistentArrayId);
			_persistentState.Read(Transaction());
			_bTree = new BTree(Transaction(), BTreeConfiguration(), BTreeId(), new BTreeIdSystem.IdSlotMappingHandler
				());
		}
示例#26
0
 public _IVisitor4_311(BTree _enclosing)
 {
     this._enclosing = _enclosing;
 }
 protected override void AdjustSizeOnRemovalByOtherTransaction(BTree btree, BTreeNode
                                                               node)
 {
 }
示例#28
0
 protected override void AdjustSizeOnRemovalByOtherTransaction(BTree btree, BTreeNode
                                                               node)
 {
     // The size was reduced for this entry, let's change back.
     btree.SizeChanged(_transaction, node, +1);
 }
示例#29
0
		internal virtual void EnsureIsManaged(BTree tree)
		{
			RegisterBTreeInTransaction(tree);
		}
 internal BTreeNodeSearchResult(Transaction trans, ByteArrayBuffer nodeReader, BTree
                                btree, BTreeNode node, int cursor, bool foundMatch) : this(trans, btree, PointerOrNull
                                                                                               (trans, nodeReader, node, cursor), foundMatch)
 {
 }
示例#31
0
 private Db4objects.Db4o.Internal.Btree.BTree BTreeForUpdate()
 {
     Db4objects.Db4o.Internal.Btree.BTree bTree = BTree();
     BTreeManager().EnsureIsManaged(bTree);
     return(bTree);
 }
示例#32
0
 public virtual void Invalidate()
 {
     _bTree = null;
 }
 internal BTreeNodeSearchResult(Transaction trans, ByteArrayBuffer nodeReader, BTree
                                btree, Searcher searcher, BTreeNode node) : this(trans, btree, NextPointerIf(PointerOrNull
                                                                                                                 (trans, nodeReader, node, searcher.Cursor()), searcher.IsGreater()), searcher.FoundMatch
                                                                                     ())
 {
 }
示例#34
0
 public _IVisitor4_486(BTree _enclosing, IDefragmentServices services)
 {
     this._enclosing = _enclosing;
     this.services   = services;
 }
示例#35
0
 public BTreeNode(int id, BTree btree)
 {
     _btree = btree;
     SetID(id);
     SetStateDeactivated();
 }
示例#36
0
 public _ISlotCopyHandler_481(BTree _enclosing)
 {
     this._enclosing = _enclosing;
 }
示例#37
0
 public BTreeIterator(Transaction trans, BTree bTree)
 {
     _transaction = trans;
     _bTree       = bTree;
 }
		private void InitializeNew()
		{
			_bTree = new BTree(Transaction(), BTreeConfiguration(), new BTreeIdSystem.IdSlotMappingHandler
				());
			int idGeneratorValue = _container.Handlers.LowestValidId() - 1;
			_persistentState = new PersistentIntegerArray(SlotChangeFactory.IdSystem, _transactionalIdSystem
				, new int[] { _bTree.GetID(), idGeneratorValue, 0 });
			_persistentState.Write(Transaction());
			_parentIdSystem.ChildId(_persistentState.GetID());
		}
示例#39
0
 protected virtual object RolledBack(BTree btree)
 {
     btree.NotifyRemoveListener(new TransactionContext(_transaction, GetObject()));
     return(No4.Instance);
 }
示例#40
0
		/// <exception cref="System.Exception"></exception>
		public static void AssertAllSlotsFreed(LocalTransaction trans, BTree bTree, ICodeBlock
			 block)
		{
			LocalObjectContainer container = (LocalObjectContainer)trans.Container();
			ITransactionalIdSystem idSystem = trans.IdSystem();
			IEnumerator allSlotIDs = bTree.AllNodeIds(trans.SystemTransaction());
			Collection4 allSlots = new Collection4();
			while (allSlotIDs.MoveNext())
			{
				int slotID = ((int)allSlotIDs.Current);
				Slot slot = idSystem.CurrentSlot(slotID);
				allSlots.Add(slot);
			}
			Slot bTreeSlot = idSystem.CurrentSlot(bTree.GetID());
			allSlots.Add(bTreeSlot);
			Collection4 freedSlots = new Collection4();
			IFreespaceManager freespaceManager = container.FreespaceManager();
			container.InstallDebugFreespaceManager(new FreespaceManagerForDebug(new _ISlotListener_99
				(freedSlots)));
			block.Run();
			container.InstallDebugFreespaceManager(freespaceManager);
			Assert.IsTrue(freedSlots.ContainsAll(allSlots.GetEnumerator()));
		}
示例#41
0
 protected override void Committed(BTree btree)
 {
     btree.NotifyRemoveListener(new TransactionContext(_transaction, GetObject()));
 }
示例#42
0
 public abstract object Rollback(Transaction trans, BTree btree);
示例#43
0
		public BTreeIterator(Transaction trans, BTree bTree)
		{
			_transaction = trans;
			_bTree = bTree;
		}
示例#44
0
		public static int FillSize(BTree btree)
		{
			return btree.NodeSize() + 1;
		}
示例#45
0
 public _IProcedure4_609(BTree _enclosing)
 {
     this._enclosing = _enclosing;
 }
示例#46
0
 public abstract object Commit(Transaction trans, BTree btree, BTreeNode node);
示例#47
0
		protected virtual object RolledBack(BTree btree)
		{
			btree.NotifyRemoveListener(new TransactionContext(_transaction, GetObject()));
			return No4.Instance;
		}
		internal BTreeNodeSearchResult(Transaction trans, ByteArrayBuffer nodeReader, BTree
			 btree, Searcher searcher, BTreeNode node) : this(trans, btree, NextPointerIf(PointerOrNull
			(trans, nodeReader, node, searcher.Cursor()), searcher.IsGreater()), searcher.FoundMatch
			())
		{
		}
示例#49
0
 protected abstract void AdjustSizeOnRemovalByOtherTransaction(BTree btree, BTreeNode
                                                               node);
示例#50
0
		private void RegisterBTreeInTransaction(BTree tree)
		{
			AssertValidBTreeId(tree.GetID());
			BTreesIn(_transaction)[tree.GetID()] = tree;
		}
 protected override void Committed(BTree btree)
 {
 }