public virtual void Insert(Session session, IPersistentStore store, Row row) { bool useRowId = !this.isUnique || this.HasNulls(row.RowData); Monitor.Enter(this._lock); store.LockStore(); try { bool flag2; NodeAVL eavl2; Constraint uniqueConstraintForIndex; Row row2; RowAVL wavl = (RowAVL)row; NodeAVL accessor = this.GetAccessor(store); if (accessor == null) { store.SetAccessor(this, wavl.GetNode(this.Position)); store.SetElementCount(this, 1, 1); return; } Label_005C: row2 = accessor.GetRow(store); int num = this.CompareRowForInsertOrDelete(session, row, row2, useRowId, 0); if ((((num == 0) && (session != null)) && (!useRowId && session.database.TxManager.IsMvRows())) && !this.IsEqualReadable(session, store, accessor)) { useRowId = true; num = this.CompareRowForInsertOrDelete(session, row, row2, useRowId, this.ColIndex.Length); } if (num != 0) { flag2 = num < 0; eavl2 = accessor; accessor = eavl2.Child(store, flag2); if (accessor != null) { goto Label_005C; } } else { uniqueConstraintForIndex = null; if (this.isConstraint) { uniqueConstraintForIndex = ((Table)this.table).GetUniqueConstraintForIndex(this); } goto Label_0119; } eavl2 = eavl2.Set(store, flag2, wavl.GetNode(this.Position)); this.Balance(store, eavl2, flag2); store.UpdateElementCount(this, 1, 1); return; Label_0119: if (uniqueConstraintForIndex == null) { throw Error.GetError(0x68, this.Name.StatementName); } throw uniqueConstraintForIndex.GetException(row.RowData); } finally { store.UnlockStore(); Monitor.Exit(this._lock); } }
public virtual void Delete(IPersistentStore store, NodeAVL x) { if (x != null) { Monitor.Enter(this._lock); store.LockStore(); try { NodeAVL parent; if (x.GetLeft(store) == null) { parent = x.GetRight(store); } else if (x.GetRight(store) == null) { parent = x.GetLeft(store); } else { NodeAVL node = x; x = x.GetLeft(store); while (true) { NodeAVL right = x.GetRight(store); if (right == null) { break; } x = right; } parent = x.GetLeft(store); int balance = x.GetBalance(store); x = x.SetBalance(store, node.GetBalance(store)); node = node.SetBalance(store, balance); NodeAVL eavl3 = x.GetParent(store); NodeAVL n = node.GetParent(store); if (node.IsRoot(store)) { store.SetAccessor(this, x); } x = x.SetParent(store, n); if (n != null) { if (!n.IsRight(node)) { n.SetLeft(store, x); } else { n.SetRight(store, x); } } if (node.Equals(eavl3)) { node = node.SetParent(store, x); if (node.IsLeft(x)) { x = x.SetLeft(store, node); NodeAVL right = node.GetRight(store); x = x.SetRight(store, right); } else { x = x.SetRight(store, node); NodeAVL left = node.GetLeft(store); x = x.SetLeft(store, left); } } else { node = node.SetParent(store, eavl3); eavl3 = eavl3.SetRight(store, node); NodeAVL left = node.GetLeft(store); NodeAVL right = node.GetRight(store); x = x.SetLeft(store, left); x = x.SetRight(store, right); } x.GetRight(store).SetParent(store, x); x.GetLeft(store).SetParent(store, x); node = node.SetLeft(store, parent); if (parent != null) { parent = parent.SetParent(store, node); } x = node.SetRight(store, null); } bool isleft = x.IsFromLeft(store); x.Replace(store, this, parent); parent = x.GetParent(store); x.Delete(); while (parent != null) { NodeAVL eavl10; int balance; NodeAVL eavl12; x = parent; int b = isleft ? 1 : -1; switch ((x.GetBalance(store) * b)) { case -1: x = x.SetBalance(store, 0); goto Label_0359; case 0: x = x.SetBalance(store, b); return; case 1: { eavl10 = x.Child(store, !isleft); balance = eavl10.GetBalance(store); if ((balance * b) < 0) { goto Label_02B7; } x.Replace(store, this, eavl10); NodeAVL n = eavl10.Child(store, isleft); x = x.Set(store, !isleft, n); eavl10 = eavl10.Set(store, isleft, x); if (balance != 0) { break; } x = x.SetBalance(store, b); eavl10 = eavl10.SetBalance(store, -b); return; } default: goto Label_0359; } x = x.SetBalance(store, 0); x = eavl10.SetBalance(store, 0); goto Label_0359; Label_02B7: eavl12 = eavl10.Child(store, isleft); x.Replace(store, this, eavl12); balance = eavl12.GetBalance(store); eavl10 = eavl10.Set(store, isleft, eavl12.Child(store, !isleft)); eavl12 = eavl12.Set(store, !isleft, eavl10); x = x.Set(store, !isleft, eavl12.Child(store, isleft)); eavl12 = eavl12.Set(store, isleft, x); x = x.SetBalance(store, (balance == b) ? -b : 0); eavl10 = eavl10.SetBalance(store, (balance == -b) ? b : 0); x = eavl12.SetBalance(store, 0); Label_0359: isleft = x.IsFromLeft(store); parent = x.GetParent(store); } } finally { store.UnlockStore(); Monitor.Exit(this._lock); } } }