-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ODS-6512] Modify batched page queries in NHibernate to use Aggregate…
…Id instead of Id for page-level inclusion criteria (#1165)
- Loading branch information
1 parent
3b5815d
commit 23f34a6
Showing
33 changed files
with
1,167 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...pi/Security/Authorization/Repositories/GetEntitiesByAggregateIdsAuthorizationDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EdFi.Ods.Common; | ||
using EdFi.Ods.Common.Repositories; | ||
|
||
namespace EdFi.Ods.Api.Security.Authorization.Repositories; | ||
|
||
/// <summary> | ||
/// Authorizes calls to the "GetByAggregateIds" repository method. | ||
/// </summary> | ||
/// <typeparam name="T">The Type of entity being queried.</typeparam> | ||
public class GetEntitiesByAggregateIdsAuthorizationDecorator<T> : IGetEntitiesByAggregateIds<T> | ||
where T : class, IHasIdentifier, IDateVersionedEntity | ||
{ | ||
private readonly IGetEntitiesByAggregateIds<T> _next; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GetEntitiesByAggregateIdsAuthorizationDecorator{T}"/> class. | ||
/// </summary> | ||
/// <param name="next">The decorated instance for which authorization is being performed.</param> | ||
public GetEntitiesByAggregateIdsAuthorizationDecorator(IGetEntitiesByAggregateIds<T> next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
/// <summary> | ||
/// Authorizes a call to get multiple records by their record identifiers. | ||
/// </summary> | ||
/// <param name="aggregateIds">The values of the record identifiers to be retrieved.</param> | ||
/// <returns>The specified entity if found; otherwise null.</returns> | ||
public async Task<IList<T>> GetByAggregateIdsAsync(IList<int> aggregateIds, CancellationToken cancellationToken) | ||
{ | ||
return await _next.GetByAggregateIdsAsync(aggregateIds, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Application/EdFi.Ods.Common/Infrastructure/Repositories/GetEntitiesByAggregateIds.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EdFi.Common; | ||
using EdFi.Ods.Common.Context; | ||
using EdFi.Ods.Common.Infrastructure.Activities; | ||
using EdFi.Ods.Common.Models; | ||
using EdFi.Ods.Common.Models.Domain; | ||
using EdFi.Ods.Common.Repositories; | ||
using EdFi.Ods.Common.Security.Claims; | ||
using NHibernate; | ||
|
||
namespace EdFi.Ods.Common.Infrastructure.Repositories; | ||
|
||
public class GetEntitiesByAggregateIds<TEntity> : GetEntitiesBase<TEntity>, IGetEntitiesByAggregateIds<TEntity> | ||
where TEntity : DomainObjectBase, IHasIdentifier, IDateVersionedEntity | ||
{ | ||
private readonly IParameterListSetter _parameterListSetter; | ||
|
||
public GetEntitiesByAggregateIds( | ||
ISessionFactory sessionFactory, | ||
IDomainModelProvider domainModelProvider, | ||
IParameterListSetter parameterListSetter, | ||
IContextProvider<DataManagementResourceContext> dataManagementResourceContextProvider) | ||
: base(sessionFactory, domainModelProvider, dataManagementResourceContextProvider) | ||
{ | ||
_parameterListSetter = Preconditions.ThrowIfNull(parameterListSetter, nameof(parameterListSetter)); | ||
} | ||
|
||
public async Task<IList<TEntity>> GetByAggregateIdsAsync(IList<int> aggregateIds, CancellationToken cancellationToken) | ||
{ | ||
using (new SessionScope(SessionFactory)) | ||
{ | ||
IEnumerable<TEntity> results; | ||
|
||
if (aggregateIds.Count == 1) | ||
{ | ||
results = await GetAggregateResultsAsync( | ||
"where a.AggregateId = :id", | ||
q => q.SetParameter("id", aggregateIds[0]), cancellationToken); | ||
} | ||
else | ||
{ | ||
results = await GetAggregateResultsAsync( | ||
"where a.AggregateId IN (:ids)", | ||
q => _parameterListSetter.SetParameterList(q ,"ids", aggregateIds), | ||
cancellationToken, | ||
"order by a.AggregateId"); | ||
} | ||
|
||
// Process multiple results in the first-level cache to a list of complete aggregates | ||
return results.ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Application/EdFi.Ods.Common/Repositories/IGetEntitiesByAggregateIds.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace EdFi.Ods.Common.Repositories; | ||
|
||
/// <summary> | ||
/// Defines a method for retrieving a list of entities by their record identifiers. | ||
/// </summary> | ||
/// <typeparam name="TEntity">The Type of the entities to be retrieved.</typeparam> | ||
public interface IGetEntitiesByAggregateIds<TEntity> | ||
where TEntity : IHasIdentifier, IDateVersionedEntity | ||
{ | ||
/// <summary> | ||
/// Get a list of entities by their record identifiers. | ||
/// </summary> | ||
/// <param name="aggregateIds">The list of aggregate identifiers.</param> | ||
/// <returns>The list of matching entities.</returns> | ||
Task<IList<TEntity>> GetByAggregateIdsAsync(IList<int> aggregateIds, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.