Exemplo n.º 1
0
        protected override void InternalClose()
        {
            while (_sourceTables.Count > 0)
            {
                PopSourceTable();
            }

            if (_sourceRow != null)
            {
                _sourceRow.Dispose();
                _sourceRow = null;
            }

            if (_targetRow != null)
            {
                _targetRow.Dispose();
                _targetRow = null;
            }

            if (_scan != null)
            {
                _scan.Dispose();
                _scan = null;
            }

            if (_buffer != null)
            {
                _buffer.Drop(Manager);
                _buffer = null;
            }

            _tableType           = null;
            _sequenceColumnIndex = -1;
        }
Exemplo n.º 2
0
        protected override void InternalFindNearest(IRow row)
        {
            IRow localRow = EnsurePartialKeyRow(row);

            try
            {
                if (localRow != null)
                {
                    BrowseTableItem item = GetTable(localRow, true, true);
                    _tables.Add(item);
                    EnterTableContext(item);
                    try
                    {
                        TopTable.MoveCrack();
                    }
                    finally
                    {
                        ExitTableContext(item);
                    }
                }
                else
                {
                    _tables.Add(GetTable());
                }
            }
            finally
            {
                if ((localRow != null) && !Object.ReferenceEquals(row, localRow))
                {
                    localRow.Dispose();
                }
            }
        }
Exemplo n.º 3
0
 public void LoadTable(ServerProcess process, Schema.TableVar tableVar)
 {
     lock (_loadedTables)
     {
         if (!IsLoaded(tableVar))
         {
             _loadedTables.Add(tableVar);
             if (File.Exists(GetTableVarFileName(tableVar)))
             {
                 using (FileStream stream = new FileStream(GetTableVarFileName(tableVar), FileMode.Open, FileAccess.Read))
                 {
                     NativeTable nativeTable = Tables[tableVar];
                     while (stream.Position < stream.Length)
                     {
                         int    length   = StreamUtility.ReadInteger(stream);
                         byte[] rowValue = new byte[length];
                         stream.Read(rowValue, 0, rowValue.Length);
                         IRow row = (IRow)DataValue.FromPhysical(process.ValueManager, nativeTable.RowType, rowValue, 0);
                         try
                         {
                             nativeTable.Insert(process.ValueManager, row);
                         }
                         finally
                         {
                             row.Dispose();
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        protected override void InternalClose()
        {
            if (_scan != null)
            {
                _scan.Dispose();
                _scan = null;
            }

            if (_buffer != null)
            {
                _buffer.Drop(Manager);
                _buffer = null;
            }

            if (_leftTable != null)
            {
                _leftTable.Dispose();
                _leftTable = null;
            }

            if (_rightTable != null)
            {
                _rightTable.Dispose();
                _rightTable = null;
            }

            if (_sourceRow != null)
            {
                _sourceRow.Dispose();
                _sourceRow = null;
            }
        }
Exemplo n.º 5
0
        public override void WriteToPhysical(byte[] buffer, int offset, bool expandStreams)
        {
            if (IsNil)
            {
                buffer[offset] = 0;
            }
            else
            {
                buffer[offset] = 1;
                offset++;

                int rowSize;
                Streams.IConveyor int32Conveyor = Manager.GetConveyor(Manager.DataTypes.SystemInteger);

                int32Conveyor.Write(_rowList.Count, buffer, offset);
                offset += sizeof(int);

                for (int index = 0; index < _rowList.Count; index++)
                {
                    rowSize = (int)_sizeList[index];
                    int32Conveyor.Write(rowSize, buffer, offset);
                    offset += sizeof(int);
                    IRow row = _rowList[index];
                    row.WriteToPhysical(buffer, offset, expandStreams);
                    offset         += rowSize;
                    row.ValuesOwned = false;
                    row.Dispose();
                }
            }
        }
Exemplo n.º 6
0
        // Must be called with the original stack
        protected void SwapReader(bool forward)
        {
            IRow origin = null;

            try
            {
                EnterTableContext(TopTable);
                try
                {
                    origin = TopTable.Origin != null ? (IRow)TopTable.Origin.Copy() : null;
                }
                finally
                {
                    ExitTableContext(TopTable);
                }
                SwapReader(origin, forward, !TopTable.Inclusive);
            }
            finally
            {
                if (origin != null)
                {
                    origin.Dispose();
                }
            }
        }
Exemplo n.º 7
0
        protected override IRow InternalGetKey()
        {
            IRow key = _sourceTable.GetKey();

            try
            {
                if (_keyRowType == null)
                {
                    _keyRowType = new Schema.RowType();
                    for (int index = 0; index < key.DataType.Columns.Count; index++)
                    {
                        _keyRowType.Columns.Add(DataType.Columns[_sourceTable.DataType.Columns.IndexOfName(key.DataType.Columns[index].Name)].Copy());
                    }
                }
                Row row = new Row(Manager, _keyRowType);
                for (int index = 0; index < key.DataType.Columns.Count; index++)
                {
                    if (key.HasValue(index))
                    {
                        row[index] = key[index];
                    }
                }
                return(row);
            }
            finally
            {
                key.Dispose();
            }
        }
Exemplo n.º 8
0
        public override object InternalExecute(Program program)
        {
            object result;
            IRow   sourceRow = (IRow)Nodes[0].Execute(program);

                        #if NILPROPOGATION
            if ((sourceRow == null) || sourceRow.IsNil)
            {
                return(null);
            }
                        #endif
            try
            {
                Row newRow = new Row(program.ValueManager, DataType);
                try
                {
                    program.Stack.Push(sourceRow);
                    try
                    {
                        sourceRow.CopyTo(newRow);

                        for (int index = _extendColumnOffset; index < newRow.DataType.Columns.Count; index++)
                        {
                            result = Nodes[index - _extendColumnOffset + 1].Execute(program);
                            if (result != null)
                            {
                                try
                                {
                                    newRow[index] = result;
                                }
                                finally
                                {
                                    DataValue.DisposeValue(program.ValueManager, result);
                                }
                            }
                        }
                    }
                    finally
                    {
                        program.Stack.Pop();
                    }
                    return(newRow);
                }
                catch
                {
                    newRow.Dispose();
                    throw;
                }
            }
            finally
            {
                sourceRow.Dispose();
            }
        }
Exemplo n.º 9
0
        protected void InternalDisposeBookmark(Guid bookmark)
        {
            IRow internalBookmark = null;

            _bookmarks.TryGetValue(bookmark, out internalBookmark);
            _bookmarks.Remove(bookmark);
            if (internalBookmark != null)
            {
                internalBookmark.Dispose();
            }
        }
Exemplo n.º 10
0
        protected override bool InternalFindKey(IRow row, bool forward)
        {
            IRow localRow = EnsureKeyRow(row);

            try
            {
                bool            tableCreated = false;
                BrowseTableItem table        = FindTable(localRow, forward, true);
                if (table == null)
                {
                    table        = CreateTable(localRow, forward, true);
                    tableCreated = true;
                }
                try
                {
                    EnterTableContext(table);
                    try
                    {
                        table.MoveCrack();
                        bool result = (table.UniqueKey != null) && (CompareKeys(localRow, table.UniqueKey) == 0);
                        if (result)
                        {
                            _tables.Add(table);
                        }
                        else
                        if (tableCreated)
                        {
                            table.Dispose();
                        }
                        return(result);
                    }
                    finally
                    {
                        ExitTableContext(table);
                    }
                }
                catch
                {
                    if (tableCreated)
                    {
                        table.Dispose();
                    }
                    throw;
                }
            }
            finally
            {
                if (!Object.ReferenceEquals(row, localRow))
                {
                    localRow.Dispose();
                }
            }
        }
Exemplo n.º 11
0
        public bool HasRow(IValueManager manager, IRow row)
        {
            IRow key = GetIndexData(manager, Index.KeyRowType, new IRow[] { row });

            try
            {
                return(Index.ContainsKey(manager, (NativeRow)key.AsNative));
            }
            finally
            {
                key.Dispose();
            }
        }
Exemplo n.º 12
0
        protected override bool InternalRefresh(IRow key)
        {
            IRow row = BuildSourceKey(key);

            try
            {
                return(_sourceTable.Refresh(row));
            }
            finally
            {
                row.Dispose();
            }
        }
Exemplo n.º 13
0
        protected override bool InternalFindKey(IRow key, bool forward)
        {
            IRow localKey = BuildSourceKey(key);

            try
            {
                return(_sourceTable.FindKey(localKey, forward));
            }
            finally
            {
                localKey.Dispose();
            }
        }
Exemplo n.º 14
0
        protected override void InternalFindNearest(IRow key)
        {
            IRow localKey = BuildSourceKey(key);

            try
            {
                _sourceTable.FindNearest(localKey);
            }
            finally
            {
                localKey.Dispose();
            }
        }
Exemplo n.º 15
0
        public bool FindKey(IRow key)
        {
                        #if SAFETABLES
            CheckActive();
                        #endif
            int         entryNumber;
            RowTreeNode indexNode;
            IRow        localKey = EnsureKeyRow(key);
            try
            {
                if (_firstKey != null)
                {
                    int compareResult = _accessPath.Compare(_manager, _firstKey.DataType, (NativeRow)_firstKey.AsNative, localKey.DataType, (NativeRow)localKey.AsNative);
                    if (((_direction == ScanDirection.Forward) && (compareResult > 0)) || ((_direction == ScanDirection.Backward) && (compareResult < 0)))
                    {
                        return(false);
                    }
                }

                if (_lastKey != null)
                {
                    int compareResult = _accessPath.Compare(_manager, _lastKey.DataType, (NativeRow)_lastKey.AsNative, localKey.DataType, (NativeRow)localKey.AsNative);
                    if (((_direction == ScanDirection.Forward) && (compareResult < 0)) || ((_direction == ScanDirection.Backward) && (compareResult < 0)))
                    {
                        return(false);
                    }
                }

                bool result = FindIndexKey(localKey.DataType, (NativeRow)localKey.AsNative, out indexNode, out entryNumber);
                if (result)
                {
                    SetIndexNode(indexNode);
                    _entryNumber = entryNumber;
                    _bOF         = false;
                    _eOF         = false;
                }
                else
                {
                    indexNode.Dispose();
                }
                return(result);
            }
            finally
            {
                if (!ReferenceEquals(key, localKey))
                {
                    localKey.Dispose();
                }
            }
        }
Exemplo n.º 16
0
        protected override void InternalClose()
        {
            if (_sourceTable != null)
            {
                _sourceTable.Dispose();
                _sourceTable = null;
            }

            if (_sourceRow != null)
            {
                _sourceRow.Dispose();
                _sourceRow = null;
            }
        }
Exemplo n.º 17
0
 protected void CheckEOF()
 {
     if (!_eOF && (_lastKey != null) && !_sourceTable.BOF())
     {
         IRow key = _sourceTable.GetKey();
         try
         {
             _eOF = IsGreater(key, _lastKey, _isLastKeyExclusive);
         }
         finally
         {
             key.Dispose();
         }
     }
 }
Exemplo n.º 18
0
        protected override void InternalClose()
        {
            if (_firstKey != null)
            {
                _firstKey.Dispose();
                _firstKey = null;
            }

            if (_lastKey != null)
            {
                _lastKey.Dispose();
                _lastKey = null;
            }
            base.InternalClose();
        }
Exemplo n.º 19
0
 protected void CheckBOF()
 {
     if (!_bOF && (_firstKey != null) && !_sourceTable.EOF())
     {
         IRow key = _sourceTable.GetKey();
         try
         {
             _bOF = IsLess(key, _firstKey, _isFirstKeyExclusive);
         }
         finally
         {
             key.Dispose();
         }
     }
 }
Exemplo n.º 20
0
        public bool HasRow(IValueManager manager, IRow row)
        {
            IRow key = GetIndexData(manager, ClusteredIndex.KeyRowType, new IRow[] { row });

            try
            {
                using (RowTreeSearchPath searchPath = new RowTreeSearchPath())
                {
                    int entryNumber;
                    return(ClusteredIndex.FindKey(manager, ClusteredIndex.KeyRowType, (NativeRow)key.AsNative, searchPath, out entryNumber));
                }
            }
            finally
            {
                key.Dispose();
            }
        }
Exemplo n.º 21
0
        protected void PushSourceTable(IRow currentRow)
        {
            if (currentRow == null)
            {
                // Open the root expression, if it is not empty, save it on the cursor stack
                _rootTable = (ITable)Node.Nodes[1].Execute(Program);
                if (!_rootTable.IsEmpty())
                {
                    _sourceTables.Push(_rootTable);
                }
                else
                {
                    _rootTable.Dispose();
                }
            }
            else
            {
                // Otherwise, use the given row to build a parent row and open a new cursor for the child expression with that row to parameterize it
                IRow parentRow = NewParentRow(currentRow);
                Program.Stack.Push(parentRow);
                try
                {
                    ITable table = (ITable)Node.Nodes[2].Execute(Program);

                    // If it is not empty, save it on the cursor stack, and save the parent row on the parent row stack
                    if (!table.IsEmpty())
                    {
                        _sourceTables.Push(table);
                        _parentRows.Push(parentRow);
                    }
                    else
                    {
                        table.Dispose();
                        parentRow.Dispose();
                    }
                }
                finally
                {
                    Program.Stack.Pop();
                }
            }
        }
Exemplo n.º 22
0
 protected override bool InternalFindKey(IRow key, bool forward)
 {
     if (!_isContradiction)
     {
         IRow localKey = EnsureKeyRow(key);
         try
         {
             if ((_firstKey != null) && IsLess(localKey, _firstKey, _isFirstKeyExclusive))
             {
                 return(false);
             }
             else if ((_lastKey != null) && IsGreater(localKey, _lastKey, _isLastKeyExclusive))
             {
                 return(false);
             }
             else
             {
                 if (_sourceTable.FindKey(localKey, forward))
                 {
                     _bOF = false;
                     _eOF = false;
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
         finally
         {
             if (!Object.ReferenceEquals(localKey, key))
             {
                 localKey.Dispose();
             }
         }
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 23
0
        public override object InternalExecute(Program program)
        {
            ITable table = (ITable)Nodes[0].Execute(program);

                        #if NILPROPOGATION
            if ((table == null))
            {
                return(null);
            }
                        #endif
            try
            {
                table.Open();
                if (table.Next())
                {
                    IRow row = table.Select();
                    try
                    {
                        if (table.Next())
                        {
                            throw new RuntimeException(RuntimeException.Codes.InvalidRowExtractorExpression);
                        }
                        return(row);
                    }
                    catch
                    {
                        row.Dispose();
                        throw;
                    }
                }
                else
                                        #if NILPROPOGATION
                { return(null); }
                                        #else
                { throw new RuntimeException(RuntimeException.Codes.RowTableEmpty); }
                                        #endif
            }
            finally
            {
                table.Dispose();
            }
        }
Exemplo n.º 24
0
        protected void FindUniqueKey()
        {
            if (!(_table.BOF() || _table.EOF()))
            {
                if (_uniqueKey == null)
                {
                    _uniqueKey = BuildUniqueKeyRow();
                }
                else
                {
                    _uniqueKey.ClearValues();
                }

                _table.Select(_uniqueKey);
            }
            else
            if (_uniqueKey != null)
            {
                _uniqueKey.Dispose();
                _uniqueKey = null;
            }
        }
Exemplo n.º 25
0
        public override object InternalExecute(Program program, object argument)
        {
            IRow sourceRow = (IRow)argument;

                        #if NILPROPOGATION
            if ((sourceRow == null) || sourceRow.IsNil)
            {
                return(null);
            }
                        #endif
            try
            {
                Row newRow = new Row(program.ValueManager, DataType);
                try
                {
                    for (int index = 0; index < sourceRow.DataType.Columns.Count; index++)
                    {
                        if (sourceRow.HasValue(index) && (index < newRow.DataType.Columns.Count))
                        {
                            newRow[index] = sourceRow[index];
                        }
                    }

                    return(newRow);
                }
                catch
                {
                    newRow.Dispose();
                    throw;
                }
            }
            finally
            {
                sourceRow.Dispose();
            }
        }
Exemplo n.º 26
0
 public void ReleaseRow(IRow row)
 {
     row.Dispose();
 }
Exemplo n.º 27
0
 public void ReleaseRow(IRow row)
 {
     CheckCompiled();
     row.Dispose();
 }
Exemplo n.º 28
0
 protected override void InternalFindNearest(IRow key)
 {
     if (!_isContradiction)
     {
         IRow localKey = EnsurePartialKeyRow(key);
         try
         {
             if (localKey != null)
             {
                 if (Direction == ScanDirection.Forward)
                 {
                     if ((_firstKey != null) && IsLess(localKey, _firstKey, _isFirstKeyExclusive))
                     {
                         InternalFirst();
                         InternalNext();
                     }
                     else if ((_lastKey != null) && IsGreater(localKey, _lastKey, _isLastKeyExclusive))
                     {
                         InternalLast();
                         InternalPrior();
                     }
                     else
                     {
                         _sourceTable.FindNearest(localKey);
                         _bOF = _sourceTable.BOF();
                         _eOF = _sourceTable.EOF();
                     }
                 }
                 else
                 {
                     if ((_firstKey != null) && IsLess(localKey, _firstKey, _isFirstKeyExclusive))
                     {
                         InternalLast();
                         InternalPrior();
                     }
                     else if ((_lastKey != null) && IsGreater(localKey, _lastKey, _isLastKeyExclusive))
                     {
                         InternalFirst();
                         InternalNext();
                     }
                     else
                     {
                         if (IsKeyRow(localKey) && _sourceTable.FindKey(localKey))
                         {
                             _bOF = false;
                             _eOF = false;
                         }
                         else
                         {
                             _sourceTable.FindNearest(localKey);
                             _sourceTable.Prior();
                             _bOF = _sourceTable.BOF();
                             _eOF = _sourceTable.EOF();
                         }
                     }
                 }
             }
         }
         finally
         {
             if (!Object.ReferenceEquals(key, localKey))
             {
                 localKey.Dispose();
             }
         }
     }
 }
Exemplo n.º 29
0
        protected override void InternalLast()
        {
            if (!_isContradiction)
            {
                _eOF = true;
                if (Direction == ScanDirection.Forward)
                {
                    if (_lastKey != null)
                    {
                        if (!_sourceTable.FindKey(_lastKey))
                        {
                            _sourceTable.FindNearest(_lastKey);
                            _sourceTable.Prior();
                        }

                        if (_isLastKeyExclusive)
                        {
                            while (!_sourceTable.BOF())
                            {
                                IRow currentKey = _sourceTable.GetKey();
                                try
                                {
                                    if (CompareKeys(currentKey, _lastKey) < 0)
                                    {
                                        _sourceTable.Next();
                                        break;
                                    }
                                    else
                                    {
                                        _sourceTable.Prior();
                                    }
                                }
                                finally
                                {
                                    currentKey.Dispose();
                                }
                            }
                        }
                        else
                        {
                            if (_sourceTable.BOF())
                            {
                                _sourceTable.Next();
                            }

                            while (!_sourceTable.EOF())
                            {
                                IRow currentKey = _sourceTable.GetKey();
                                try
                                {
                                    if (CompareKeys(currentKey, _lastKey) > 0)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        _sourceTable.Next();
                                    }
                                }
                                finally
                                {
                                    currentKey.Dispose();
                                }
                            }
                        }
                    }
                    else
                    {
                        _sourceTable.Last();
                    }
                    _bOF = _sourceTable.BOF();
                }
                else
                {
                    if (_lastKey != null)
                    {
                        _sourceTable.FindNearest(_lastKey);

                        if (_isLastKeyExclusive)
                        {
                            while (!_sourceTable.EOF())
                            {
                                IRow currentKey = _sourceTable.GetKey();
                                try
                                {
                                    if (CompareKeys(currentKey, _lastKey) < 0)
                                    {
                                        _sourceTable.Prior();
                                        break;
                                    }
                                    else
                                    {
                                        _sourceTable.Next();
                                    }
                                }
                                finally
                                {
                                    currentKey.Dispose();
                                }
                            }
                        }
                        else
                        {
                            if (_sourceTable.EOF())
                            {
                                _sourceTable.Prior();
                            }

                            while (!_sourceTable.BOF())
                            {
                                IRow currentKey = _sourceTable.GetKey();
                                try
                                {
                                    if (CompareKeys(currentKey, _lastKey) > 0)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        _sourceTable.Prior();
                                    }
                                }
                                finally
                                {
                                    currentKey.Dispose();
                                }
                            }
                        }
                    }
                    else
                    {
                        _sourceTable.First();
                    }
                    _bOF = _sourceTable.EOF();
                }
                InternalPrior();
                if (Direction == ScanDirection.Forward)
                {
                    _sourceTable.Next();
                }
                else
                {
                    _sourceTable.Prior();
                }
                _eOF = true;
            }
        }
Exemplo n.º 30
0
        public override object InternalExecute(Program program)
        {
            object objectValue = Nodes[0].Execute(program);

                        #if NILPROPOGATION
            if (objectValue == null)
            {
                return(null);
            }
                        #endif

            ITable table = objectValue as ITable;
            if (table != null)
            {
                try
                {
                    table.Open();
                    if (table.Next())
                    {
                        IRow row = table.Select();
                        try
                        {
                            if (table.Next())
                            {
                                throw new RuntimeException(RuntimeException.Codes.InvalidRowExtractorExpression);
                            }
                                                        #if USECOLUMNLOCATIONBINDING
                            if (row.HasValue(Location))
                            {
                                return(row[Location].AsNative);
                            }
                            else
                            {
                                return(null);
                            }
                                                        #else
                            int columnIndex = row.DataType.Columns.IndexOf(Identifier);
                            if (row.HasValue(columnIndex))
                            {
                                return(row[columnIndex]);
                            }
                            else
                            {
                                return(null);
                            }
                                                        #endif
                        }
                        finally
                        {
                            row.Dispose();
                        }
                    }
                    else
                                                #if NILPROPOGATION
                    { return(null); }
                                                #else
                    { throw new RuntimeException(RuntimeException.Codes.ColumnTableEmpty); }
                                                #endif
                }
                finally
                {
                    if (_shouldDisposeSource)
                    {
                        table.Dispose();
                    }
                }
            }
            else
            {
                IRow row = (IRow)objectValue;
                try
                {
                                        #if USECOLUMNLOCATIONBINDING
                    if (row.HasValue(Location))
                    {
                        return(row[Location].AsNative);
                    }
                    else
                    {
                        return(null);
                    }
                                        #else
                    int columnIndex = row.DataType.Columns.IndexOf(Identifier);
                    if (!row.IsNil && row.HasValue(columnIndex))
                    {
                        return(row[columnIndex]);
                    }
                    else
                    {
                        return(null);
                    }
                                        #endif
                }
                finally
                {
                    if (_shouldDisposeSource)
                    {
                        row.Dispose();
                    }
                }
            }
        }