Skip to content

Commit e928c78

Browse files
committed
Simplify QueueEntry hierarchy
1 parent 5b563f5 commit e928c78

File tree

1 file changed

+39
-43
lines changed

1 file changed

+39
-43
lines changed

src/NHibernate/Loader/JoinWalker.cs

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace NHibernate.Loader
1515
public class JoinWalker
1616
{
1717
private readonly ISessionFactoryImplementor factory;
18-
private Queue<QueueEntry> joinQueue = new Queue<QueueEntry>();
1918
private int depth;
2019
protected readonly IList<OuterJoinableAssociation> associations = new List<OuterJoinableAssociation>();
2120
private readonly HashSet<AssociationKey> visitedAssociationKeys = new HashSet<AssociationKey>();
@@ -33,6 +32,7 @@ public class JoinWalker
3332
private string[] aliases;
3433
private LockMode[] lockModeArray;
3534
private SqlString sql;
35+
private readonly Queue<IJoinQueueEntry> _joinQueue = new();
3636

3737
public string[] CollectionSuffixes
3838
{
@@ -192,26 +192,11 @@ private void AddAssociationToJoinTree(IAssociationType type, string[] aliasedLhs
192192

193193
if (qc != null)
194194
{
195-
joinQueue.Enqueue(
196-
new CollectionQueueEntry()
197-
{
198-
Persister = qc,
199-
Alias = subalias,
200-
Path = path,
201-
PathAlias = pathAlias,
202-
}
203-
);
195+
_joinQueue.Enqueue(new CollectionJoinQueueEntry(qc, subalias, path, pathAlias));
204196
}
205197
else if (joinable is IOuterJoinLoadable jl)
206198
{
207-
joinQueue.Enqueue(
208-
new EntityQueueEntry()
209-
{
210-
Persister = jl,
211-
Alias = subalias,
212-
Path = path,
213-
}
214-
);
199+
_joinQueue.Enqueue(new EntityJoinQueueEntry(jl, subalias, path));
215200
}
216201
}
217202

@@ -327,9 +312,9 @@ protected void WalkCollectionTree(IQueryableCollection persister, string alias)
327312

328313
protected void ProcessJoins()
329314
{
330-
while (joinQueue.Count > 0)
315+
while (_joinQueue.Count > 0)
331316
{
332-
QueueEntry entry = joinQueue.Dequeue();
317+
var entry = _joinQueue.Dequeue();
333318
entry.Walk(this);
334319
}
335320
}
@@ -466,7 +451,7 @@ protected virtual void WalkEntityTree(IOuterJoinLoadable persister, string alias
466451
{
467452
int n = persister.CountSubclassProperties();
468453

469-
joinQueue.Enqueue(NextLevelQueueEntry.Instance);
454+
_joinQueue.Enqueue(NextLevelJoinQueueEntry.Instance);
470455
for (int i = 0; i < n; i++)
471456
{
472457
IType type = persister.GetSubclassPropertyType(i);
@@ -1252,49 +1237,60 @@ protected static string GetSelectFragment(OuterJoinableAssociation join, string
12521237
return join.GetSelectFragment(entitySuffix, collectionSuffix, next);
12531238
}
12541239

1255-
protected abstract class QueueEntry
1240+
protected interface IJoinQueueEntry
12561241
{
1257-
public abstract void Walk(JoinWalker walker);
1242+
void Walk(JoinWalker walker);
12581243
}
12591244

1260-
protected abstract class QueueEntry<T> : QueueEntry where T : IJoinable
1245+
protected class EntityJoinQueueEntry : IJoinQueueEntry
12611246
{
1262-
public string Alias { get; set; }
1263-
public T Persister { get; set; }
1264-
}
1247+
private readonly IOuterJoinLoadable _persister;
1248+
private readonly string _alias;
1249+
private readonly string _path;
12651250

1266-
protected abstract class EntityQueueEntry<T> : QueueEntry<T> where T : IJoinable
1267-
{
1268-
public string Path { get; set; }
1269-
}
1251+
public EntityJoinQueueEntry(IOuterJoinLoadable persister, string alias, string path)
1252+
{
1253+
_persister = persister;
1254+
_alias = alias;
1255+
_path = path;
1256+
}
12701257

1271-
protected class EntityQueueEntry : EntityQueueEntry<IOuterJoinLoadable>
1272-
{
1273-
public override void Walk(JoinWalker walker)
1258+
public void Walk(JoinWalker walker)
12741259
{
1275-
walker.WalkEntityTree(Persister, Alias, Path);
1260+
walker.WalkEntityTree(_persister, _alias, _path);
12761261
}
12771262
}
12781263

1279-
protected class CollectionQueueEntry : EntityQueueEntry<IQueryableCollection>
1264+
protected class CollectionJoinQueueEntry : IJoinQueueEntry
12801265
{
1281-
public string PathAlias { get; set; }
1266+
private readonly IQueryableCollection _persister;
1267+
private readonly string _alias;
1268+
private readonly string _path;
1269+
private readonly string _pathAlias;
1270+
1271+
public CollectionJoinQueueEntry(IQueryableCollection persister, string alias, string path, string pathAlias)
1272+
{
1273+
_persister = persister;
1274+
_alias = alias;
1275+
_path = path;
1276+
_pathAlias = pathAlias;
1277+
}
12821278

1283-
public override void Walk(JoinWalker walker)
1279+
public void Walk(JoinWalker walker)
12841280
{
1285-
walker.WalkCollectionTree(Persister, Alias, Path, PathAlias);
1281+
walker.WalkCollectionTree(_persister, _alias, _path, _pathAlias);
12861282
}
12871283
}
12881284

1289-
protected class NextLevelQueueEntry : QueueEntry
1285+
protected class NextLevelJoinQueueEntry : IJoinQueueEntry
12901286
{
1291-
public static readonly NextLevelQueueEntry Instance = new NextLevelQueueEntry();
1287+
public static readonly NextLevelJoinQueueEntry Instance = new();
12921288

1293-
private NextLevelQueueEntry()
1289+
private NextLevelJoinQueueEntry()
12941290
{
12951291
}
12961292

1297-
public override void Walk(JoinWalker walker)
1293+
public void Walk(JoinWalker walker)
12981294
{
12991295
walker.depth++;
13001296
}

0 commit comments

Comments
 (0)