public void Remove(Transaction trans, int index) { if (!_isLeaf) { throw new InvalidOperationException(); } PrepareWrite(trans); SetStateDirty(); object obj = null; BTreePatch patch = KeyPatch(index); if (patch == null) { obj = _keys[index]; } else { BTreePatch transPatch = patch.ForTransaction(trans); if (transPatch != null) { obj = transPatch.GetObject(); } else { // There could be more than one patch with different object // identities. We have no means to determine a "best" object // so we just take any one. Could be problematic. obj = patch.GetObject(); } } Remove(trans, obj, index); }
private object InternalKey(Transaction trans, int index) { BTreePatch patch = KeyPatch(index); if (patch == null) { return(_keys[index]); } return(patch.Key(trans)); }
private bool WasRemoved(Transaction trans, Searcher s) { if (!s.FoundMatch()) { return(false); } BTreePatch patch = KeyPatch(trans, s.Cursor()); return(patch != null && patch.IsRemove()); }
internal void CommitOrRollback(Transaction trans, bool isCommit) { if (DTrace.enabled) { DTrace.BtreeNodeCommitOrRollback.Log(GetID()); } if (_dead) { return; } if (!_isLeaf) { return; } if (!IsDirty(trans)) { return; } object keyZero = _keys[0]; object[] tempKeys = new object[_btree.NodeSize()]; int count = 0; for (int i = 0; i < _count; i++) { object key = _keys[i]; BTreePatch patch = KeyPatch(i); if (patch != null) { key = isCommit ? patch.Commit(trans, _btree, this) : patch.Rollback(trans, _btree ); } if (key != No4.Instance) { tempKeys[count] = key; count++; } } _keys = tempKeys; _count = count; if (FreeIfEmpty(trans)) { return; } SetStateDirty(); // TODO: Merge nodes here on low _count value. if (_keys[0] != keyZero) { TellParentAboutChangedKey(trans); } }
public bool IndexIsValid(Transaction trans, int index) { if (!CanWrite()) { return(true); } BTreePatch patch = KeyPatch(index); if (patch == null) { return(true); } return(patch.Key(trans) != No4.Instance); }
public override object Key(Transaction trans) { BTreePatch patch = ForTransaction(trans); if (patch == null) { return(GetObject()); } if (patch.IsRemove()) { return(No4.Instance); } return(patch.GetObject()); }
public virtual Db4objects.Db4o.Internal.Btree.BTreeUpdate ReplacePatch(BTreePatch patch, Db4objects.Db4o.Internal.Btree.BTreeUpdate update) { if (patch == this) { update._next = _next; return(update); } if (_next == null) { throw new InvalidOperationException(); } _next = _next.ReplacePatch(patch, update); return(this); }
public virtual BTreeUpdate ReplacePatch(BTreePatch patch, BTreeUpdate update) { if (patch == this) { update._next = _next; return(update); } if (_next == null) { throw new InvalidOperationException(); } _next = _next.ReplacePatch(patch, update); return(this); }
public bool Remove(Transaction trans, object obj, int index) { if (!_isLeaf) { throw new InvalidOperationException(); } PrepareWrite(trans); SetStateDirty(); BTreePatch patch = KeyPatch(index); // no patch, no problem, can remove if (patch == null) { _keys[index] = ApplyNewRemovePatch(trans, obj); KeyChanged(trans, index); return(true); } BTreePatch transPatch = patch.ForTransaction(trans); if (transPatch != null) { if (transPatch.IsAdd()) { CancelAdding(trans, index); return(true); } if (transPatch.IsCancelledRemoval()) { BTreeRemove removePatch = ApplyNewRemovePatch(trans, transPatch.GetObject()); _keys[index] = ((BTreeUpdate)patch).ReplacePatch(transPatch, removePatch); KeyChanged(trans, index); return(true); } } else { // If the patch is a removal of a cancelled removal for another // transaction, we need one for this transaction also. if (!patch.IsAdd()) { ((BTreeUpdate)patch).Append(ApplyNewRemovePatch(trans, obj)); return(true); } } return(false); }
public int Size(Transaction trans) { PrepareRead(trans); if (!CanWrite()) { return(_count); } int size = 0; for (int i = 0; i < _count; i++) { BTreePatch keyPatch = KeyPatch(i); if (keyPatch != null) { size += keyPatch.SizeDiff(trans); } else { size++; } } return(size); }
public virtual BTreeUpdate ReplacePatch(BTreePatch patch, BTreeUpdate update) { if (patch == this) { update._next = _next; return update; } if (_next == null) { throw new InvalidOperationException(); } _next = _next.ReplacePatch(patch, update); return this; }
public virtual Db4objects.Db4o.Internal.Btree.BTreeUpdate ReplacePatch(BTreePatch patch, Db4objects.Db4o.Internal.Btree.BTreeUpdate update) { if (patch == this) { update._next = _next; return update; } if (_next == null) { throw new InvalidOperationException(); } _next = _next.ReplacePatch(patch, update); return this; }