Skip to content

Commit 1ffbd30

Browse files
committed
Code cleanup
1 parent 778d71d commit 1ffbd30

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

src/NHibernate/Action/BulkOperationCleanupAction.cs

Lines changed: 27 additions & 32 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;
22+
private readonly ISessionFactoryImplementor _factory;
2323
private readonly HashSet<string> affectedEntityNames = new HashSet<string>();
2424
private readonly HashSet<string> affectedCollectionRoles = new HashSet<string>();
25-
private readonly List<string> spaces;
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
{
4243
affectedCollectionRoles.UnionWith(roles);
4344
}
44-
for (int y = 0; y < affectedQueryables[i].QuerySpaces.Length; y++)
45-
{
46-
tmpSpaces.Add(affectedQueryables[i].QuerySpaces[y]);
47-
}
45+
46+
tmpSpaces.UnionWith(queryables.QuerySpaces);
4847
}
49-
spaces = new List<string>(tmpSpaces);
48+
49+
spaces = tmpSpaces.ToArray();
5050
}
5151

5252
/// <summary>
@@ -55,16 +55,15 @@ 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
{
@@ -73,18 +72,17 @@ public BulkOperationCleanupAction(ISessionImplementor session, ISet<string> quer
7372
_hasCache = true;
7473
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
{
7979
affectedCollectionRoles.UnionWith(roles);
8080
}
81-
for (int y = 0; y < entitySpaces.Length; y++)
82-
{
83-
tmpSpaces.Add(entitySpaces[y]);
84-
}
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
{
@@ -142,15 +137,15 @@ private void EvictCollectionRegions()
142137
{
143138
if (affectedCollectionRoles != null && affectedCollectionRoles.Any())
144139
{
145-
session.Factory.EvictCollection(affectedCollectionRoles);
140+
_factory.EvictCollection(affectedCollectionRoles);
146141
}
147142
}
148143

149144
private void EvictEntityRegions()
150145
{
151146
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private Task EvictCollectionRegionsAsync(CancellationToken cancellationToken)
7979
{
8080
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
}
@@ -99,7 +99,7 @@ private Task EvictEntityRegionsAsync(CancellationToken cancellationToken)
9999
{
100100
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
}

0 commit comments

Comments
 (0)