An implementation of IEnlistmentNotification for the Raven Client API, allowing Raven Client API to participate in Distributed Transactions
상속: IEnlistmentNotification
예제 #1
0
        public void SaveChanges()
        {
            if (enlistment == null && Transaction.Current != null)
            {
                enlistment = new RavenClientEnlistment(this, Transaction.Current.TransactionInformation.DistributedIdentifier);
                Transaction.Current.EnlistVolatile(enlistment, EnlistmentOptions.None);
            }
            var entities           = new List <object>();
            var cmds               = new List <ICommandData>();
            DocumentMetadata value = null;

            foreach (var key in (from deletedEntity in deletedEntities
                                 where entitiesAndMetadata.TryGetValue(deletedEntity, out value)
                                 select value.Key))
            {
                Guid?  etag = null;
                object existingEntity;
                if (entitiesByKey.TryGetValue(key, out existingEntity))
                {
                    DocumentMetadata metadata;
                    if (entitiesAndMetadata.TryGetValue(existingEntity, out metadata))
                    {
                        etag = metadata.ETag;
                    }
                    entitiesAndMetadata.Remove(existingEntity);
                }

                etag = UseOptimisticConcurrency ? etag : null;
                entities.Add(existingEntity);
                cmds.Add(new DeleteCommandData
                {
                    Etag = etag,
                    Key  = key,
                });
            }
            deletedEntities.Clear();
            foreach (var entity in entitiesAndMetadata.Where(EntityChanged))
            {
                entities.Add(entity.Key);
                if (entity.Value.Key != null)
                {
                    entitiesByKey.Remove(entity.Value.Key);
                }
                cmds.Add(CreatePutEntityCommand(entity.Key, entity.Value));
            }

            if (cmds.Count == 0)
            {
                return;
            }

            IncrementRequestCount();
            Trace.WriteLine(string.Format("Saving {0} changes to {1}", cmds.Count, StoreIdentifier));
            UpdateBatchResults(database.Batch(cmds.ToArray()), entities);
        }
예제 #2
0
 public void Rollback(Guid txId)
 {
     IncrementRequestCount();
     documentStore.DatabaseCommands.Rollback(txId);
     enlistment = null;
 }
예제 #3
0
 public void Commit(Guid txId)
 {
     IncrementRequestCount();
     documentStore.DatabaseCommands.Commit(txId);
     enlistment = null;
 }