Exemplo n.º 1
0
        public RowId AddRow(Row row)
        {
            AssertNotDisposed();

            if (Transaction.ReadOnly())
            {
                throw new Exception("Transaction is Read only.");
            }

            if (TableSource.IsReadOnly)
            {
                throw new InvalidOperationException("Can not add row - table is read-only.");
            }

            int rowNum;

            try {
                rowNum = TableSource.AddRow(row);
            } catch (Exception ex) {
                throw new InvalidOperationException(
                          String.Format("Unknown error when adding a row to the table '{0}'.", TableInfo.TableName), ex);
            }

            row.SetRowNumber(rowNum);

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.

            EventRegistry.Register(new TableRowEvent(TableId, rowNum, TableRowEventType.Add));

            return(new RowId(TableId, rowNum));
        }
Exemplo n.º 2
0
        public void UpdateRow(Row row)
        {
            AssertNotDisposed();

            if (Transaction.ReadOnly())
            {
                throw new Exception("Transaction is Read only.");
            }

            // Check this isn't a Read only source
            if (TableSource.IsReadOnly)
            {
                throw new InvalidOperationException("Can not update row - table is read-only.");
            }

            if (row.RowId.IsNull)
            {
                throw new ArgumentException("The ROWID cannot be null in an update.");
            }

            if (row.RowId.TableId != TableId)
            {
                throw new ArgumentException("The row was not created from this table.");
            }

            var rowNum = row.RowId.RowNumber;

            if (rowNum < 0)
            {
                throw new ArgumentException("The number part of the ROWID is invalid.");
            }

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.
            EventRegistry.Register(new TableRowEvent(TableId, rowNum, TableRowEventType.UpdateRemove));

            int newRowIndex;

            try {
                newRowIndex = TableSource.AddRow(row);
            } catch (IOException e) {
                throw new InvalidOperationException("IO Error: " + e.Message, e);
            }

            row.SetRowNumber(newRowIndex);

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.
            EventRegistry.Register(new TableRowEvent(TableId, newRowIndex, TableRowEventType.UpdateAdd));
        }
Exemplo n.º 3
0
        public bool RemoveRow(RowId rowId)
        {
            AssertNotDisposed();

            if (rowId.IsNull)
            {
                throw new ArgumentNullException("rowId");
            }

            if (rowId.TableId != TableId)
            {
                throw new ArgumentException("The table part of the ROWID is not this table.");
            }
            if (rowId.RowNumber < 0)
            {
                throw new ArgumentException("The number part of the ROWID is not valid for remove.");
            }

            if (Transaction.ReadOnly())
            {
                throw new Exception("Transaction is Read only.");
            }

            // Check this isn't a Read only source
            if (TableSource.IsReadOnly)
            {
                throw new InvalidOperationException("Can not remove row - table is Read only.");
            }

            // NOTE: This must <b>NOT</b> call 'RemoveRow' in TableSource.
            //   We do not want to delete a row permanently from the underlying
            //   file because the transaction using this data source may yet decide
            //   to roll back the change and not delete the row.

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.
            EventRegistry.Register(new TableRowEvent(rowId.TableId, rowId.RowNumber, TableRowEventType.Remove));

            return(true);
        }