Exemple #1
0
        void PersistJournal(TransactionJournal transactionJournal)
        {
            var bson = this.Session.SerializerResolver.SerializerFor <TransactionJournal>()
                       .Serialize(transactionJournal);

            this.JournalWriter.Write(0,
                                     new BufferWriter(new byte[sizeof(int)])
                                     .WriteInt32(bson.Length).GetTrimmedBuffer()
                                     );
            this.JournalWriter.Write(sizeof(int), bson);
        }
        void PersistJournal(TransactionJournal transactionJournal)
        {
            var bson = this.Session.SerializerResolver.SerializerFor <TransactionJournal>()
                       .Serialize(transactionJournal);

            //First write the journal's data, as long as the size is 0, we can still fail
            this.JournalWriter.Write(sizeof(Int32), bson);

            //Overwrite the journal size
            this.JournalWriter.Write(0,
                                     new BufferWriter(new byte [sizeof(Int32)])
                                     .WriteInt32(bson.Length).GetTrimmedBuffer()
                                     );
        }
        internal void Commit()
        {
            if (this.UncommittedEntries.Count == 0)
            {
                return;
            }

            var transactionJournal = new TransactionJournal();

            foreach (var entry in this.UncommittedEntries)
            {
                transactionJournal.Entries.Add(entry);
            }
            PersistJournal(transactionJournal);
            this.ClearUncommitted();
        }