public void Save(string bucketId, IAggregate aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { Dictionary <string, object> headers = PrepareHeaders(aggregate, updateHeaders); while (true) { IEventStream stream = PrepareStream(bucketId, aggregate, headers); int commitEventCount = stream.CommittedEvents.Count; try { stream.CommitChanges(commitId); aggregate.ClearUncommittedEvents(); return; } catch (DuplicateCommitException) { stream.ClearChanges(); return; } catch (ConcurrencyException e) { var conflict = ThrowOnConflict(stream, commitEventCount); stream.ClearChanges(); if (conflict) { throw new ConflictingCommandException(e.Message, e); } } catch (StorageException e) { throw new PersistenceException(e.Message, e); } } }
/// <summary> /// /// </summary> /// <param name="bucketId"></param> /// <param name="aggregate"></param> /// <param name="commitId"></param> /// <param name="updateHeaders"></param> /// <returns></returns> public Int32 Save(string bucketId, IAggregateEx aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { if (_disposed) { throw new ObjectDisposedException("This instance of repository was already disposed"); } Dictionary <string, object> headers = PrepareHeaders(aggregate, updateHeaders); Int32 uncommittedEvents = aggregate.GetUncommittedEvents().Count; while (true) { IEventStream stream = this.PrepareStream(bucketId, aggregate, headers); int commitEventCount = stream.CommittedEvents.Count; try { stream.CommitChanges(commitId); aggregate.ClearUncommittedEvents(); return(uncommittedEvents); } catch (DuplicateCommitException dex) { stream.ClearChanges(); _logger.Debug(String.Format("Duplicate commit exception bucket {0} - id {1} - commitid {2}. \n{3}", bucketId, aggregate.Id, commitId, dex)); return(0); //no events commited } catch (ConcurrencyException e) { _logger.Warn(String.Format("Concurrency Exception bucket {0} - id {1} - commitid {2}. \n{3}", bucketId, aggregate.Id, commitId, e)); if (this.ThrowOnConflict(stream, commitEventCount)) { //@@FIX -> aggiungere prima del lancio dell'eccezione stream.ClearChanges(); throw new ConflictingCommandException(e.Message, e); } stream.ClearChanges(); } catch (StorageException e) { throw new PersistenceException(e.Message, e); } finally { ReleaseAggregateId(aggregate.Id); } } }
void CommitStream(Guid commitId, IEventStream toCommit) { try { toCommit.CommitChanges(commitId); } catch (DuplicateCommitException) { toCommit.ClearChanges(); } catch (ConcurrencyException) { toCommit.ClearChanges(); throw; } }
public void Save(string bucketId, IAggregateEx aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { Dictionary <string, object> headers = PrepareHeaders(aggregate, updateHeaders); while (true) { IEventStream stream = this.PrepareStream(bucketId, aggregate, headers); int commitEventCount = stream.CommittedEvents.Count; try { stream.CommitChanges(commitId); aggregate.ClearUncommittedEvents(); return; } catch (DuplicateCommitException) { stream.ClearChanges(); return; } catch (ConcurrencyException e) { if (this.ThrowOnConflict(stream, commitEventCount)) { //@@FIX -> aggiungere prima del lancio dell'eccezione stream.ClearChanges(); throw new ConflictingCommandException(e.Message, e); } stream.ClearChanges(); } catch (StorageException e) { throw new PersistenceException(e.Message, e); } finally { ReleaseAggregateId(aggregate.Id); } } }
public void Save(string bucketId, IAggregate aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { Dictionary <string, object> headers = PrepareHeaders(aggregate, updateHeaders); while (true) { IEventStream stream = PrepareStream(bucketId, aggregate, headers); int commitEventCount = stream.CommittedEvents.Count; try { stream.CommitChanges(commitId); aggregate.ClearUncommittedEvents(); return; } catch (DuplicateCommitException) { stream.ClearChanges(); // Issue: #4 and test: when_an_aggregate_is_persisted_using_the_same_commitId_twice // should we rethtow the exception here? or provide a feedback whether the save was successful ? return; } catch (ConcurrencyException e) { var conflict = ThrowOnConflict(stream, commitEventCount); stream.ClearChanges(); if (conflict) { throw new ConflictingCommandException(e.Message, e); } } catch (StorageException e) { throw new PersistenceException(e.Message, e); } } }
static void Persist(IEventStream stream, Guid commitId) { try { stream.CommitChanges(commitId); } catch (DuplicateCommitException) { stream.ClearChanges(); } catch (StorageException e) { throw new PersistenceException(e.Message, e); } }