Throw `ConcurrencyException` when `AbpDbConcurrencyException` occurs.

https://github.com/abpframework/abp/issues/15530#issuecomment-1505182866
pull/16351/head
maliming 2 years ago
parent 0dfbbc0950
commit f46328e5dd
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4

@ -8,6 +8,9 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenIddict.Abstractions;
using Volo.Abp.Data;
using Volo.Abp.Guids;
using Volo.Abp.OpenIddict.Tokens;
using Volo.Abp.Uow;
@ -52,13 +55,21 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
{
Check.NotNull(application, nameof(application));
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.RepeatableRead))
try
{
await TokenRepository.DeleteManyByApplicationIdAsync(application.Id, cancellationToken: cancellationToken);
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.RepeatableRead))
{
await TokenRepository.DeleteManyByApplicationIdAsync(application.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(application.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(application.Id, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
await uow.CompleteAsync(cancellationToken);
}
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
}
@ -527,7 +538,15 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
var entity = await Repository.GetAsync(application.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(application.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
try
{
await Repository.UpdateAsync(application.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
application = (await Repository.FindAsync(entity.Id, cancellationToken: cancellationToken)).ToModel();
}

@ -7,7 +7,9 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenIddict.Abstractions;
using Volo.Abp.Data;
using Volo.Abp.Guids;
using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.OpenIddict.Tokens;
@ -56,13 +58,21 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
{
Check.NotNull(authorization, nameof(authorization));
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.RepeatableRead))
try
{
await TokenRepository.DeleteManyByAuthorizationIdAsync(authorization.Id, cancellationToken: cancellationToken);
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.RepeatableRead))
{
await TokenRepository.DeleteManyByAuthorizationIdAsync(authorization.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(authorization.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(authorization.Id, cancellationToken: cancellationToken);
await uow.CompleteAsync(cancellationToken);
await uow.CompleteAsync(cancellationToken);
}
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
}
@ -387,7 +397,15 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
var entity = await Repository.GetAsync(authorization.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(authorization.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
try
{
await Repository.UpdateAsync(authorization.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
authorization = (await Repository.FindAsync(entity.Id, cancellationToken: cancellationToken)).ToModel();
}

@ -7,7 +7,9 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenIddict.Abstractions;
using Volo.Abp.Data;
using Volo.Abp.Guids;
using Volo.Abp.Uow;
@ -48,7 +50,15 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
{
Check.NotNull(scope, nameof(scope));
await Repository.DeleteAsync(scope.Id, autoSave: true, cancellationToken: cancellationToken);
try
{
await Repository.DeleteAsync(scope.Id, autoSave: true, cancellationToken: cancellationToken);
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
}
public virtual async ValueTask<OpenIddictScopeModel> FindByIdAsync(string identifier, CancellationToken cancellationToken)
@ -385,7 +395,15 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
var entity = await Repository.GetAsync(scope.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(scope.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
try
{
await Repository.UpdateAsync(scope.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
scope = (await Repository.FindAsync(entity.Id, cancellationToken: cancellationToken)).ToModel();
}

@ -7,7 +7,9 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenIddict.Abstractions;
using Volo.Abp.Data;
using Volo.Abp.Guids;
using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.OpenIddict.Authorizations;
@ -56,7 +58,15 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
{
Check.NotNull(token, nameof(token));
await Repository.DeleteAsync(token.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
try
{
await Repository.DeleteAsync(token.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
}
public virtual async IAsyncEnumerable<OpenIddictTokenModel> FindAsync(string subject, string client, [EnumeratorCancellation] CancellationToken cancellationToken)
@ -432,7 +442,15 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
var entity = await Repository.GetAsync(token.Id, cancellationToken: cancellationToken);
await Repository.UpdateAsync(token.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
try
{
await Repository.UpdateAsync(token.ToEntity(entity), autoSave: true, cancellationToken: cancellationToken);
}
catch (AbpDbConcurrencyException e)
{
Logger.LogException(e);
throw new OpenIddictExceptions.ConcurrencyException(e.Message, e.InnerException);
}
token = (await Repository.FindAsync(entity.Id, cancellationToken: cancellationToken)).ToModel();
}

Loading…
Cancel
Save