Exemple #1
0
        protected override void InternalClose()
        {
            if (_sourceTable != null)
            {
                _sourceTable.Dispose();
                _sourceTable = null;
            }

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

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

            if (_lastRow != null)
            {
                _lastRow.Dispose();
                _lastRow = null;
            }
        }
Exemple #2
0
        public void Update(IValueManager manager, IRow oldRow, IRow newRow)
        {
            Row oldKey = GetIndexData(manager, Index.KeyRowType, new IRow[] { oldRow });

            try
            {
                Row newKey = GetIndexData(manager, Index.KeyRowType, new IRow[] { newRow });
                try
                {
                    Row newData = GetIndexData(manager, Index.DataRowType, new IRow[] { newRow });
                    try
                    {
                        Index.Update(manager, (NativeRow)oldKey.AsNative, (NativeRow)newKey.AsNative, (NativeRow)newData.AsNative);
                        newKey.ValuesOwned  = false;
                        newData.ValuesOwned = false;
                    }
                    finally
                    {
                        newData.Dispose();
                    }
                }
                finally
                {
                    newKey.Dispose();
                }
            }
            finally
            {
                oldKey.Dispose();
            }
        }
Exemple #3
0
        protected override bool InternalNext()
        {
            bool found = false;

            while (_sourceTable.Next())
            {
                var currentRow = new Row(Manager, Node.DataType.RowType);
                try
                {
                    _sourceTable.Select(currentRow);

                    if (!_map.HasRow(Manager, currentRow))
                    {
                        _map.Insert(Manager, currentRow);
                        currentRow.ValuesOwned = false;
                        found = true;
                        break;
                    }
                }
                finally
                {
                    currentRow.Dispose();
                }
            }
            return(found);
        }
Exemple #4
0
 protected override void PopulateTable()
 {
     using (ITable table = (ITable)Node.Nodes[0].Execute(Program))
     {
         Row row = new Row(Manager, DataType.RowType);
         try
         {
             _rowCount = 0;
             while (table.Next())
             {
                 table.Select(row);
                 _rowCount++;
                 if (Node.SequenceColumnIndex >= 0)
                 {
                     row[Node.SequenceColumnIndex] = _rowCount;
                 }
                 _table.Insert(Manager, row);                    // no validation is required because FTable will never be changed
                 row.ClearValues();
                 Program.CheckAborted();                         // Yield
             }
         }
         finally
         {
             row.Dispose();
         }
     }
 }
Exemple #5
0
 protected override void InternalClose()
 {
     if (_keyRow != null)
     {
         _keyRow.Dispose();
         _keyRow = null;
     }
     base.InternalClose();
 }
Exemple #6
0
        protected override void InternalSelect(IRow row)
        {
            var localRow = new Row(Manager, _map.Index.DataRowType, _enumerator.Current.Value);

            try
            {
                localRow.CopyTo(row);
            }
            finally
            {
                localRow.Dispose();
            }
        }
Exemple #7
0
        public void Delete(IValueManager manager, IRow row)
        {
            // Delete the row from all indexes
            Row key = GetIndexData(manager, Index.KeyRowType, new IRow[] { row });

            try
            {
                Index.Delete(manager, (NativeRow)key.AsNative);
            }
            finally
            {
                key.Dispose();
            }
        }
Exemple #8
0
        public IRow Select()
        {
            IRow row = new Row(Manager, DataType.RowType);

            try
            {
                Select(row);
                return(row);
            }
            catch
            {
                row.Dispose();
                throw;
            }
        }
Exemple #9
0
        protected override void InternalClose()
        {
            if (_leftRow != null)
            {
                _leftRow.Dispose();
                _leftRow = null;
            }

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

            base.InternalClose();
        }
Exemple #10
0
        public void Delete(IValueManager manager, IRow row)
        {
            // Delete the row from all indexes
            Row clusteredKey = GetIndexData(manager, ClusteredIndex.KeyRowType, new IRow[] { row });

            try
            {
                using (RowTreeSearchPath searchPath = new RowTreeSearchPath())
                {
                    int  entryNumber;
                    bool result = ClusteredIndex.FindKey(manager, ClusteredIndex.KeyRowType, (NativeRow)clusteredKey.AsNative, searchPath, out entryNumber);
                    if (!result)
                    {
                        throw new IndexException(IndexException.Codes.KeyNotFound);
                    }

                    Row clusteredData = new Row(manager, ClusteredIndex.DataRowType, searchPath.DataNode.DataNode.Rows[entryNumber]);
                    try
                    {
                        foreach (NativeRowTree bufferIndex in NonClusteredIndexes)
                        {
                            Row key = GetIndexData(manager, bufferIndex.KeyRowType, new IRow[] { clusteredKey, clusteredData });
                            try
                            {
                                bufferIndex.Delete(manager, (NativeRow)key.AsNative);
                            }
                            finally
                            {
                                key.Dispose();
                            }
                        }
                    }
                    finally
                    {
                        clusteredData.Dispose();
                    }
                }

                ClusteredIndex.Delete(manager, (NativeRow)clusteredKey.AsNative);
            }
            finally
            {
                clusteredKey.Dispose();
            }

            _rowCount--;
        }
Exemple #11
0
        private Row GetIndexData(IValueManager manager, Schema.IRowType rowType, IRow[] sourceRows)
        {
            Row row = new Row(manager, rowType);

            try
            {
                int  columnIndex;
                bool found;
                for (int index = 0; index < row.DataType.Columns.Count; index++)
                {
                    found = false;
                    foreach (Row sourceRow in sourceRows)
                    {
                        columnIndex = sourceRow.DataType.Columns.IndexOfName(row.DataType.Columns[index].Name);
                        if (columnIndex >= 0)
                        {
                            if (sourceRow.HasValue(columnIndex))
                            {
                                row[index] = sourceRow.GetNativeValue(columnIndex);
                            }
                            else
                            {
                                row.ClearValue(index);
                            }
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }

                    throw new RuntimeException(RuntimeException.Codes.UnableToConstructIndexKey);
                }
                return(row);
            }
            catch
            {
                row.Dispose();
                throw;
            }
        }
Exemple #12
0
        public static DataParams SerializableParamDataToDataParams(Alphora.Dataphor.DAE.IServerProcess process, SerializableParamData paramsValue)
        {
            if ((paramsValue.Params != null) && (paramsValue.Params.Length > 0))
            {
                DataParams     localParamsValue = new DataParams();
                Schema.RowType rowType          = new Schema.RowType();
                for (int index = 0; index < paramsValue.Params.Length; index++)
                {
                    rowType.Columns.Add(new Schema.Column(paramsValue.Params[index].Name, (Schema.ScalarType)process.Session.Server.Catalog[paramsValue.Params[index].TypeName]));
                }

                Data.Row row = new Data.Row(process.ValueManager, rowType);
                try
                {
                    row.ValuesOwned = false;
                    row.AsPhysical  = paramsValue.Data.Data;

                    for (int index = 0; index < paramsValue.Params.Length; index++)
                    {
                        if (row.HasValue(index))
                        {
                            localParamsValue.Add(new DataParam(row.DataType.Columns[index].Name, row.DataType.Columns[index].DataType, SerializableModifierToModifier(paramsValue.Params[index].Modifier), Data.DataValue.CopyValue(process.ValueManager, row[index])));
                        }
                        else
                        {
                            localParamsValue.Add(new DataParam(row.DataType.Columns[index].Name, row.DataType.Columns[index].DataType, SerializableModifierToModifier(paramsValue.Params[index].Modifier), null));
                        }
                    }

                    return(localParamsValue);
                }
                finally
                {
                    row.Dispose();
                }
            }
            else
            {
                return(null);
            }
        }
Exemple #13
0
 protected void PopulateTable()
 {
     using (ITable table = (ITable)Node.Nodes[0].Execute(Program))
     {
         Row row = new Row(Manager, DataType.RowType);
         try
         {
             while (table.Next())
             {
                 table.Select(row);
                 if (!_map.HasRow(Manager, row))
                 {
                     _map.Insert(Manager, row);                             // no validation is required because FTable will never be changed
                 }
                 row.ClearValues();
                 Program.CheckAborted();                         // Yield
             }
         }
         finally
         {
             row.Dispose();
         }
     }
 }
Exemple #14
0
        public void Update(IValueManager manager, IRow oldRow, IRow newRow)
        {
            // AOldRow must have at least the columns of the clustered index key
            Row oldClusteredKey = GetIndexData(manager, ClusteredIndex.KeyRowType, new IRow[] { oldRow });

            try
            {
                bool isClusteredIndexKeyAffected  = GetIsIndexAffected(ClusteredIndex.KeyRowType, newRow);
                bool isClusteredIndexDataAffected = GetIsIndexAffected(ClusteredIndex.DataRowType, newRow);

                Row newClusteredKey  = null;
                Row newClusteredData = null;
                try
                {
                    // Update the row in each index
                    using (RowTreeSearchPath searchPath = new RowTreeSearchPath())
                    {
                        int  entryNumber;
                        bool result = ClusteredIndex.FindKey(manager, ClusteredIndex.KeyRowType, (NativeRow)oldClusteredKey.AsNative, searchPath, out entryNumber);
                        if (!result)
                        {
                            throw new IndexException(IndexException.Codes.KeyNotFound);
                        }

                        Row oldClusteredData = new Row(manager, ClusteredIndex.DataRowType, searchPath.DataNode.DataNode.Rows[entryNumber]);
                        try
                        {
                            bool isIndexAffected;
                            foreach (NativeRowTree tree in NonClusteredIndexes)
                            {
                                isIndexAffected = GetIsIndexAffected(tree.KeyRowType, newRow);

                                if (isClusteredIndexKeyAffected || isIndexAffected)
                                {
                                    Row oldIndexKey = GetIndexData(manager, tree.KeyRowType, new Row[] { oldClusteredKey, oldClusteredData });
                                    try
                                    {
                                        Row newIndexKey  = null;
                                        Row newIndexData = null;
                                        try
                                        {
                                            if (isIndexAffected)
                                            {
                                                newIndexKey = GetIndexData(manager, tree.KeyRowType, new IRow[] { newRow, oldClusteredKey, oldClusteredData });
                                            }

                                            if (isClusteredIndexKeyAffected)
                                            {
                                                newIndexData = GetIndexData(manager, tree.DataRowType, new IRow[] { newRow, oldClusteredKey, oldClusteredData });
                                            }

                                            if (isIndexAffected && isClusteredIndexKeyAffected)
                                            {
                                                tree.Update(manager, (NativeRow)oldIndexKey.AsNative, (NativeRow)newIndexKey.AsNative, (NativeRow)newIndexData.AsNative);
                                                newIndexKey.ValuesOwned  = false;
                                                newIndexData.ValuesOwned = false;
                                            }
                                            else if (isIndexAffected)
                                            {
                                                tree.Update(manager, (NativeRow)oldIndexKey.AsNative, (NativeRow)newIndexKey.AsNative);
                                                newIndexKey.ValuesOwned = false;
                                            }
                                            else if (isClusteredIndexKeyAffected)
                                            {
                                                tree.Update(manager, (NativeRow)oldIndexKey.AsNative, (NativeRow)oldIndexKey.AsNative, (NativeRow)newIndexData.AsNative);
                                                newIndexData.ValuesOwned = false;
                                            }
                                        }
                                        finally
                                        {
                                            if (newIndexKey != null)
                                            {
                                                newIndexKey.Dispose();
                                            }

                                            if (newIndexData != null)
                                            {
                                                newIndexData.Dispose();
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        oldIndexKey.Dispose();
                                    }
                                }
                            }

                            if (isClusteredIndexKeyAffected)
                            {
                                newClusteredKey = GetIndexData(manager, ClusteredIndex.KeyRowType, new IRow[] { newRow, oldClusteredKey, oldClusteredData });
                            }

                            if (isClusteredIndexDataAffected)
                            {
                                newClusteredData = GetIndexData(manager, ClusteredIndex.DataRowType, new IRow[] { newRow, oldClusteredData });
                            }
                        }
                        finally
                        {
                            oldClusteredData.Dispose();
                        }
                    }

                    if (isClusteredIndexKeyAffected && isClusteredIndexDataAffected)
                    {
                        ClusteredIndex.Update(manager, (NativeRow)oldClusteredKey.AsNative, (NativeRow)newClusteredKey.AsNative, (NativeRow)newClusteredData.AsNative);
                        newClusteredKey.ValuesOwned  = false;
                        newClusteredData.ValuesOwned = false;
                    }
                    else if (isClusteredIndexKeyAffected)
                    {
                        ClusteredIndex.Update(manager, (NativeRow)oldClusteredKey.AsNative, (NativeRow)newClusteredKey.AsNative);
                        newClusteredKey.ValuesOwned = false;
                    }
                    else if (isClusteredIndexDataAffected)
                    {
                        ClusteredIndex.Update(manager, (NativeRow)oldClusteredKey.AsNative, (NativeRow)oldClusteredKey.AsNative, (NativeRow)newClusteredData.AsNative);
                        newClusteredData.ValuesOwned = false;
                    }
                }
                finally
                {
                    if (newClusteredKey != null)
                    {
                        newClusteredKey.Dispose();
                    }

                    if (newClusteredData != null)
                    {
                        newClusteredData.Dispose();
                    }
                }
            }
            finally
            {
                oldClusteredKey.Dispose();
            }
        }
Exemple #15
0
        private void IndexInsert(IValueManager manager, NativeRowTree index, IRow row)
                #endif
        {
            int columnIndex;
            Row key = new Row(manager, index.KeyRowType);

            try
            {
                Row data = new Row(manager, index.DataRowType);
                try
                {
                    key.ValuesOwned  = false;
                    data.ValuesOwned = false;

                    for (int localIndex = 0; localIndex < key.DataType.Columns.Count; localIndex++)
                    {
                                                #if USEINTERNALID
                        if (key.DataType.Columns[localIndex].Name == InternalIDColumnName)
                        {
                            key[localIndex] = internalID;
                        }
                        else
                                                #endif
                        {
                            columnIndex = row.DataType.Columns.GetIndexOfColumn(key.DataType.Columns[localIndex].Name);
                            if (row.HasValue(columnIndex))
                            {
                                key[localIndex] = row.GetNativeValue(columnIndex);
                            }
                            else
                            {
                                key.ClearValue(localIndex);
                            }
                        }
                    }

                    for (int localIndex = 0; localIndex < data.DataType.Columns.Count; localIndex++)
                    {
                                                #if USEINTERNALID
                        if (data.DataType.Columns[localIndex].Name == InternalIDColumnName)
                        {
                            data[localIndex] = internalID;
                        }
                        else
                                                #endif
                        {
                            columnIndex = row.DataType.Columns.GetIndexOfColumn(data.DataType.Columns[localIndex].Name);
                            if (row.HasValue(columnIndex))
                            {
                                data[localIndex] = row.GetNativeValue(columnIndex);
                            }
                            else
                            {
                                data.ClearValue(localIndex);
                            }
                        }
                    }

                    index.Insert(manager, (NativeRow)key.AsNative, (NativeRow)data.AsNative);
                }
                finally
                {
                    data.Dispose();
                }
            }
            finally
            {
                key.Dispose();
            }
        }
Exemple #16
0
        public void GetRow(IRow row)
        {
                        #if SAFETABLES
            CheckActive();
                        #endif
            CheckNotCrack();

            if ((_accessPath.IsClustered) || IsSubset(row, _accessPath))
            {
                Row localRow = new Row(_manager, _accessPath.KeyRowType, _indexNode.Node.Keys[_entryNumber]);
                try
                {
                    localRow.CopyTo(row);
                }
                finally
                {
                    localRow.Dispose();
                }

                localRow = new Row(_manager, _accessPath.DataRowType, _indexNode.DataNode.Rows[_entryNumber]);
                try
                {
                    localRow.CopyTo(row);
                }
                finally
                {
                    localRow.Dispose();
                }
            }
            else
            {
                using (RowTreeSearchPath searchPath = new RowTreeSearchPath())
                {
                    int  entryNumber;
                    bool result = _table.ClusteredIndex.FindKey(_manager, _table.ClusteredIndex.KeyRowType, _indexNode.DataNode.Rows[_entryNumber], searchPath, out entryNumber);
                    if (result)
                    {
                        Row localRow = new Row(_manager, _table.ClusteredIndex.KeyRowType, searchPath.DataNode.Node.Keys[entryNumber]);
                        try
                        {
                            localRow.CopyTo(row);
                        }
                        finally
                        {
                            localRow.Dispose();
                        }

                        localRow = new Row(_manager, _table.ClusteredIndex.DataRowType, searchPath.DataNode.DataNode.Rows[entryNumber]);
                        try
                        {
                            localRow.CopyTo(row);
                        }
                        finally
                        {
                            localRow.Dispose();
                        }
                    }
                    else
                    {
                        throw new ScanException(ScanException.Codes.ClusteredRowNotFound);
                    }
                }
            }
        }