Esempio n. 1
0
        private static void Update(DbConnection db, ISagaState data, string correlationId)
        {
            var old    = data.AutoTimestamp;
            var result = db.Update <SagaRow>()
                         .Set(d => d.Data, data.Serialize().ToByteArray())
                         .Set(d => d.Version, data.AutoTimestamp)
                         .Set(d => d.LastChangedOn, DateTime.UtcNow)
                         .Set(d => d.IsCompleted, data.IsCompleted)
                         .Where(d => d.SagaId == SagaRow.GetId(correlationId, data.GetType()) && d.Version == old)
                         .Execute();

            if (result != 1)
            {
                throw new SagaConcurrencyException();
            }
        }
Esempio n. 2
0
 public ISagaState GetSaga(string correlationId, Type sagaStateType)
 {
     try
     {
         return(_db.RetryOnTransientError(db =>
         {
             var data = db.WithSql(q => q.From <SagaRow>()
                                   .Where(d => d.SagaId == SagaRow.GetId(correlationId, sagaStateType))
                                   .Select(d => d.Data)).GetValue();
             return data?.Deserialize <ISagaState>();
         }));
     }
     catch (DbException ex)
     {
         throw new BusStorageException("", ex);
     }
 }
Esempio n. 3
0
 private static void Insert(DbConnection db, ISagaState data, string correlationId)
 {
     try
     {
         db.Insert(new SagaRow()
         {
             SagaId        = SagaRow.GetId(correlationId, data.GetType()),
             Data          = data.Serialize().ToByteArray(),
             IsCompleted   = false,
             LastChangedOn = DateTime.UtcNow,
             Version       = data.AutoTimestamp
         });
     }
     catch (DbException ex)
     {
         if (db.IsUniqueViolation(ex))
         {
             throw new SagaExistsException();
         }
     }
 }