From b7eceb4751fb3565c12ec305c8911c2aaf083d7d Mon Sep 17 00:00:00 2001 From: "amir.jabari" Date: Mon, 7 Mar 2022 10:51:43 +0000 Subject: [PATCH 1/2] Update DynamoDB provider. --- .../DynamoDBDataProvider.cs | 38 +++++++++++++++---- .../Olive.Entities.Data.DynamoDB.csproj | 5 ++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs b/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs index 435bcf638..0fd951c11 100644 --- a/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs +++ b/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs @@ -32,19 +32,23 @@ public Task Aggregate(IDatabaseQuery query, AggregateFunction function, throw new NotImplementedException(); } - public Task BulkInsert(IEntity[] entities, int batchSize) + public async Task BulkInsert(IEntity[] entities, int batchSize) { var writer = Dynamo.Db.CreateBatchWrite(); writer.AddPutItems(entities.Cast()); - return writer.ExecuteAsync(); + await writer.ExecuteAsync(); + + SetIsNewAndOriginalId(entities); } - public Task BulkUpdate(IEntity[] entities, int batchSize) + public async Task BulkUpdate(IEntity[] entities, int batchSize) { var writer = Dynamo.Db.CreateBatchWrite(); entities.Do(x => writer.AddDeleteKey(x.GetId())); writer.AddPutItems(entities.Cast()); - return writer.ExecuteAsync(); + await writer.ExecuteAsync(); + + SetIsNewAndOriginalId(entities); } public Task Count(IDatabaseQuery query) => GetList(query).Count(); @@ -62,7 +66,8 @@ public string GenerateSelectCommand(IDatabaseQuery iquery, string fields) public async Task Get(object objectID) { - return (IEntity)await Dynamo.Table().Get(objectID); + var result = (IEntity)await Dynamo.Table().Get(objectID); + return SetIsNewAndOriginalId(result); } public DirectDatabaseCriterion GetAssociationInclusionCriteria(IDatabaseQuery masterQuery, PropertyInfo association) @@ -96,6 +101,8 @@ async Task> FindByHashKey(IDatabaseQuery query) if (hashKeyInfo.Value is null) return Enumerable.Empty(); var item = await Get(hashKeyInfo.Value); if (item is null) return Enumerable.Empty(); + + SetIsNewAndOriginalId(item); return new[] { item }; } @@ -121,7 +128,9 @@ async Task> FindByIndex(IDatabaseQuery query) if (indexInfo.IsIndex) { if (indexInfo.Value is null) return Enumerable.Empty(); - return (await Dynamo.Index(indexInfo.Name).All(indexInfo.Value)).Cast(); + + var result = (await Dynamo.Index(indexInfo.Name).All(indexInfo.Value)).Cast(); + return SetIsNewAndOriginalId(result); } return null; @@ -177,7 +186,8 @@ ScanOperator GetOperator() return new ScanCondition(criterion.PropertyName, @operator, values); } - return (await Dynamo.Table().All(query.Criteria.Select(ToCondition).ToArray())).Cast(); + var result = (await Dynamo.Table().All(query.Criteria.Select(ToCondition).ToArray())).Cast(); + return SetIsNewAndOriginalId(result); } public IDictionary> GetUpdatedValues(IEntity original, IEntity updated) @@ -221,8 +231,22 @@ public async Task Save(IEntity record) await Dynamo.Client.UpdateItemAsync( new UpdateItemRequest(tableName, key, updates) ); + + SetIsNewAndOriginalId(record); } public bool SupportValidationBypassing() => throw new NotImplementedException(); + + IEntity SetIsNewAndOriginalId(IEntity entity) + { + Entity.Services.SetSaved(entity); + Entity.Services.SetOriginalId(entity); + return entity; + } + IEnumerable SetIsNewAndOriginalId(IEnumerable entities) + { + entities.Do(i => SetIsNewAndOriginalId(i)); + return entities; + } } } \ No newline at end of file diff --git a/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj b/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj index f26bc1f13..2428c5bc4 100644 --- a/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj +++ b/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj @@ -5,7 +5,7 @@ Olive.Entities.Data.DynamoDB Olive.Entities.Data.DynamoDB $(AssemblyName) ($(TargetFramework)) - 1.0.12.0 + 1.0.13.0 true en default @@ -40,4 +40,7 @@ + + + \ No newline at end of file From e892f8dedfe12296878af563e337a29f43658f2d Mon Sep 17 00:00:00 2001 From: "amir.jabari" Date: Tue, 8 Mar 2022 08:19:06 +0000 Subject: [PATCH 2/2] Fix the reviews. --- .../DynamoDBDataProvider.cs | 21 ++++++++++--------- .../Olive.Entities.Data.DynamoDB.csproj | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs b/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs index 0fd951c11..ec9a55e27 100644 --- a/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs +++ b/Olive.Entities.Data.DynamoDB/DynamoDBDataProvider.cs @@ -38,7 +38,7 @@ public async Task BulkInsert(IEntity[] entities, int batchSize) writer.AddPutItems(entities.Cast()); await writer.ExecuteAsync(); - SetIsNewAndOriginalId(entities); + OnEntityLoaded(entities); } public async Task BulkUpdate(IEntity[] entities, int batchSize) @@ -48,7 +48,7 @@ public async Task BulkUpdate(IEntity[] entities, int batchSize) writer.AddPutItems(entities.Cast()); await writer.ExecuteAsync(); - SetIsNewAndOriginalId(entities); + OnEntityLoaded(entities); } public Task Count(IDatabaseQuery query) => GetList(query).Count(); @@ -67,7 +67,7 @@ public string GenerateSelectCommand(IDatabaseQuery iquery, string fields) public async Task Get(object objectID) { var result = (IEntity)await Dynamo.Table().Get(objectID); - return SetIsNewAndOriginalId(result); + return OnEntityLoaded(result); } public DirectDatabaseCriterion GetAssociationInclusionCriteria(IDatabaseQuery masterQuery, PropertyInfo association) @@ -102,7 +102,7 @@ async Task> FindByHashKey(IDatabaseQuery query) var item = await Get(hashKeyInfo.Value); if (item is null) return Enumerable.Empty(); - SetIsNewAndOriginalId(item); + OnEntityLoaded(item); return new[] { item }; } @@ -130,7 +130,7 @@ async Task> FindByIndex(IDatabaseQuery query) if (indexInfo.Value is null) return Enumerable.Empty(); var result = (await Dynamo.Index(indexInfo.Name).All(indexInfo.Value)).Cast(); - return SetIsNewAndOriginalId(result); + return OnEntityLoaded(result); } return null; @@ -187,7 +187,7 @@ ScanOperator GetOperator() } var result = (await Dynamo.Table().All(query.Criteria.Select(ToCondition).ToArray())).Cast(); - return SetIsNewAndOriginalId(result); + return OnEntityLoaded(result); } public IDictionary> GetUpdatedValues(IEntity original, IEntity updated) @@ -232,20 +232,21 @@ await Dynamo.Client.UpdateItemAsync( new UpdateItemRequest(tableName, key, updates) ); - SetIsNewAndOriginalId(record); + OnEntityLoaded(record); } public bool SupportValidationBypassing() => throw new NotImplementedException(); - IEntity SetIsNewAndOriginalId(IEntity entity) + IEntity OnEntityLoaded(IEntity entity) { Entity.Services.SetSaved(entity); Entity.Services.SetOriginalId(entity); return entity; } - IEnumerable SetIsNewAndOriginalId(IEnumerable entities) + + IEnumerable OnEntityLoaded(IEnumerable entities) { - entities.Do(i => SetIsNewAndOriginalId(i)); + entities.Do(i => OnEntityLoaded(i)); return entities; } } diff --git a/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj b/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj index 2428c5bc4..033c59165 100644 --- a/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj +++ b/Olive.Entities.Data.DynamoDB/Olive.Entities.Data.DynamoDB.csproj @@ -5,7 +5,7 @@ Olive.Entities.Data.DynamoDB Olive.Entities.Data.DynamoDB $(AssemblyName) ($(TargetFramework)) - 1.0.13.0 + 1.0.12.0 true en default