예제 #1
0
 public void Append(IStorageOperation operation)
 {
     Count++;
     operation.ConfigureCommand(_builder, _session);
     _builder.Append(";");
     _operations.Add(operation);
 }
예제 #2
0
        public void DeleteByIdInTenant <T>(string tenantId, int id)
        {
            assertNotDisposed();

            var tenant  = DocumentStore.Tenancy[tenantId];
            var storage = selectStorage(tenant.Providers.StorageFor <T>());

            IStorageOperation deletion = null;

            if (storage is IDocumentStorage <T, int> i)
            {
                _unitOfWork.Add(i.DeleteForId(id, tenant));

                ejectById <T>(id);
            }
            else if (storage is IDocumentStorage <T, long> l)
            {
                _unitOfWork.Add(l.DeleteForId(id, tenant));

                ejectById <T>((long)id);
            }
            else
            {
                throw new DocumentIdTypeMismatchException(storage, typeof(int));
            }
        }
예제 #3
0
        public void Delete <T>(int id)
        {
            assertNotDisposed();

            var storage = StorageFor <T>();

            IStorageOperation deletion = null;

            if (storage is IDocumentStorage <T, int> i)
            {
                _unitOfWork.Add(i.DeleteForId(id));

                ejectById <T>(id);
            }
            else if (storage is IDocumentStorage <T, long> l)
            {
                _unitOfWork.Add(l.DeleteForId(id));

                ejectById <T>((long)id);
            }
            else
            {
                throw new DocumentIdTypeMismatchException(storage, typeof(int));
            }
        }
예제 #4
0
        public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList <StreamAction> streams,
                                     CancellationToken cancellation)
        {
            // Doing the filtering here to prevent unnecessary network round trips by allowing
            // an aggregate projection to "work" on a stream with no matching events
            var filteredStreams = streams
                                  .Where(x => Projection.AppliesTo(x.Events.Select(x => x.EventType)))
                                  .ToArray();

            var slices = Slicer.Slice(filteredStreams, Tenancy);

            var martenSession = (DocumentSessionBase)operations;

            foreach (var slice in slices)
            {
                IStorageOperation operation = null;

                // TODO -- this can only apply to the last event
                if (Projection.MatchesAnyDeleteType(slice))
                {
                    operation = Storage.DeleteForId(slice.Id, slice.Tenant);
                }
                else
                {
                    operation = await DetermineOperation(martenSession, slice, cancellation);
                }

                if (operation != null)
                {
                    operations.QueueOperation(operation);
                }
            }
        }
예제 #5
0
        internal void Start(IShardAgent shardAgent, ActionBlock <IStorageOperation> queue,
                            AggregationRuntime <TDoc, TId> runtime,
                            IDocumentStore store, EventRangeGroup parent)
        {
            _builder = new TransformBlock <EventSlice <TDoc, TId>, IStorageOperation>(async slice =>
            {
                if (parent.Cancellation.IsCancellationRequested)
                {
                    return(null);
                }

                IStorageOperation operation = null;

                await shardAgent.TryAction(async() =>
                {
                    using var session = (DocumentSessionBase)store.LightweightSession(slice.Tenant.TenantId);

                    operation = await runtime.DetermineOperation(session, slice, parent.Cancellation, ProjectionLifecycle.Async);
                }, parent.Cancellation, group: parent, logException: (l, e) =>
                {
                    l.LogError(e, "Failure trying to build a storage operation to update {DocumentType} with {Id}", typeof(TDoc).FullNameInCode(), slice.Id);
                }, actionMode: GroupActionMode.Child);

                return(operation);
            }, new ExecutionDataflowBlockOptions
            {
                CancellationToken = parent.Cancellation,
            });

            _builder.LinkTo(queue, x => x != null);

            _application = Task.Factory.StartNew(() =>
                                                 processEventSlices(shardAgent, runtime, store, parent.Cancellation)
                                                 , parent.Cancellation);
        }
예제 #6
0
        public void Add(IStorageOperation operation)
        {
            var batch = Current();

            operation.AddParameters(batch);

            batch.AddCall(operation, operation as ICallback);
        }
예제 #7
0
        public void Add(IStorageOperation operation)
        {
            var batch = Current();

            operation.AddParameters(batch);

            batch.AddCall(operation, operation as ICallback);
        }
예제 #8
0
        private void processOperation(IStorageOperation operation)
        {
            _current.Append(operation);

            if (_current.Count >= _session.Options.UpdateBatchSize)
            {
                startNewPage(_session);
            }
        }
예제 #9
0
        public void Add(IStorageOperation operation)
        {
            if (operation is IDocumentStorageOperation o)
            {
                _operations.RemoveAll(x =>
                                      x is IDocumentStorageOperation && x.As <IDocumentStorageOperation>().Document == o.Document);
            }

            _operations.Add(operation);
        }
예제 #10
0
 public void Add(IStorageOperation operation)
 {
     if (operation.DocumentType == null)
     {
         _ancillaryOperations.Add(operation);
     }
     else
     {
         var list = _operations.GetOrAdd(operation.DocumentType, type => new List <IStorageOperation>());
         list.Add(operation);
     }
 }
예제 #11
0
 public void Add(IStorageOperation operation)
 {
     if (operation.DocumentType == null)
     {
         _ancillaryOperations.Add(operation);
     }
     else
     {
         var list = operationsFor(operation.DocumentType);
         list.Add(operation);
     }
 }
예제 #12
0
        private void processOperation(IStorageOperation operation)
        {
            if (_token.IsCancellationRequested)
            {
                return;
            }

            _current.Append(operation);

            if (_current.Count >= _session.Options.UpdateBatchSize)
            {
                startNewPage(_session);
            }
        }
예제 #13
0
        public void Add(IStorageOperation operation)
        {
            if (operation is IDocumentStorageOperation o)
            {
                _operations.RemoveAll(x =>
                                      x is IDocumentStorageOperation && x.As <IDocumentStorageOperation>().Document == o.Document);
            }

            if (operation.DocumentType == typeof(IEvent))
            {
                _eventOperations.Add(operation);
            }
            else
            {
                _operations.Add(operation);
            }
        }
예제 #14
0
        public bool DetectChanges(IMartenSession session, out IStorageOperation operation)
        {
            var newJson = session.Serializer.ToCleanJson(_document);

            if (JToken.DeepEquals(JObject.Parse(_json), JObject.Parse(newJson)))
            {
                operation = null;
                return(false);
            }

            operation = session
                        .Database
                        .Providers.StorageFor <T>()
                        .DirtyTracking
                        .Upsert(_document, session, session.TenantId);

            return(true);
        }
예제 #15
0
        public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList <StreamAction> streams,
                                     CancellationToken cancellation)
        {
            var slices = Slicer.Slice(streams, Tenancy);

            var martenSession = (DocumentSessionBase)operations;

            foreach (var slice in slices)
            {
                IStorageOperation operation = null;
                if (Projection.MatchesAnyDeleteType(slice))
                {
                    operation = Storage.DeleteForId(slice.Id, slice.Tenant);
                }
                else
                {
                    operation = await DetermineOperation(martenSession, slice, cancellation);
                }

                operations.QueueOperation(operation);
            }
        }
예제 #16
0
 public void QueueOperation(IStorageOperation storageOperation)
 {
     _unitOfWork.Add(storageOperation);
 }
예제 #17
0
 public void QueueOperation(IStorageOperation storageOperation)
 {
     _workTracker.Add(storageOperation);
 }
예제 #18
0
 public void QueueOperation(IStorageOperation storageOperation)
 {
     assertNotDisposed();
     _unitOfWork.Add(storageOperation);
 }
예제 #19
0
 void ISessionWorkTracker.Add(IStorageOperation operation)
 {
     Queue.Post(operation);
 }
예제 #20
0
 public void Add(IStorageOperation operation)
 {
     _operations.Add(operation);
 }
예제 #21
0
 public void AddCall(IStorageOperation call, ICallback callback = null)
 {
     Calls.Add(call);
     Callbacks.Add(callback);
 }
예제 #22
0
 public void AddCall(IStorageOperation call, ICallback callback = null, IExceptionTransform exceptionTransform = null)
 {
     Calls.Add(call);
     Callbacks.Add(callback);
     ExceptionTransforms.Add(exceptionTransform);
 }