Resolved #4296: DatabaseBlobProvider auto save changes.

pull/4308/head
Halil İbrahim Kalkan 5 years ago
parent dff6d79036
commit 2414fb1ddb

@ -26,8 +26,11 @@ namespace Volo.Abp.BlobStoring.Database
{ {
var container = await GetOrCreateContainerAsync(args.ContainerName, args.CancellationToken); var container = await GetOrCreateContainerAsync(args.ContainerName, args.CancellationToken);
var blob = await DatabaseBlobRepository.FindAsync(container.Id, args.BlobName, var blob = await DatabaseBlobRepository.FindAsync(
args.CancellationToken); container.Id,
args.BlobName,
args.CancellationToken
);
var content = await args.BlobStream.GetAllBytesAsync(args.CancellationToken); var content = await args.BlobStream.GetAllBytesAsync(args.CancellationToken);
@ -40,58 +43,72 @@ namespace Volo.Abp.BlobStoring.Database
} }
blob.SetContent(content); blob.SetContent(content);
await DatabaseBlobRepository.UpdateAsync(blob);
await DatabaseBlobRepository.UpdateAsync(blob, autoSave: true);
} }
else else
{ {
blob = new DatabaseBlob(GuidGenerator.Create(), container.Id, args.BlobName, content); blob = new DatabaseBlob(GuidGenerator.Create(), container.Id, args.BlobName, content);
await DatabaseBlobRepository.InsertAsync(blob); await DatabaseBlobRepository.InsertAsync(blob, autoSave: true);
} }
} }
public override async Task<bool> DeleteAsync(BlobProviderDeleteArgs args) public override async Task<bool> DeleteAsync(BlobProviderDeleteArgs args)
{ {
var container = var container = await DatabaseBlobContainerRepository.FindAsync(
await DatabaseBlobContainerRepository.FindAsync(args.ContainerName, args.ContainerName,
args.CancellationToken); args.CancellationToken
);
if (container == null) if (container == null)
{ {
return false; return false;
} }
return await DatabaseBlobRepository.DeleteAsync(container.Id, args.BlobName, return await DatabaseBlobRepository.DeleteAsync(
args.CancellationToken); container.Id,
args.BlobName,
autoSave: true,
cancellationToken: args.CancellationToken
);
} }
public override async Task<bool> ExistsAsync(BlobProviderExistsArgs args) public override async Task<bool> ExistsAsync(BlobProviderExistsArgs args)
{ {
var container = var container = await DatabaseBlobContainerRepository.FindAsync(
await DatabaseBlobContainerRepository.FindAsync(args.ContainerName, args.ContainerName,
args.CancellationToken); args.CancellationToken
);
if (container == null) if (container == null)
{ {
return false; return false;
} }
return await DatabaseBlobRepository.ExistsAsync(container.Id, args.BlobName, return await DatabaseBlobRepository.ExistsAsync(
args.CancellationToken); container.Id,
args.BlobName,
args.CancellationToken
);
} }
public override async Task<Stream> GetOrNullAsync(BlobProviderGetArgs args) public override async Task<Stream> GetOrNullAsync(BlobProviderGetArgs args)
{ {
var container = var container = await DatabaseBlobContainerRepository.FindAsync(
await DatabaseBlobContainerRepository.FindAsync(args.ContainerName, args.ContainerName,
args.CancellationToken); args.CancellationToken
);
if (container == null) if (container == null)
{ {
return null; return null;
} }
var blob = await DatabaseBlobRepository.FindAsync(container.Id, args.BlobName, var blob = await DatabaseBlobRepository.FindAsync(
args.CancellationToken); container.Id,
args.BlobName,
args.CancellationToken
);
if (blob == null) if (blob == null)
{ {

@ -12,6 +12,6 @@ namespace Volo.Abp.BlobStoring.Database
Task<bool> ExistsAsync(Guid containerId, [NotNull] string name, CancellationToken cancellationToken = default); Task<bool> ExistsAsync(Guid containerId, [NotNull] string name, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(Guid containerId, [NotNull] string name, CancellationToken cancellationToken = default); Task<bool> DeleteAsync(Guid containerId, [NotNull] string name, bool autoSave = false, CancellationToken cancellationToken = default);
} }
} }

@ -7,7 +7,8 @@ using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore
{ {
public class EfCoreDatabaseBlobRepository : EfCoreRepository<IBlobStoringDbContext, DatabaseBlob, Guid>, IDatabaseBlobRepository public class EfCoreDatabaseBlobRepository : EfCoreRepository<IBlobStoringDbContext, DatabaseBlob, Guid>,
IDatabaseBlobRepository
{ {
public EfCoreDatabaseBlobRepository(IDbContextProvider<IBlobStoringDbContext> dbContextProvider) public EfCoreDatabaseBlobRepository(IDbContextProvider<IBlobStoringDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
@ -38,15 +39,18 @@ namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore
public virtual async Task<bool> DeleteAsync( public virtual async Task<bool> DeleteAsync(
Guid containerId, Guid containerId,
string name, string name,
bool autoSave = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
//TODO: Should extract this logic to out of the repository and remove this method completely
var blob = await FindAsync(containerId, name, cancellationToken); var blob = await FindAsync(containerId, name, cancellationToken);
if (blob == null) if (blob == null)
{ {
return false; return false;
} }
await base.DeleteAsync(blob.Id, cancellationToken: GetCancellationToken(cancellationToken)); await base.DeleteAsync(blob, autoSave, cancellationToken: GetCancellationToken(cancellationToken));
return true; return true;
} }
} }

@ -29,7 +29,11 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB
GetCancellationToken(cancellationToken)); GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> DeleteAsync(Guid containerId, string name, CancellationToken cancellationToken = default) public virtual async Task<bool> DeleteAsync(
Guid containerId,
string name,
bool autoSave = false,
CancellationToken cancellationToken = default)
{ {
var blob = await FindAsync(containerId, name, cancellationToken); var blob = await FindAsync(containerId, name, cancellationToken);
@ -38,7 +42,7 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB
return false; return false;
} }
await base.DeleteAsync(blob, cancellationToken: GetCancellationToken(cancellationToken)); await base.DeleteAsync(blob, autoSave, cancellationToken: GetCancellationToken(cancellationToken));
return true; return true;
} }
} }

Loading…
Cancel
Save