public void Recalculate(IReadOnlyCollection <RecalculateAggregate> commands) { ApplyChangesToValueObjects(commands); var specification = _findSpecificationProvider.Create(commands); var mergeResult = _aggregateChangesDetector.DetectChanges(specification); _repository.Delete(mergeResult.Complement); _repository.Create(mergeResult.Difference); _repository.Update(mergeResult.Intersection); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { // db accessors var syncDataObjectCommands = commands.OfType <ISyncDataObjectCommand>().ToList(); if (syncDataObjectCommands.Count != 0) { foreach (var accessor in CreateAccessors(_query)) { var specification = accessor.GetFindSpecification(syncDataObjectCommands); var dataChangesDetector = new TwoPhaseDataChangesDetector <EntityName>( spec => accessor.GetSource().WhereMatched(spec), spec => _query.For <EntityName>().WhereMatched(spec), _identityComparer, _completeComparer); var changes = dataChangesDetector.DetectChanges(specification); _bulkRepository.Delete(changes.Complement); _bulkRepository.Create(changes.Difference); _bulkRepository.Update(changes.Intersection); } } // memory accessors var replaceDataObjectCommands = commands.OfType <IReplaceDataObjectCommand>().ToList(); if (replaceDataObjectCommands.Count != 0) { foreach (var accessor in CreateMemoryAccessors()) { var specification = accessor.GetFindSpecification(replaceDataObjectCommands); var dataChangesDetector = new TwoPhaseDataChangesDetector <EntityName>( _ => accessor.GetDataObjects(replaceDataObjectCommands), spec => _query.For <EntityName>().WhereMatched(spec), _identityComparer, _completeComparer); var changes = dataChangesDetector.DetectChanges(specification); _bulkRepository.Delete(changes.Complement); _bulkRepository.Create(changes.Difference); _bulkRepository.Update(changes.Intersection); } } return(Array.Empty <IEvent>()); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var commandsToExecute = commands.OfType <IReplaceValueObjectCommand>().Distinct().ToArray(); if (!commandsToExecute.Any()) { return(Array.Empty <IEvent>()); } var events = new List <IEvent>(); var changes = _changesProvider.GetChanges(commandsToExecute); var toDelete = changes.Complement.ToArray(); events.AddRange(_dataChangesHandler.HandleRelates(toDelete)); events.AddRange(_dataChangesHandler.HandleDeletes(toDelete)); _bulkRepository.Delete(toDelete); var toCreate = changes.Difference.ToArray(); _bulkRepository.Create(toCreate); events.AddRange(_dataChangesHandler.HandleCreates(toCreate)); events.AddRange(_dataChangesHandler.HandleRelates(toCreate)); return(events); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var commandsToExecute = commands.OfType <IDeleteInMemoryDataObjectCommand>() .Where(x => x.DataObjectType == typeof(TDataObject)) .Distinct() .ToArray(); if (!commandsToExecute.Any()) { return(Array.Empty <IEvent>()); } var events = new List <IEvent>(); var changes = _changesProvider.GetChanges(commandsToExecute); // Тут Intersection, а не Complement // Я так понял что DeleteDataObjectsActor там условие поиска по ParentId идёт, поэтому там Complement // а здесь условие поиска по Id, соответственно тут Intersection var toDelete = changes.Intersection.ToArray(); if (toDelete.Length != 0) { events.AddRange(_dataChangesHandler.HandleRelates(toDelete)); events.AddRange(_dataChangesHandler.HandleDeletes(toDelete)); _bulkRepository.Delete(toDelete); } return(events); }
public IReadOnlyCollection <IOperation> Execute(IReadOnlyCollection <FactOperation> commands) { var spec = _findSpecificationProvider.Create(commands.Select(x => x.FactId).ToArray()); var changes = _changesDetector.DetectChanges(spec); var result = new List <IOperation>(); var factsToCreate = changes.Difference.ToArray(); var factsToUpdate = changes.Intersection.ToArray(); var factsToDelete = changes.Complement.ToArray(); // Create _repository.Create(factsToCreate); result.AddRange(_depencencyProcessors.SelectMany(x => x.ProcessCreation(factsToCreate.Select(_identityProvider).ToArray()))); // Update result.AddRange(_indirectDepencencyProcessors.SelectMany(x => x.ProcessUpdating(factsToUpdate.Select(_identityProvider).ToArray()))); _repository.Update(factsToUpdate); result.AddRange(_depencencyProcessors.SelectMany(x => x.ProcessUpdating(factsToUpdate.Select(_identityProvider).ToArray()))); // Delete result.AddRange(_depencencyProcessors.SelectMany(x => x.ProcessDeletion(factsToDelete.Select(_identityProvider).ToArray()))); _repository.Delete(factsToDelete); return(result); }
private void DeleteFact(IReadOnlyCollection <long> ids) { var spec = _factMetadata.FindSpecificationProvider.Invoke(ids); var targetQueryable = _factMetadata.MapSpecificationProviderForTarget(spec).Map(_query); _repository.Delete(targetQueryable); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var commandsToExecute = commands.OfType <IDeleteDataObjectCommand>() .Where(x => x.DataObjectType == typeof(TDataObject)) .Distinct() .ToArray(); if (!commandsToExecute.Any()) { return(Array.Empty <IEvent>()); } var events = new List <IEvent>(); var changes = _changesProvider.GetChanges(commandsToExecute); var toDelete = changes.Complement.ToArray(); if (toDelete.Length != 0) { events.AddRange(_dataChangesHandler.HandleRelates(toDelete)); events.AddRange(_dataChangesHandler.HandleDeletes(toDelete)); _bulkRepository.Delete(toDelete); } return(events); }
public void ApplyChanges(IReadOnlyCollection <long> ids) { var mergeResult = _changesDetector.DetectChanges(Specs.Map.ZeroMapping <T>(), _metadata.FindSpecificationProvider.Invoke(ids), _equalityComparerFactory.CreateIdentityComparer <T>()); _repository.Delete(mergeResult.Complement); _repository.Create(mergeResult.Difference); _repository.Update(mergeResult.Intersection); }
public void Execute(IReadOnlyCollection <AggregateOperation> commands) { var spec = _findSpecificationProvider.Create(commands); var mergeResult = _changesDetector.DetectChanges(spec); _repository.Delete(mergeResult.Complement); _repository.Create(mergeResult.Difference); }
public void Recalculate(IReadOnlyCollection <long> ids) { ApplyChangesToValueObjects(ids); var mergeResult = _aggregateChangesDetector.DetectChanges(Specs.Map.ToIds <T>(), _metadata.FindSpecificationProvider.Invoke(ids), EqualityComparer <long> .Default); var createFilter = _metadata.FindSpecificationProvider.Invoke(mergeResult.Difference.ToArray()); var updateFilter = _metadata.FindSpecificationProvider.Invoke(mergeResult.Intersection.ToArray()); var deleteFilter = _metadata.FindSpecificationProvider.Invoke(mergeResult.Complement.ToArray()); var aggregatesToCreate = _metadata.MapSpecificationProviderForSource.Invoke(createFilter).Map(_query).ToArray(); var aggregatesToUpdate = _metadata.MapSpecificationProviderForSource.Invoke(updateFilter).Map(_query).ToArray(); var aggregatesToDelete = _metadata.MapSpecificationProviderForTarget.Invoke(deleteFilter).Map(_query).ToArray(); _repository.Delete(aggregatesToDelete); _repository.Create(aggregatesToCreate); _repository.Update(aggregatesToUpdate); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { // db accessors var syncDataObjectCommands = commands.OfType <ISyncDataObjectCommand>().ToList(); if (syncDataObjectCommands.Count != 0) { foreach (var accessor in CreateAccessors(_query).Select(AddTenancy)) { var specification = accessor.GetFindSpecification(syncDataObjectCommands); var source = accessor.GetSource().WhereMatched(specification); var target = _query.For <EntityName>() .Where(new FindSpecification <EntityName>(x => x.TenantId == _tenantProvider.Current)) .WhereMatched(specification); var changes = _dataChangesDetector.DetectChanges(source, target); _bulkRepository.Delete(changes.Complement); _bulkRepository.Create(changes.Difference); _bulkRepository.Update(changes.Intersection); } } // memory accessors var syncInMemoryDataObjectCommands = commands.OfType <ISyncInMemoryDataObjectCommand>().ToList(); if (syncInMemoryDataObjectCommands.Count != 0) { foreach (var accessor in CreateMemoryAccessors()) { var specification = accessor.GetFindSpecification(syncInMemoryDataObjectCommands); var source = accessor.GetDataObjects(syncInMemoryDataObjectCommands); var target = _query.For <EntityName>().WhereMatched(specification); var changes = _dataChangesDetector.DetectChanges(source, target); _bulkRepository.Delete(changes.Complement); _bulkRepository.Create(changes.Difference); _bulkRepository.Update(changes.Intersection); } } return(Array.Empty <IEvent>()); }
public void Complete( IEnumerable <IMessage> successfullyProcessedMessages, IEnumerable <IMessage> failedProcessedMessages) { var processedRecords = successfullyProcessedMessages .Select(x => new EventRecord { Id = ToLong(x.Id) }); _bulkRepository.Delete(processedRecords); }
public void Execute(IReadOnlyCollection <RecalculateStatisticsOperation> commands) { var filter = _metadata.FindSpecificationProvider.Invoke(commands.Select(c => c.EntityId).ToArray()); // Сначала сравниением получаем различающиеся записи, // затем получаем те из различающихся, которые совпадают по идентификатору. var intermediateResult = _changesDetector.DetectChanges(filter); var changes = MergeTool.Merge(intermediateResult.Difference, intermediateResult.Complement, _equalityComparerFactory.CreateIdentityComparer <T>()); _repository.Delete(changes.Complement); _repository.Create(changes.Difference); _repository.Update(changes.Intersection); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var commandsToExecute = commands.OfType <ISyncInMemoryDataObjectCommand>() .Where(x => x.DataObjectType == typeof(TDataObject)) .ToHashSet(); if (commandsToExecute.Count == 0) { return(Array.Empty <IEvent>()); } var events = new List <IEvent>(); using var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TimeSpan.Zero }); var changes = _changesProvider.GetChanges(commandsToExecute); var toDelete = changes.Complement.ToArray(); if (toDelete.Length != 0) { events.AddRange(_dataChangesHandler.HandleRelates(toDelete)); events.AddRange(_dataChangesHandler.HandleDeletes(toDelete)); _bulkRepository.Delete(toDelete); } var toCreate = changes.Difference.ToArray(); if (toCreate.Length != 0) { _bulkRepository.Create(toCreate); events.AddRange(_dataChangesHandler.HandleCreates(toCreate)); events.AddRange(_dataChangesHandler.HandleRelates(toCreate)); } var toUpdate = changes.Intersection.ToArray(); if (toUpdate.Length != 0) { events.AddRange(_dataChangesHandler.HandleRelates(toUpdate)); _bulkRepository.Update(toUpdate); events.AddRange(_dataChangesHandler.HandleRelates(toUpdate)); events.AddRange(_dataChangesHandler.HandleUpdates(toUpdate)); } transaction.Complete(); return(events); }
private IReadOnlyCollection <IOperation> Import(TDto statisticsDto) { using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TimeSpan.Zero })) { _repository.Delete(_query.For(_importStatisticsMetadata.FindSpecificationProvider.Invoke(statisticsDto))); _repository.Create(_importStatisticsMetadata.MapSpecification.Map(statisticsDto)); transaction.Complete(); } return(_importStatisticsMetadata.RecalculationSpecification.Map(statisticsDto)); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var commandsToExecute = commands.OfType <ISyncDataObjectCommand>() .Where(x => x.DataObjectType == typeof(TDataObject)) .ToHashSet(); if (commandsToExecute.Count == 0) { return(Array.Empty <IEvent>()); } var events = new List <IEvent>(); var changes = _changesProvider.GetChanges(commandsToExecute); var toDelete = changes.Complement.ToArray(); if (toDelete.Length != 0) { events.AddRange(_dataChangesHandler.HandleRelates(toDelete)); events.AddRange(_dataChangesHandler.HandleDeletes(toDelete)); _bulkRepository.Delete(toDelete); } var toCreate = changes.Difference.ToArray(); if (toCreate.Length != 0) { _bulkRepository.Create(toCreate); events.AddRange(_dataChangesHandler.HandleCreates(toCreate)); events.AddRange(_dataChangesHandler.HandleRelates(toCreate)); } var toUpdate = changes.Intersection.ToArray(); if (toUpdate.Length != 0) { events.AddRange(_dataChangesHandler.HandleRelates(toUpdate)); _bulkRepository.Update(toUpdate); events.AddRange(_dataChangesHandler.HandleRelates(toUpdate)); events.AddRange(_dataChangesHandler.HandleUpdates(toUpdate)); } return(events); }
public IReadOnlyCollection <IEvent> ExecuteCommands(IReadOnlyCollection <ICommand> commands) { var commandsToExecute = commands.OfType <IReplaceDataObjectCommand>() .Where(x => x.DataObjectType == typeof(TDataObject)) .Distinct() .ToArray(); if (!commandsToExecute.Any()) { return(Array.Empty <IEvent>()); } var events = new List <IEvent>(); foreach (var command in commandsToExecute) { using (var transaction = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TimeSpan.Zero })) { var findSpecification = _memoryBasedDataObjectAccessor.GetFindSpecification(command); var existingDataObjects = _query.For(findSpecification) .ToList(); if (existingDataObjects.Any()) { events.AddRange(_dataChangesHandler.HandleRelates(existingDataObjects)); _bulkRepository.Delete(existingDataObjects); } var targetDataObjects = _memoryBasedDataObjectAccessor.GetDataObjects(command); if (targetDataObjects.Any()) { _bulkRepository.Create(targetDataObjects); events.AddRange(_dataChangesHandler.HandleCreates(targetDataObjects)); events.AddRange(_dataChangesHandler.HandleRelates(targetDataObjects)); } transaction.Complete(); } } return(events); }
public void Execute(DateTime archiveDate) { var versions = _query.For <Version>().Where(x => x.UtcDateTime < archiveDate).OrderByDescending(x => x.Id).ToList(); if (versions.Count > 1) { var keepVersion = versions.First(); var keepValidationResults = _query.For <Version.ValidationResult>().ForVersion(keepVersion.Id).ApplyVersionId(keepVersion.Id).ToList(); _validationResultDeleteRepository.Delete(versions.Select(x => new Version.ValidationResultBulkDelete { VersionId = x.Id })); _ermStateDeleteRepository.Delete(versions.Select(x => new Version.ErmStateBulkDelete { VersionId = x.Id })); _amsStateDeleteRepository.Delete(versions.Select(x => new Version.AmsStateBulkDelete { VersionId = x.Id })); _versionDeleteRepository.Delete(versions.Skip(1)); _validationResultRepository.Create(keepValidationResults); } }
public void Import(TDto statisticsDto) { _repository.Delete(_query.For(_feature.FindSpecificationProvider.Invoke(statisticsDto))); _repository.Create(_feature.MapSpecification.Map(statisticsDto)); }