Skip to content

Commit b162519

Browse files
committed
style: replaced principal with left and dependent with right whenever it referred to relationships
1 parent ce08b4f commit b162519

16 files changed

+544
-221
lines changed

src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ private IList GetTrackedManyRelationshipValue(IEnumerable<IIdentifiable> relatio
239239
{ // convert each element in the value list to relationshipAttr.DependentType.
240240
var tracked = AttachOrGetTracked(pointer);
241241
if (tracked != null) _wasAlreadyAttached = true;
242-
return Convert.ChangeType(tracked ?? pointer, relationshipAttr.DependentType);
243-
}).ToList().Cast(relationshipAttr.DependentType);
242+
return Convert.ChangeType(tracked ?? pointer, relationshipAttr.RightType);
243+
}).ToList().Cast(relationshipAttr.RightType);
244244
if (_wasAlreadyAttached) wasAlreadyAttached = true;
245245
return (IList)trackedPointerCollection;
246246
}
@@ -262,7 +262,7 @@ public async Task UpdateRelationshipsAsync(object parent, RelationshipAttribute
262262
// of the property...
263263
var typeToUpdate = (relationship is HasManyThroughAttribute hasManyThrough)
264264
? hasManyThrough.ThroughType
265-
: relationship.DependentType;
265+
: relationship.RightType;
266266

267267
var genericProcessor = _genericProcessorFactory.GetProcessor<IGenericProcessor>(typeof(GenericProcessor<>), typeToUpdate);
268268
await genericProcessor.UpdateRelationshipsAsync(parent, relationship, relationshipIds);
@@ -365,7 +365,7 @@ protected void LoadCurrentRelationships(TResource oldEntity, RelationshipAttribu
365365

366366
/// <summary>
367367
/// The relationshipValue parameter contains the dependent side of the relationship (Tags).
368-
/// We can't directly add them to the principal entity (Article): we need to
368+
/// We can't directly add them to the left entity (Article): we need to
369369
/// use the join table (ArticleTags). This methods assigns the relationship value to entity
370370
/// by taking care of that
371371
/// </summary>

src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ internal EntityHashSet(IEnumerable entities,
4444

4545

4646
/// <inheritdoc />
47-
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type principalType)
47+
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type leftType)
4848
{
49-
return _relationships.GetByRelationship(principalType);
49+
return _relationships.GetByRelationship(leftType);
5050
}
5151

5252
/// <inheritdoc />
53-
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship<TRelatedResource>() where TRelatedResource : class, IIdentifiable
53+
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship<TRightResource>() where TRightResource : class, IIdentifiable
5454
{
55-
return GetByRelationship(typeof(TRelatedResource));
55+
return GetByRelationship(typeof(TRightResource));
5656
}
5757

5858
/// <inheritdoc />

src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs

+29-31
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
using JsonApiDotNetCore.Internal.Generics;
88
using JsonApiDotNetCore.Models;
99
using JsonApiDotNetCore.Extensions;
10-
using PrincipalType = System.Type;
11-
using DependentType = System.Type;
12-
using Microsoft.EntityFrameworkCore;
10+
using LeftType = System.Type;
11+
using RightType = System.Type;
1312
using JsonApiDotNetCore.Internal;
14-
using JsonApiDotNetCore.Internal.Contracts;
1513
using JsonApiDotNetCore.Configuration;
1614

1715
namespace JsonApiDotNetCore.Hooks
@@ -22,31 +20,31 @@ internal class HookExecutorHelper : IHookExecutorHelper
2220
private readonly IdentifiableComparer _comparer = new IdentifiableComparer();
2321
private readonly IJsonApiOptions _options;
2422
protected readonly IGenericProcessorFactory _genericProcessorFactory;
25-
protected readonly Dictionary<DependentType, IResourceHookContainer> _hookContainers;
26-
protected readonly Dictionary<DependentType, IHooksDiscovery> _hookDiscoveries;
23+
protected readonly Dictionary<RightType, IResourceHookContainer> _hookContainers;
24+
protected readonly Dictionary<RightType, IHooksDiscovery> _hookDiscoveries;
2725
protected readonly List<ResourceHook> _targetedHooksForRelatedEntities;
2826

2927
public HookExecutorHelper(IGenericProcessorFactory genericProcessorFactory,
3028
IJsonApiOptions options)
3129
{
3230
_options = options;
3331
_genericProcessorFactory = genericProcessorFactory;
34-
_hookContainers = new Dictionary<DependentType, IResourceHookContainer>();
35-
_hookDiscoveries = new Dictionary<DependentType, IHooksDiscovery>();
32+
_hookContainers = new Dictionary<RightType, IResourceHookContainer>();
33+
_hookDiscoveries = new Dictionary<RightType, IHooksDiscovery>();
3634
_targetedHooksForRelatedEntities = new List<ResourceHook>();
3735
}
3836

3937
/// <inheritdoc/>
40-
public IResourceHookContainer GetResourceHookContainer(DependentType dependentType, ResourceHook hook = ResourceHook.None)
38+
public IResourceHookContainer GetResourceHookContainer(RightType rightType, ResourceHook hook = ResourceHook.None)
4139
{
4240
/// checking the cache if we have a reference for the requested container,
4341
/// regardless of the hook we will use it for. If the value is null,
4442
/// it means there was no implementation IResourceHookContainer at all,
4543
/// so we need not even bother.
46-
if (!_hookContainers.TryGetValue(dependentType, out IResourceHookContainer container))
44+
if (!_hookContainers.TryGetValue(rightType, out IResourceHookContainer container))
4745
{
48-
container = (_genericProcessorFactory.GetProcessor<IResourceHookContainer>(typeof(ResourceDefinition<>), dependentType));
49-
_hookContainers[dependentType] = container;
46+
container = (_genericProcessorFactory.GetProcessor<IResourceHookContainer>(typeof(ResourceDefinition<>), rightType));
47+
_hookContainers[rightType] = container;
5048
}
5149
if (container == null) return container;
5250

@@ -65,7 +63,7 @@ public IResourceHookContainer GetResourceHookContainer(DependentType dependentTy
6563

6664
foreach (ResourceHook targetHook in targetHooks)
6765
{
68-
if (ShouldExecuteHook(dependentType, targetHook)) return container;
66+
if (ShouldExecuteHook(rightType, targetHook)) return container;
6967
}
7068
return null;
7169
}
@@ -76,7 +74,7 @@ public IResourceHookContainer<TResource> GetResourceHookContainer<TResource>(Res
7674
return (IResourceHookContainer<TResource>)GetResourceHookContainer(typeof(TResource), hook);
7775
}
7876

79-
public IEnumerable LoadDbValues(PrincipalType entityTypeForRepository, IEnumerable entities, ResourceHook hook, params RelationshipAttribute[] inclusionChain)
77+
public IEnumerable LoadDbValues(LeftType entityTypeForRepository, IEnumerable entities, ResourceHook hook, params RelationshipAttribute[] inclusionChain)
8078
{
8179
var idType = TypeHelper.GetIdentifierType(entityTypeForRepository);
8280
var parameterizedGetWhere = GetType()
@@ -107,7 +105,7 @@ public bool ShouldLoadDbValues(Type entityType, ResourceHook hook)
107105
return _options.LoaDatabaseValues;
108106
}
109107

110-
bool ShouldExecuteHook(DependentType entityType, ResourceHook hook)
108+
bool ShouldExecuteHook(RightType entityType, ResourceHook hook)
111109
{
112110
var discovery = GetHookDiscovery(entityType);
113111
return discovery.ImplementedHooks.Contains(hook);
@@ -145,46 +143,46 @@ IResourceReadRepository<TResource, TId> GetRepository<TResource, TId>() where TR
145143

146144

147145
public Dictionary<RelationshipAttribute, IEnumerable> LoadImplicitlyAffected(
148-
Dictionary<RelationshipAttribute, IEnumerable> principalEntitiesByRelation,
149-
IEnumerable existingDependentEntities = null)
146+
Dictionary<RelationshipAttribute, IEnumerable> leftEntitiesByRelation,
147+
IEnumerable existingRightEntities = null)
150148
{
151149
var implicitlyAffected = new Dictionary<RelationshipAttribute, IEnumerable>();
152-
foreach (var kvp in principalEntitiesByRelation)
150+
foreach (var kvp in leftEntitiesByRelation)
153151
{
154-
if (IsHasManyThrough(kvp, out var principals, out var relationship)) continue;
152+
if (IsHasManyThrough(kvp, out var lefts, out var relationship)) continue;
155153

156154
// note that we dont't have to check if BeforeImplicitUpdate hook is implemented. If not, it wont ever get here.
157-
var includedPrincipals = LoadDbValues(relationship.PrincipalType, principals, ResourceHook.BeforeImplicitUpdateRelationship, relationship);
155+
var includedLefts = LoadDbValues(relationship.LeftType, lefts, ResourceHook.BeforeImplicitUpdateRelationship, relationship);
158156

159-
foreach (IIdentifiable ip in includedPrincipals)
157+
foreach (IIdentifiable ip in includedLefts)
160158
{
161-
IList dbDependentEntityList = null;
159+
IList dbRightEntityList = null;
162160
var relationshipValue = relationship.GetValue(ip);
163161
if (!(relationshipValue is IEnumerable))
164162
{
165-
dbDependentEntityList = TypeHelper.CreateListFor(relationship.DependentType);
166-
if (relationshipValue != null) dbDependentEntityList.Add(relationshipValue);
163+
dbRightEntityList = TypeHelper.CreateListFor(relationship.RightType);
164+
if (relationshipValue != null) dbRightEntityList.Add(relationshipValue);
167165
}
168166
else
169167
{
170-
dbDependentEntityList = (IList)relationshipValue;
168+
dbRightEntityList = (IList)relationshipValue;
171169
}
172-
var dbDependentEntityListCasted = dbDependentEntityList.Cast<IIdentifiable>().ToList();
173-
if (existingDependentEntities != null) dbDependentEntityListCasted = dbDependentEntityListCasted.Except(existingDependentEntities.Cast<IIdentifiable>(), _comparer).ToList();
170+
var dbRightEntityListCasted = dbRightEntityList.Cast<IIdentifiable>().ToList();
171+
if (existingRightEntities != null) dbRightEntityListCasted = dbRightEntityListCasted.Except(existingRightEntities.Cast<IIdentifiable>(), _comparer).ToList();
174172

175-
if (dbDependentEntityListCasted.Any())
173+
if (dbRightEntityListCasted.Any())
176174
{
177175
if (!implicitlyAffected.TryGetValue(relationship, out IEnumerable affected))
178176
{
179-
affected = TypeHelper.CreateListFor(relationship.DependentType);
177+
affected = TypeHelper.CreateListFor(relationship.RightType);
180178
implicitlyAffected[relationship] = affected;
181179
}
182-
((IList)affected).AddRange(dbDependentEntityListCasted);
180+
((IList)affected).AddRange(dbRightEntityListCasted);
183181
}
184182
}
185183
}
186184

187-
return implicitlyAffected.ToDictionary(kvp => kvp.Key, kvp => TypeHelper.CreateHashSetFor(kvp.Key.DependentType, kvp.Value));
185+
return implicitlyAffected.ToDictionary(kvp => kvp.Key, kvp => TypeHelper.CreateHashSetFor(kvp.Key.RightType, kvp.Value));
188186

189187
}
190188

src/JsonApiDotNetCore/Hooks/Execution/IHookExecutorHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal interface IHookExecutorHelper
3737
/// Load the implicitly affected entities from the database for a given set of target target entities and involved relationships
3838
/// </summary>
3939
/// <returns>The implicitly affected entities by relationship</returns>
40-
Dictionary<RelationshipAttribute, IEnumerable> LoadImplicitlyAffected(Dictionary<RelationshipAttribute, IEnumerable> principalEntities, IEnumerable existingDependentEntities = null);
40+
Dictionary<RelationshipAttribute, IEnumerable> LoadImplicitlyAffected(Dictionary<RelationshipAttribute, IEnumerable> leftEntities, IEnumerable existingRightEntities = null);
4141

4242
/// <summary>
4343
/// For a set of entities, loads current values from the database

src/JsonApiDotNetCore/Hooks/Execution/RelationshipsDictionary.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,51 @@ public interface IRelationshipsDictionary { }
1616
/// <summary>
1717
/// An interface that is implemented to expose a relationship dictionary on another class.
1818
/// </summary>
19-
public interface IByAffectedRelationships<TDependentResource> :
20-
IRelationshipGetters<TDependentResource> where TDependentResource : class, IIdentifiable
19+
public interface IByAffectedRelationships<TRightResource> :
20+
IRelationshipGetters<TRightResource> where TRightResource : class, IIdentifiable
2121
{
2222
/// <summary>
2323
/// Gets a dictionary of affected resources grouped by affected relationships.
2424
/// </summary>
25-
Dictionary<RelationshipAttribute, HashSet<TDependentResource>> AffectedRelationships { get; }
25+
Dictionary<RelationshipAttribute, HashSet<TRightResource>> AffectedRelationships { get; }
2626
}
2727

2828
/// <summary>
2929
/// A helper class that provides insights in which relationships have been updated for which entities.
3030
/// </summary>
31-
public interface IRelationshipsDictionary<TDependentResource> :
32-
IRelationshipGetters<TDependentResource>,
33-
IReadOnlyDictionary<RelationshipAttribute, HashSet<TDependentResource>>,
34-
IRelationshipsDictionary where TDependentResource : class, IIdentifiable
31+
public interface IRelationshipsDictionary<TRightResource> :
32+
IRelationshipGetters<TRightResource>,
33+
IReadOnlyDictionary<RelationshipAttribute, HashSet<TRightResource>>,
34+
IRelationshipsDictionary where TRightResource : class, IIdentifiable
3535
{ }
3636

3737
/// <summary>
3838
/// A helper class that provides insights in which relationships have been updated for which entities.
3939
/// </summary>
40-
public interface IRelationshipGetters<TResource> where TResource : class, IIdentifiable
40+
public interface IRelationshipGetters<TLeftResource> where TLeftResource : class, IIdentifiable
4141
{
4242
/// <summary>
43-
/// Gets a dictionary of all entities that have an affected relationship to type <typeparamref name="TPrincipalResource"/>
43+
/// Gets a dictionary of all entities that have an affected relationship to type <typeparamref name="TLeftResource"/>
4444
/// </summary>
45-
Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship<TRelatedResource>() where TRelatedResource : class, IIdentifiable;
45+
Dictionary<RelationshipAttribute, HashSet<TLeftResource>> GetByRelationship<TRightResource>() where TRightResource : class, IIdentifiable;
4646
/// <summary>
47-
/// Gets a dictionary of all entities that have an affected relationship to type <paramref name="principalType"/>
47+
/// Gets a dictionary of all entities that have an affected relationship to type <paramref name="relatedResourceType"/>
4848
/// </summary>
49-
Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type relatedResourceType);
49+
Dictionary<RelationshipAttribute, HashSet<TLeftResource>> GetByRelationship(Type relatedResourceType);
5050
/// <summary>
51-
/// Gets a collection of all the entities for the property within <paramref name="NavigationAction"/>
51+
/// Gets a collection of all the entities for the property within <paramref name="navigationAction"/>
5252
/// has been affected by the request
5353
/// </summary>
54-
/// <param name="NavigationAction"></param>
55-
HashSet<TResource> GetAffected(Expression<Func<TResource, object>> NavigationAction);
54+
/// <param name="navigationAction"></param>
55+
HashSet<TLeftResource> GetAffected(Expression<Func<TLeftResource, object>> navigationAction);
5656
}
5757

5858

5959
/// <summary>
60-
/// Implementation of IAffectedRelationships{TDependentResource}
60+
/// Implementation of IAffectedRelationships{TRightResource}
6161
///
62-
/// It is practically a ReadOnlyDictionary{RelationshipAttribute, HashSet{TDependentResource}} dictionary
63-
/// with the two helper methods defined on IAffectedRelationships{TDependentResource}.
62+
/// It is practically a ReadOnlyDictionary{RelationshipAttribute, HashSet{TRightResource}} dictionary
63+
/// with the two helper methods defined on IAffectedRelationships{TRightResource}.
6464
/// </summary>
6565
public class RelationshipsDictionary<TResource> :
6666
Dictionary<RelationshipAttribute, HashSet<TResource>>,

0 commit comments

Comments
 (0)