Exemple #1
0
        public void Update(DbRow row)
        {
            if (rowBufferId != 0)
            {
                throw new ApplicationException("State error: previous table operation not completed");
            }

            // Check row is currently indexed,
            long        rowid = row.RowId;
            IDataFile   df    = GetDataFile(rowIndexKey);
            SortedIndex rows  = new SortedIndex(df);

            if (!rows.ContainsSortKey(rowid))
            {
                throw new ApplicationException("Row being updated is not in the table");
            }

            if (rowBuffer == null)
            {
                rowBuffer = new Dictionary <string, string>();
            }

            rowBufferId = rowid;

            // Copy from the existing data in the row,
            string[] cols = ColumnNames;
            foreach (string col in cols)
            {
                string val = row.GetValue(col);
                if (val != null)
                {
                    rowBuffer[col] = val;
                }
            }
        }
Exemple #2
0
        public int Delete(IEnumerator <DbRow> rows)
        {
            int deleteCount = 0;

            while (rows.MoveNext())
            {
                DbRow row = rows.Current;
                if (row == null)
                {
                    continue;
                }

                long        rowid     = row.RowId;
                IDataFile   df        = GetDataFile(rowIndexKey);
                SortedIndex rowsIndex = new SortedIndex(df);
                if (rowsIndex.ContainsSortKey(rowid))
                {
                    // Remove the row from the main index,
                    RemoveRowFromRowSet(rowid);
                    // Remove the row from any indexes defined on the table,
                    RemoveRowFromIndexSet(rowid);
                    // Delete the row file
                    IDataFile rowFile = GetDataFile(GetRowIdKey(rowid));
                    rowFile.Delete();

                    // Add this event to the transaction log,
                    AddTransactionEvent("deleteRow", rowid);
                    deleteCount++;
                }
            }

            ++currentVersion;
            return(deleteCount);
        }
Exemple #3
0
 public void CheckTableDataDelete(String table, long rowid)
 {
     // Is it in the modification set?
     if (tableDataChanged != null)
     {
         DbTable t;
         if (tableDataChanged.TryGetValue(table, out t))
         {
             // Yes, so check if the given row in the modification set,
             SortedIndex deleteSet = t.Deletes;
             if (deleteSet.ContainsSortKey(rowid))
             {
                 // Yes, so generate a commit fault,
                 throw new CommitFaultException(String.Format("Row in Table ''{0}'' was modified by a concurrent transaction",
                                                              table));
             }
         }
     }
 }
Exemple #4
0
        public void BeginUpdate(long rowid)
        {
            if (rowBufferId != 0)
            {
                throw new ApplicationException("State error: previous table operation not completed");
            }

            // Check row is currently indexed,
            IDataFile   df   = GetDataFile(rowIndexKey);
            SortedIndex rows = new SortedIndex(df);

            if (!rows.ContainsSortKey(rowid))
            {
                throw new ApplicationException("Row being updated is not in the table");
            }

            if (rowBuffer == null)
            {
                rowBuffer = new Dictionary <string, string>();
            }

            rowBufferId = rowid;
        }
Exemple #5
0
        public void Delete(DbRow row)
        {
            long        rowid = row.RowId;
            IDataFile   df    = GetDataFile(rowIndexKey);
            SortedIndex rows  = new SortedIndex(df);

            if (!rows.ContainsSortKey(rowid))
            {
                throw new ApplicationException("Row being deleted is not in the table");
            }

            // Remove the row from the main index,
            RemoveRowFromRowSet(rowid);
            // Remove the row from any indexes defined on the table,
            RemoveRowFromIndexSet(rowid);
            // Delete the row file
            IDataFile rowFile = GetDataFile(GetRowIdKey(rowid));

            rowFile.Delete();

            // Add this event to the transaction log,
            AddTransactionEvent("deleteRow", rowid);
            ++currentVersion;
        }
Exemple #6
0
        internal void PrepareForCommit()
        {
            // Write the transaction log for this table,
            IDataFile df = GetDataFile(AddLog);

            df.Delete();
            SortedIndex addlist = new SortedIndex(df);

            foreach (long v in addRowList)
            {
                addlist.InsertSortKey(v);
            }

            df = GetDataFile(RemoveLog);
            df.Delete();
            SortedIndex deletelist = new SortedIndex(df);

            foreach (long v in deleteRowList)
            {
                if (addlist.ContainsSortKey(v))
                {
                    addlist.RemoveSortKey(v);
                }
                else
                {
                    deletelist.InsertSortKey(v);
                }
            }

            // Set the id gen key
            if (currentIdGen != -1)
            {
                StringDictionary p = TableProperties;
                p.SetValue("k", currentIdGen);
            }
        }