Ejemplo n.º 1
0
        public NodeAVL Last(Session session, IPersistentStore store, NodeAVL x)
        {
            if (x == null)
            {
                return(null);
            }
            lock (this._lock)
            {
Label_0012:
                x = this.Last(store, x);
                if (x != null)
                {
                    if (session == null)
                    {
                        return(x);
                    }
                    Row row = x.GetRow(store);
                    if (!session.database.TxManager.CanRead(session, row, 0, null))
                    {
                        goto Label_0012;
                    }
                }
                else
                {
                    return(x);
                }
                return(x);
            }
        }
Ejemplo n.º 2
0
        public IRowIterator FirstRow(IPersistentStore store)
        {
            IRowIterator iterator;
            int          num = 0;

            Monitor.Enter(this._lock);
            try
            {
                NodeAVL accessor = this.GetAccessor(store);
                NodeAVL left     = accessor;
                while (left != null)
                {
                    accessor = left;
                    left     = accessor.GetLeft(store);
                    num++;
                }
                iterator = this.GetIterator(null, store, accessor, false, false);
            }
            finally
            {
                this.Depth = num;
                Monitor.Exit(this._lock);
            }
            return(iterator);
        }
Ejemplo n.º 3
0
        public IRowIterator FirstRow(Session session, IPersistentStore store)
        {
            IRowIterator iterator;
            int          num = 0;

            Monitor.Enter(this._lock);
            try
            {
                NodeAVL accessor = this.GetAccessor(store);
                NodeAVL left     = accessor;
                while (left != null)
                {
                    accessor = left;
                    left     = accessor.GetLeft(store);
                    num++;
                }
                while ((session != null) && (accessor != null))
                {
                    Row row = accessor.GetRow(store);
                    if (session.database.TxManager.CanRead(session, row, 0, null))
                    {
                        break;
                    }
                    accessor = this.Next(store, accessor);
                }
                iterator = this.GetIterator(session, store, accessor, false, false);
            }
            finally
            {
                this.Depth = num;
                Monitor.Exit(this._lock);
            }
            return(iterator);
        }
Ejemplo n.º 4
0
        public override NodeAVL SetParent(IPersistentStore store, NodeAVL n)
        {
            NodeAVLDisk node = this;
            RowAVLDisk  row  = this.row;

            if (!row.KeepInMemory(true))
            {
                row  = (RowAVLDisk)store.Get(this.row, true);
                node = (NodeAVLDisk)row.GetNode(this._iId);
            }
            if (!row.IsInMemory())
            {
                row.KeepInMemory(false);
                throw Error.RuntimeError(0xc9, "NodeAVLDisk");
            }
            row.SetNodesChanged();
            node._iParent = (n == null) ? -1 : n.GetPos();
            if ((n != null) && !n.IsInMemory())
            {
                n = this.FindNode(store, n.GetPos());
            }
            node.nParent = n;
            row.KeepInMemory(false);
            return(node);
        }
Ejemplo n.º 5
0
        public override void Replace(IPersistentStore store, Index index, NodeAVL n)
        {
            NodeAVLDisk node = this;
            RowAVLDisk  row  = this.row;

            if (!row.KeepInMemory(true))
            {
                row  = (RowAVLDisk)store.Get(this.row, true);
                node = (NodeAVLDisk)row.GetNode(this._iId);
            }
            if (node._iParent == -1)
            {
                if (n != null)
                {
                    n = n.SetParent(store, null);
                }
                store.SetAccessor(index, n);
            }
            else
            {
                bool isLeft = node.IsFromLeft(store);
                node.GetParent(store).Set(store, isLeft, n);
            }
            row.KeepInMemory(false);
        }
Ejemplo n.º 6
0
        public override NodeAVL Next(Session session, IPersistentStore store, NodeAVL x)
        {
            if (x == null)
            {
                return(null);
            }
            lock (base._lock)
            {
Label_0012:
                x = this.Next(store, x);
                if ((x != null) && (session != null))
                {
                    Row memoryRow = x.MemoryRow;
                    if (!session.database.TxManager.CanRead(session, memoryRow, 0, null))
                    {
                        goto Label_0012;
                    }
                }
                else
                {
                    return(x);
                }
                return(x);
            }
        }
Ejemplo n.º 7
0
        public override NodeAVL Last(IPersistentStore store, NodeAVL x)
        {
            if (x == null)
            {
                return(null);
            }
            NodeAVL nLeft = x.nLeft;

            if (nLeft != null)
            {
                x = nLeft;
                for (NodeAVL eavl3 = x.nRight; eavl3 != null; eavl3 = x.nRight)
                {
                    x = eavl3;
                }
                return(x);
            }
            NodeAVL eavl4 = x;

            x = x.nParent;
            while ((x != null) && (eavl4 == x.nLeft))
            {
                eavl4 = x;
                x     = x.nParent;
            }
            return(x);
        }
Ejemplo n.º 8
0
        public virtual NodeAVL Last(IPersistentStore store, NodeAVL x)
        {
            if (x == null)
            {
                return(null);
            }
            NodeAVL left = x.GetLeft(store);

            if (left != null)
            {
                x = left;
                for (NodeAVL eavl3 = x.GetRight(store); eavl3 != null; eavl3 = x.GetRight(store))
                {
                    x = eavl3;
                }
                return(x);
            }
            NodeAVL eavl4 = x;

            x = x.GetParent(store);
            while ((x != null) && eavl4.Equals(x.GetLeft(store)))
            {
                eavl4 = x;
                x     = x.GetParent(store);
            }
            return(x);
        }
Ejemplo n.º 9
0
 public override bool IsRight(NodeAVL n)
 {
     if (n == null)
     {
         return(this._iRight == -1);
     }
     return(this._iRight == ((NodeAVLDisk)n).iData);
 }
Ejemplo n.º 10
0
 public override NodeAVL Set(IPersistentStore store, bool isLeft, NodeAVL n)
 {
     if (n != null)
     {
         n.SetParent(store, this);
     }
     return(isLeft ? this.SetLeft(store, n) : this.SetRight(store, n));
 }
Ejemplo n.º 11
0
        public IRowIterator FindFirstRow(Session session, IPersistentStore store, object[] rowdata, int matchCount, int compareType, bool reversed, bool[] map)
        {
            if (compareType == 0x4a)
            {
                return(this.LastRow(session, store));
            }
            NodeAVL x = this.FindNode(session, store, rowdata, this.DefaultColMap, matchCount, compareType, 0, reversed);

            return(this.GetIterator(session, store, x, false, reversed));
        }
Ejemplo n.º 12
0
 public IndexRowIterator(Session session, IPersistentStore store, IndexAVL index, NodeAVL node, bool single, bool reversed)
 {
     this._session  = session;
     this._store    = store;
     this._index    = index;
     this._single   = single;
     this._reversed = reversed;
     if (index != null)
     {
         this._nextnode = node;
     }
 }
Ejemplo n.º 13
0
 public bool Equals(NodeAVL n)
 {
     if (!(n is NodeAVLDisk))
     {
         return(false);
     }
     if (this != n)
     {
         return(this.GetPos() == n.GetPos());
     }
     return(true);
 }
Ejemplo n.º 14
0
        public void Delete(Session session, IPersistentStore store, Row row)
        {
            if (!row.IsInMemory())
            {
                row = (Row)store.Get(row, false);
            }
            NodeAVL node = ((RowAVL)row).GetNode(this.Position);

            if (node != null)
            {
                this.Delete(store, node);
                store.UpdateElementCount(this, -1, -1);
            }
        }
Ejemplo n.º 15
0
 public virtual void Replace(IPersistentStore store, Index index, NodeAVL n)
 {
     if (this.nParent == null)
     {
         if (n != null)
         {
             n = n.SetParent(store, null);
         }
         store.SetAccessor(index, n);
     }
     else
     {
         this.nParent.Set(store, this.IsFromLeft(store), n);
     }
 }
Ejemplo n.º 16
0
        private void Balance(IPersistentStore store, NodeAVL x, bool isleft)
        {
            while (true)
            {
                int num = isleft ? 1 : -1;
                switch ((x.GetBalance(store) * num))
                {
                case -1:
                {
                    NodeAVL n = x.Child(store, isleft);
                    if (n.GetBalance(store) != -num)
                    {
                        NodeAVL eavl2 = n.Child(store, !isleft);
                        x.Replace(store, this, eavl2);
                        n     = n.Set(store, !isleft, eavl2.Child(store, isleft));
                        eavl2 = eavl2.Set(store, isleft, n);
                        x     = x.Set(store, isleft, eavl2.Child(store, !isleft));
                        eavl2 = eavl2.Set(store, !isleft, x);
                        int balance = eavl2.GetBalance(store);
                        x     = x.SetBalance(store, (balance == -num) ? num : 0);
                        n     = n.SetBalance(store, (balance == num) ? -num : 0);
                        eavl2 = eavl2.SetBalance(store, 0);
                        return;
                    }
                    x.Replace(store, this, n);
                    x = x.Set(store, isleft, n.Child(store, !isleft));
                    n = n.Set(store, !isleft, x);
                    x = x.SetBalance(store, 0);
                    n = n.SetBalance(store, 0);
                    return;
                }

                case 0:
                    x = x.SetBalance(store, -num);
                    break;

                case 1:
                    x = x.SetBalance(store, 0);
                    return;
                }
                if (x.IsRoot(store))
                {
                    return;
                }
                isleft = x.IsFromLeft(store);
                x      = x.GetParent(store);
            }
        }
Ejemplo n.º 17
0
        private void Balance(IPersistentStore store, NodeAVL x, bool isleft)
        {
            while (true)
            {
                int num = isleft ? 1 : -1;
                switch ((x.IBalance * num))
                {
                case -1:
                {
                    NodeAVL n = isleft ? x.nLeft : x.nRight;
                    if (n.IBalance != -num)
                    {
                        NodeAVL eavl2 = !isleft ? n.nLeft : n.nRight;
                        x.Replace(store, this, eavl2);
                        n.Set(store, !isleft, isleft ? eavl2.nLeft : eavl2.nRight);
                        eavl2.Set(store, isleft, n);
                        x.Set(store, isleft, isleft ? eavl2.nRight : eavl2.nLeft);
                        eavl2.Set(store, !isleft, x);
                        int iBalance = eavl2.IBalance;
                        x.IBalance     = (iBalance == -num) ? num : 0;
                        n.IBalance     = (iBalance == num) ? -num : 0;
                        eavl2.IBalance = 0;
                        return;
                    }
                    x.Replace(store, this, n);
                    x.Set(store, isleft, isleft ? n.nRight : n.nLeft);
                    n.Set(store, !isleft, x);
                    x.IBalance = 0;
                    n.IBalance = 0;
                    return;
                }

                case 0:
                    x.IBalance = -num;
                    break;

                case 1:
                    x.IBalance = 0;
                    return;
                }
                if (x.nParent == null)
                {
                    return;
                }
                isleft = x == x.nParent.nLeft;
                x      = x.nParent;
            }
        }
Ejemplo n.º 18
0
 public virtual NodeAVL Set(IPersistentStore store, bool isLeft, NodeAVL n)
 {
     if (isLeft)
     {
         this.nLeft = n;
     }
     else
     {
         this.nRight = n;
     }
     if (n != null)
     {
         n.nParent = this;
     }
     return(this);
 }
Ejemplo n.º 19
0
        protected bool IsEqualReadable(Session session, IPersistentStore store, NodeAVL node)
        {
            object[] data;
            NodeAVL  x = node;

            if (!session.database.TxManager.CanRead(session, node.GetRow(store), 1, null))
            {
                Row row;
                data = node.GetData(store);
                do
                {
                    x = this.Last(store, x);
                    if (x == null)
                    {
                        goto Label_006E;
                    }
                    object[] data = x.GetData(store);
                    if (this.CompareRow(session, data, data) != 0)
                    {
                        goto Label_006E;
                    }
                    row = x.GetRow(store);
                }while (!session.database.TxManager.CanRead(session, row, 1, null));
            }
            return(true);

Label_006E:
            x = this.Next(session, store, node);
            if (x != null)
            {
                object[] data = x.GetData(store);
                if (this.CompareRow(session, data, data) != 0)
                {
                    return(false);
                }
                Row row = x.GetRow(store);
                if (!session.database.TxManager.CanRead(session, row, 1, null))
                {
                    goto Label_006E;
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 20
0
 public IRowIterator LastRow(Session session, IPersistentStore store)
 {
     lock (this._lock)
     {
         NodeAVL accessor = this.GetAccessor(store);
         for (NodeAVL eavl2 = accessor; eavl2 != null; eavl2 = accessor.GetRight(store))
         {
             accessor = eavl2;
         }
         while ((session != null) && (accessor != null))
         {
             Row row = accessor.GetRow(store);
             if (session.database.TxManager.CanRead(session, row, 0, null))
             {
                 break;
             }
             accessor = this.Last(store, accessor);
         }
         return(this.GetIterator(null, store, accessor, false, true));
     }
 }
Ejemplo n.º 21
0
 public Row GetNextRow()
 {
     if (this._nextnode == null)
     {
         this.Release();
         return(null);
     }
     this._lastrow = this._nextnode.GetRow(this._store);
     if (this._single)
     {
         this._nextnode = null;
     }
     else if (this._reversed)
     {
         this._nextnode = this._index.Last(this._session, this._store, this._nextnode);
     }
     else
     {
         this._nextnode = this._index.Next(this._session, this._store, this._nextnode);
     }
     return(this._lastrow);
 }
Ejemplo n.º 22
0
        public virtual NodeAVL Next(IPersistentStore store, NodeAVL x)
        {
            NodeAVL right = x.GetRight(store);

            if (right != null)
            {
                x = right;
                for (NodeAVL eavl3 = x.GetLeft(store); eavl3 != null; eavl3 = x.GetLeft(store))
                {
                    x = eavl3;
                }
                return(x);
            }
            NodeAVL eavl4 = x;

            x = x.GetParent(store);
            while ((x != null) && (eavl4 == x.GetRight(store)))
            {
                eavl4 = x;
                x     = x.GetParent(store);
            }
            return(x);
        }
Ejemplo n.º 23
0
 public virtual void Delete()
 {
     this.IBalance = 0;
     this.nLeft    = this.nRight = (NodeAVL)(this.nParent = null);
 }
Ejemplo n.º 24
0
 public virtual NodeAVL SetRight(IPersistentStore persistentStore, NodeAVL n)
 {
     this.nRight = n;
     return(this);
 }
Ejemplo n.º 25
0
 public virtual NodeAVL SetParent(IPersistentStore persistentStore, NodeAVL n)
 {
     this.nParent = n;
     return(this);
 }
Ejemplo n.º 26
0
 public virtual bool IsRight(NodeAVL node)
 {
     return(this.nRight == node);
 }
Ejemplo n.º 27
0
 public virtual bool IsLeft(NodeAVL node)
 {
     return(this.nLeft == node);
 }
Ejemplo n.º 28
0
 private IndexRowIterator GetIterator(Session session, IPersistentStore store, NodeAVL x, bool single, bool reversed)
 {
     if (x == null)
     {
         return(EmptyIterator);
     }
     return(new IndexRowIterator(session, store, this, x, single, reversed));
 }
Ejemplo n.º 29
0
 public virtual NodeAVL SetLeft(IPersistentStore persistentStore, NodeAVL n)
 {
     this.nLeft = n;
     return(this);
 }
Ejemplo n.º 30
0
        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);
            }
        }