Skip to content

Commit 6b8bb07

Browse files
committed
Initialize collections on demand
1 parent 8571caa commit 6b8bb07

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/NHibernate/Action/BulkOperationCleanupAction.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public partial class BulkOperationCleanupAction :
2020
ICacheableExecutable
2121
{
2222
private readonly ISessionFactoryImplementor _factory;
23-
private readonly HashSet<string> _affectedEntityNames = new HashSet<string>();
24-
private readonly HashSet<string> _affectedCollectionRoles = new HashSet<string>();
23+
private readonly HashSet<string> _affectedEntityNames;
24+
private readonly HashSet<string> _affectedCollectionRoles;
2525
private readonly string[] _spaces;
2626
private readonly bool _hasCache;
2727

@@ -34,12 +34,22 @@ public BulkOperationCleanupAction(ISessionImplementor session, IQueryable[] affe
3434
if (queryables.HasCache)
3535
{
3636
_hasCache = true;
37+
if (_affectedEntityNames == null)
38+
{
39+
_affectedEntityNames = new HashSet<string>();
40+
}
41+
3742
_affectedEntityNames.Add(queryables.EntityName);
3843
}
3944

4045
var roles = _factory.GetCollectionRolesByEntityParticipant(queryables.EntityName);
4146
if (roles != null)
4247
{
48+
if (_affectedCollectionRoles == null)
49+
{
50+
_affectedCollectionRoles = new HashSet<string>();
51+
}
52+
4353
_affectedCollectionRoles.UnionWith(roles);
4454
}
4555

@@ -56,6 +66,8 @@ public BulkOperationCleanupAction(ISessionImplementor session, ISet<string> quer
5666
{
5767
//from H3.2 TODO: cache the autodetected information and pass it in instead.
5868
_factory = session.Factory;
69+
_affectedEntityNames = new HashSet<string>();
70+
_affectedCollectionRoles = new HashSet<string>();
5971

6072
var tmpSpaces = new HashSet<string>(querySpaces);
6173
var acmd = _factory.GetAllClassMetadata();
@@ -70,12 +82,22 @@ public BulkOperationCleanupAction(ISessionImplementor session, ISet<string> quer
7082
if (persister.HasCache)
7183
{
7284
_hasCache = true;
85+
if (_affectedEntityNames == null)
86+
{
87+
_affectedEntityNames = new HashSet<string>();
88+
}
89+
7390
_affectedEntityNames.Add(persister.EntityName);
7491
}
7592

7693
var roles = session.Factory.GetCollectionRolesByEntityParticipant(persister.EntityName);
7794
if (roles != null)
7895
{
96+
if (_affectedCollectionRoles == null)
97+
{
98+
_affectedCollectionRoles = new HashSet<string>();
99+
}
100+
79101
_affectedCollectionRoles.UnionWith(roles);
80102
}
81103

0 commit comments

Comments
 (0)