Exemplo n.º 1
0
        public void Complete()
        {
            if (rowBufferId == 0)
            {
                throw new ApplicationException("State error: not in insert or update state");
            }

            // Create a new rowid
            long      rowid = GenerateId();
            IDataFile df    = GetDataFile(GetRowIdKey(rowid));

            // Build the row,
            RowBuilder builder = new RowBuilder(df);

            foreach (KeyValuePair <string, string> pair in rowBuffer)
            {
                builder.SetValue(GetColumnId(pair.Key), pair.Value);
            }

            // If the operation is insert or update,
            if (rowBufferId == -1)
            {
                // Insert,
                // Update the indexes
                AddRowToRowSet(rowid);
                AddRowToIndexSet(rowid);
                // Add this event to the transaction log,
                AddTransactionEvent("insertRow", rowid);
                ++currentVersion;
            }
            else
            {
                // Update,
                // Update the indexes
                RemoveRowFromRowSet(rowBufferId);
                RemoveRowFromIndexSet(rowBufferId);
                AddRowToRowSet(rowid);
                AddRowToIndexSet(rowid);
                // Add this event to the transaction log,
                AddTransactionEvent("deleteRow", rowBufferId);
                AddTransactionEvent("insertRow", rowid);
                IDataFile rowFile = GetDataFile(GetRowIdKey(rowBufferId));
                rowFile.Delete();
                ++currentVersion;
            }

            // Clear the row buffer, etc
            rowBufferId = 0;
            rowBuffer.Clear();
        }