@@ -19,34 +19,34 @@ public partial class BulkOperationCleanupAction :
19
19
IAfterTransactionCompletionProcess ,
20
20
ICacheableExecutable
21
21
{
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 ;
26
26
private readonly bool _hasCache ;
27
27
28
28
public BulkOperationCleanupAction ( ISessionImplementor session , IQueryable [ ] affectedQueryables )
29
29
{
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 )
33
33
{
34
- if ( affectedQueryables [ i ] . HasCache )
34
+ if ( queryables . HasCache )
35
35
{
36
36
_hasCache = true ;
37
- affectedEntityNames . Add ( affectedQueryables [ i ] . EntityName ) ;
37
+ _affectedEntityNames . Add ( queryables . EntityName ) ;
38
38
}
39
- ISet < string > roles = session . Factory . GetCollectionRolesByEntityParticipant ( affectedQueryables [ i ] . EntityName ) ;
39
+
40
+ var roles = _factory . GetCollectionRolesByEntityParticipant ( queryables . EntityName ) ;
40
41
if ( roles != null )
41
42
{
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 ) ;
47
44
}
45
+
46
+ tmpSpaces . UnionWith ( queryables . QuerySpaces ) ;
48
47
}
49
- spaces = new List < string > ( tmpSpaces ) ;
48
+
49
+ _spaces = tmpSpaces . ToArray ( ) ;
50
50
}
51
51
52
52
/// <summary>
@@ -55,36 +55,34 @@ public BulkOperationCleanupAction(ISessionImplementor session, IQueryable[] affe
55
55
public BulkOperationCleanupAction ( ISessionImplementor session , ISet < string > querySpaces )
56
56
{
57
57
//from H3.2 TODO: cache the autodetected information and pass it in instead.
58
- this . session = session ;
58
+ _factory = session . Factory ;
59
59
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 ( ) ;
63
62
foreach ( KeyValuePair < string , IClassMetadata > entry in acmd )
64
63
{
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 ;
68
67
69
68
if ( AffectedEntity ( querySpaces , entitySpaces ) )
70
69
{
71
70
if ( persister . HasCache )
72
71
{
73
72
_hasCache = true ;
74
- affectedEntityNames . Add ( persister . EntityName ) ;
73
+ _affectedEntityNames . Add ( persister . EntityName ) ;
75
74
}
76
- ISet < string > roles = session . Factory . GetCollectionRolesByEntityParticipant ( persister . EntityName ) ;
75
+
76
+ var roles = session . Factory . GetCollectionRolesByEntityParticipant ( persister . EntityName ) ;
77
77
if ( roles != null )
78
78
{
79
- affectedCollectionRoles . UnionWith ( roles ) ;
80
- }
81
- for ( int y = 0 ; y < entitySpaces . Length ; y ++ )
82
- {
83
- tmpSpaces . Add ( entitySpaces [ y ] ) ;
79
+ _affectedCollectionRoles . UnionWith ( roles ) ;
84
80
}
81
+
82
+ tmpSpaces . UnionWith ( entitySpaces ) ;
85
83
}
86
84
}
87
- spaces = new List < string > ( tmpSpaces ) ;
85
+ _spaces = tmpSpaces . ToArray ( ) ;
88
86
}
89
87
90
88
private bool AffectedEntity ( ISet < string > querySpaces , string [ ] entitySpaces )
@@ -94,18 +92,14 @@ private bool AffectedEntity(ISet<string> querySpaces, string[] entitySpaces)
94
92
return true ;
95
93
}
96
94
97
-
98
95
return entitySpaces . Any ( querySpaces . Contains ) ;
99
96
}
100
97
101
98
public bool HasCache => _hasCache ;
102
99
103
100
#region IExecutable Members
104
101
105
- public string [ ] PropertySpaces
106
- {
107
- get { return spaces . ToArray ( ) ; }
108
- }
102
+ public string [ ] PropertySpaces => _spaces ;
109
103
110
104
public void BeforeExecutions ( )
111
105
{
@@ -141,17 +135,17 @@ public void ExecuteAfterTransactionCompletion(bool success)
141
135
142
136
private void EvictCollectionRegions ( )
143
137
{
144
- if ( affectedCollectionRoles != null && affectedCollectionRoles . Any ( ) )
138
+ if ( _affectedCollectionRoles != null && _affectedCollectionRoles . Any ( ) )
145
139
{
146
- session . Factory . EvictCollection ( affectedCollectionRoles ) ;
140
+ _factory . EvictCollection ( _affectedCollectionRoles ) ;
147
141
}
148
142
}
149
143
150
144
private void EvictEntityRegions ( )
151
145
{
152
- if ( affectedEntityNames != null && affectedEntityNames . Any ( ) )
146
+ if ( _affectedEntityNames != null && _affectedEntityNames . Any ( ) )
153
147
{
154
- session . Factory . EvictEntity ( affectedEntityNames ) ;
148
+ _factory . EvictEntity ( _affectedEntityNames ) ;
155
149
}
156
150
}
157
151
0 commit comments