public void Append(IStorageOperation operation) { Count++; operation.ConfigureCommand(_builder, _session); _builder.Append(";"); _operations.Add(operation); }
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)); } }
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)); } }
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); } } }
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); }
public void Add(IStorageOperation operation) { var batch = Current(); operation.AddParameters(batch); batch.AddCall(operation, operation as ICallback); }
private void processOperation(IStorageOperation operation) { _current.Append(operation); if (_current.Count >= _session.Options.UpdateBatchSize) { startNewPage(_session); } }
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); }
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); } }
public void Add(IStorageOperation operation) { if (operation.DocumentType == null) { _ancillaryOperations.Add(operation); } else { var list = operationsFor(operation.DocumentType); list.Add(operation); } }
private void processOperation(IStorageOperation operation) { if (_token.IsCancellationRequested) { return; } _current.Append(operation); if (_current.Count >= _session.Options.UpdateBatchSize) { startNewPage(_session); } }
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); } }
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); }
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); } }
public void QueueOperation(IStorageOperation storageOperation) { _unitOfWork.Add(storageOperation); }
public void QueueOperation(IStorageOperation storageOperation) { _workTracker.Add(storageOperation); }
public void QueueOperation(IStorageOperation storageOperation) { assertNotDisposed(); _unitOfWork.Add(storageOperation); }
void ISessionWorkTracker.Add(IStorageOperation operation) { Queue.Post(operation); }
public void Add(IStorageOperation operation) { _operations.Add(operation); }
public void AddCall(IStorageOperation call, ICallback callback = null) { Calls.Add(call); Callbacks.Add(callback); }
public void AddCall(IStorageOperation call, ICallback callback = null, IExceptionTransform exceptionTransform = null) { Calls.Add(call); Callbacks.Add(callback); ExceptionTransforms.Add(exceptionTransform); }