Example #1
0
        public virtual void Commit(Commit attempt)
        {
            Logger.Debug(Messages.AttemptingToCommit, attempt.Events.Count, attempt.StreamId, attempt.CommitSequence, attempt.BucketId);

            try
            {
                TryRaven(() =>
                {
                    using (TransactionScope scope = OpenCommandScope())
                        using (IDocumentSession session = _store.OpenSession())
                        {
                            session.Advanced.UseOptimisticConcurrency = true;
                            var doc = attempt.ToRavenCommit(_serializer);
                            session.Store(doc);
                            session.SaveChanges();
                            scope.Complete();
                        }

                    Logger.Debug(Messages.CommitPersisted, attempt.CommitId, attempt.BucketId);
                    SaveStreamHead(attempt.ToRavenStreamHead());
                    return(true);
                });
            }
            catch (Raven.Abstractions.Exceptions.ConcurrencyException)
            {
                RavenCommit savedCommit = LoadSavedCommit(attempt);
                if (savedCommit.CommitId == attempt.CommitId)
                {
                    throw new DuplicateCommitException();
                }

                Logger.Debug(Messages.ConcurrentWriteDetected);
                throw new ConcurrencyException();
            }
        }
Example #2
0
 public static Commit ToCommit(this RavenCommit commit, IDocumentSerializer serializer)
 {
     return(new Commit(commit.StreamId,
                       commit.StreamRevision,
                       commit.CommitId,
                       commit.CommitSequence,
                       commit.CommitStamp,
                       commit.Headers,
                       serializer.Deserialize <List <EventMessage> >(commit.Payload)));
 }