Skip to content

Commit 15a4372

Browse files
committed
Code cleanup
1 parent 778d71d commit 15a4372

File tree

4 files changed

+47
-52
lines changed

4 files changed

+47
-52
lines changed

src/NHibernate/Action/BulkOperationCleanupAction.cs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ public partial class BulkOperationCleanupAction :
1919
IAfterTransactionCompletionProcess,
2020
ICacheableExecutable
2121
{
22-
private readonly ISessionImplementor session;
23-
private readonly HashSet<string> affectedEntityNames = new HashSet<string>();
24-
private readonly HashSet<string> affectedCollectionRoles = new HashSet<string>();
25-
private readonly List<string> spaces;
22+
private readonly ISessionFactoryImplementor _factory;
23+
private readonly HashSet<string> _affectedEntityNames = new HashSet<string>();
24+
private readonly HashSet<string> _affectedCollectionRoles = new HashSet<string>();
25+
private readonly string[] _spaces;
2626
private readonly bool _hasCache;
2727

2828
public BulkOperationCleanupAction(ISessionImplementor session, IQueryable[] affectedQueryables)
2929
{
30-
this.session = session;
31-
List<string> tmpSpaces = new List<string>();
32-
for (int i = 0; i < affectedQueryables.Length; i++)
30+
_factory = session.Factory;
31+
var tmpSpaces = new HashSet<string>();
32+
foreach (var queryables in affectedQueryables)
3333
{
34-
if (affectedQueryables[i].HasCache)
34+
if (queryables.HasCache)
3535
{
3636
_hasCache = true;
37-
affectedEntityNames.Add(affectedQueryables[i].EntityName);
37+
_affectedEntityNames.Add(queryables.EntityName);
3838
}
39-
ISet<string> roles = session.Factory.GetCollectionRolesByEntityParticipant(affectedQueryables[i].EntityName);
39+
40+
var roles = _factory.GetCollectionRolesByEntityParticipant(queryables.EntityName);
4041
if (roles != null)
4142
{
42-
affectedCollectionRoles.UnionWith(roles);
43-
}
44-
for (int y = 0; y < affectedQueryables[i].QuerySpaces.Length; y++)
45-
{
46-
tmpSpaces.Add(affectedQueryables[i].QuerySpaces[y]);
43+
_affectedCollectionRoles.UnionWith(roles);
4744
}
45+
46+
tmpSpaces.UnionWith(queryables.QuerySpaces);
4847
}
49-
spaces = new List<string>(tmpSpaces);
48+
49+
_spaces = tmpSpaces.ToArray();
5050
}
5151

5252
/// <summary>
@@ -55,36 +55,34 @@ public BulkOperationCleanupAction(ISessionImplementor session, IQueryable[] affe
5555
public BulkOperationCleanupAction(ISessionImplementor session, ISet<string> querySpaces)
5656
{
5757
//from H3.2 TODO: cache the autodetected information and pass it in instead.
58-
this.session = session;
58+
_factory = session.Factory;
5959

60-
ISet<string> tmpSpaces = new HashSet<string>(querySpaces);
61-
ISessionFactoryImplementor factory = session.Factory;
62-
IDictionary<string, IClassMetadata> acmd = factory.GetAllClassMetadata();
60+
var tmpSpaces = new HashSet<string>(querySpaces);
61+
var acmd = _factory.GetAllClassMetadata();
6362
foreach (KeyValuePair<string, IClassMetadata> entry in acmd)
6463
{
65-
string entityName = entry.Key;
66-
IEntityPersister persister = factory.GetEntityPersister(entityName);
67-
string[] entitySpaces = persister.QuerySpaces;
64+
var entityName = entry.Key;
65+
var persister = _factory.GetEntityPersister(entityName);
66+
var entitySpaces = persister.QuerySpaces;
6867

6968
if (AffectedEntity(querySpaces, entitySpaces))
7069
{
7170
if (persister.HasCache)
7271
{
7372
_hasCache = true;
74-
affectedEntityNames.Add(persister.EntityName);
73+
_affectedEntityNames.Add(persister.EntityName);
7574
}
76-
ISet<string> roles = session.Factory.GetCollectionRolesByEntityParticipant(persister.EntityName);
75+
76+
var roles = session.Factory.GetCollectionRolesByEntityParticipant(persister.EntityName);
7777
if (roles != null)
7878
{
79-
affectedCollectionRoles.UnionWith(roles);
80-
}
81-
for (int y = 0; y < entitySpaces.Length; y++)
82-
{
83-
tmpSpaces.Add(entitySpaces[y]);
79+
_affectedCollectionRoles.UnionWith(roles);
8480
}
81+
82+
tmpSpaces.UnionWith(entitySpaces);
8583
}
8684
}
87-
spaces = new List<string>(tmpSpaces);
85+
_spaces = tmpSpaces.ToArray();
8886
}
8987

9088
private bool AffectedEntity(ISet<string> querySpaces, string[] entitySpaces)
@@ -101,10 +99,7 @@ private bool AffectedEntity(ISet<string> querySpaces, string[] entitySpaces)
10199

102100
#region IExecutable Members
103101

104-
public string[] PropertySpaces
105-
{
106-
get { return spaces.ToArray(); }
107-
}
102+
public string[] PropertySpaces => _spaces;
108103

109104
public void BeforeExecutions()
110105
{
@@ -140,17 +135,17 @@ public void ExecuteAfterTransactionCompletion(bool success)
140135

141136
private void EvictCollectionRegions()
142137
{
143-
if (affectedCollectionRoles != null && affectedCollectionRoles.Any())
138+
if (_affectedCollectionRoles != null && _affectedCollectionRoles.Any())
144139
{
145-
session.Factory.EvictCollection(affectedCollectionRoles);
140+
_factory.EvictCollection(_affectedCollectionRoles);
146141
}
147142
}
148143

149144
private void EvictEntityRegions()
150145
{
151-
if (affectedEntityNames != null && affectedEntityNames.Any())
146+
if (_affectedEntityNames != null && _affectedEntityNames.Any())
152147
{
153-
session.Factory.EvictEntity(affectedEntityNames);
148+
_factory.EvictEntity(_affectedEntityNames);
154149
}
155150
}
156151

src/NHibernate/Async/Action/BulkOperationCleanupAction.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ private Task EvictCollectionRegionsAsync(CancellationToken cancellationToken)
7777
}
7878
try
7979
{
80-
if (affectedCollectionRoles != null && affectedCollectionRoles.Any())
80+
if (_affectedCollectionRoles != null && _affectedCollectionRoles.Any())
8181
{
82-
return session.Factory.EvictCollectionAsync(affectedCollectionRoles, cancellationToken);
82+
return _factory.EvictCollectionAsync(_affectedCollectionRoles, cancellationToken);
8383
}
8484
return Task.CompletedTask;
8585
}
@@ -97,9 +97,9 @@ private Task EvictEntityRegionsAsync(CancellationToken cancellationToken)
9797
}
9898
try
9999
{
100-
if (affectedEntityNames != null && affectedEntityNames.Any())
100+
if (_affectedEntityNames != null && _affectedEntityNames.Any())
101101
{
102-
return session.Factory.EvictEntityAsync(affectedEntityNames, cancellationToken);
102+
return _factory.EvictEntityAsync(_affectedEntityNames, cancellationToken);
103103
}
104104
return Task.CompletedTask;
105105
}

src/NHibernate/Async/Engine/ActionQueue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private Task PreInvalidateCachesAsync(CancellationToken cancellationToken)
4747
}
4848
if (session.Factory.Settings.IsQueryCacheEnabled && executedSpaces.Count > 0)
4949
{
50-
return session.Factory.UpdateTimestampsCache.PreInvalidateAsync(executedSpaces, cancellationToken);
50+
return session.Factory.UpdateTimestampsCache.PreInvalidateAsync(_spacesToInvalidate, cancellationToken);
5151
}
5252
return Task.CompletedTask;
5353
}
@@ -167,10 +167,10 @@ private async Task InvalidateCachesAsync(CancellationToken cancellationToken)
167167
cancellationToken.ThrowIfCancellationRequested();
168168
if (session.Factory.Settings.IsQueryCacheEnabled && executedSpaces.Count > 0)
169169
{
170-
await (session.Factory.UpdateTimestampsCache.InvalidateAsync(executedSpaces, cancellationToken)).ConfigureAwait(false);
170+
await (session.Factory.UpdateTimestampsCache.InvalidateAsync(_spacesToInvalidate, cancellationToken)).ConfigureAwait(false);
171171
}
172172

173-
executedSpaces.Clear();
173+
_spacesToInvalidate.Clear();
174174
}
175175
private partial class BeforeTransactionCompletionProcessQueue
176176
{

src/NHibernate/Engine/ActionQueue.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public partial class ActionQueue
4343

4444
private readonly AfterTransactionCompletionProcessQueue afterTransactionProcesses;
4545
private readonly BeforeTransactionCompletionProcessQueue beforeTransactionProcesses;
46-
private readonly HashSet<string> executedSpaces;
46+
private readonly HashSet<string> _spacesToInvalidate;
4747

4848
public ActionQueue(ISessionImplementor session)
4949
{
@@ -59,7 +59,7 @@ public ActionQueue(ISessionImplementor session)
5959
afterTransactionProcesses = new AfterTransactionCompletionProcessQueue();
6060
beforeTransactionProcesses = new BeforeTransactionCompletionProcessQueue();
6161

62-
executedSpaces = new HashSet<string>();
62+
_spacesToInvalidate = new HashSet<string>();
6363
}
6464

6565
public virtual void Clear()
@@ -174,7 +174,7 @@ private void PreInvalidateCaches()
174174
{
175175
if (session.Factory.Settings.IsQueryCacheEnabled && executedSpaces.Count > 0)
176176
{
177-
session.Factory.UpdateTimestampsCache.PreInvalidate(executedSpaces);
177+
session.Factory.UpdateTimestampsCache.PreInvalidate(_spacesToInvalidate);
178178
}
179179
}
180180

@@ -219,7 +219,7 @@ private void RegisterCleanupActions(IExecutable executable)
219219

220220
if (executable.PropertySpaces != null && (!(executable is ICacheableExecutable ce) || ce.HasCache))
221221
{
222-
executedSpaces.UnionWith(executable.PropertySpaces);
222+
_spacesToInvalidate.UnionWith(executable.PropertySpaces);
223223
}
224224
}
225225

@@ -297,10 +297,10 @@ private void InvalidateCaches()
297297
{
298298
if (session.Factory.Settings.IsQueryCacheEnabled && executedSpaces.Count > 0)
299299
{
300-
session.Factory.UpdateTimestampsCache.Invalidate(executedSpaces);
300+
session.Factory.UpdateTimestampsCache.Invalidate(_spacesToInvalidate);
301301
}
302302

303-
executedSpaces.Clear();
303+
_spacesToInvalidate.Clear();
304304
}
305305

306306
/// <summary>

0 commit comments

Comments
 (0)