Skip to content

Commit 4b40405

Browse files
committed
Fixes after code review
1 parent 0cd9c10 commit 4b40405

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

src/NHibernate/Async/Engine/BatchFetchQueue.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task<object[]> GetCollectionBatchAsync(ICollectionPersister collect
4343

4444
if (batchLoadableCollections.TryGetValue(collectionPersister.Role, out var map))
4545
{
46-
foreach (KeyValuePair<CollectionEntry,IPersistentCollection> me in map)
46+
foreach (KeyValuePair<CollectionEntry, IPersistentCollection> me in map)
4747
{
4848
var ce = me.Key;
4949
var collection = me.Value;
@@ -59,11 +59,7 @@ public async Task<object[]> GetCollectionBatchAsync(ICollectionPersister collect
5959

6060
if (collection.WasInitialized)
6161
{
62-
// should never happen
63-
if (log.IsWarnEnabled())
64-
{
65-
log.Warn("Encountered initialized collection in BatchFetchQueue, this should not happen.");
66-
}
62+
log.Warn("Encountered initialized collection in BatchFetchQueue, this should not happen.");
6763
continue;
6864
}
6965

@@ -99,7 +95,7 @@ public async Task<object[]> GetCollectionBatchAsync(ICollectionPersister collect
9995
}
10096
}
10197
}
102-
98+
10399
return keys; //we ran out of keys to try
104100
}
105101

@@ -113,7 +109,7 @@ public async Task<object[]> GetCollectionBatchAsync(ICollectionPersister collect
113109
/// <param name="batchSize">The maximum number of keys to return</param>
114110
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
115111
/// <returns>an array of identifiers, of length batchSize (possibly padded with nulls)</returns>
116-
public async Task<object[]> GetEntityBatchAsync(IEntityPersister persister,object id,int batchSize, CancellationToken cancellationToken)
112+
public async Task<object[]> GetEntityBatchAsync(IEntityPersister persister, object id, int batchSize, CancellationToken cancellationToken)
117113
{
118114
cancellationToken.ThrowIfCancellationRequested();
119115
object[] ids = new object[batchSize];
@@ -122,7 +118,7 @@ public async Task<object[]> GetEntityBatchAsync(IEntityPersister persister,objec
122118
int end = -1;
123119
bool checkForEnd = false;
124120

125-
if (batchLoadableEntityKeys.TryGetValue(persister.EntityName,out var set))//TODO: this needn't exclude subclasses...
121+
if (batchLoadableEntityKeys.TryGetValue(persister.EntityName, out var set))
126122
{
127123
foreach (var key in set)
128124
{

src/NHibernate/Engine/BatchFetchQueue.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public partial class BatchFetchQueue
2222
/// type at a time.
2323
/// </remarks>
2424
private readonly IDictionary<string, LinkedHashSet<EntityKey>> batchLoadableEntityKeys = new Dictionary<string, LinkedHashSet<EntityKey>>(8);
25-
25+
2626
/// <summary>
2727
/// A map of <see cref="SubselectFetch">subselect-fetch descriptors</see>
2828
/// keyed by the <see cref="EntityKey" /> against which the descriptor is
2929
/// registered.
3030
/// </summary>
3131
private readonly IDictionary<EntityKey, SubselectFetch> subselectsByEntityKey = new Dictionary<EntityKey, SubselectFetch>(8);
3232

33-
private readonly IDictionary<string, LinkedHashMap <CollectionEntry, IPersistentCollection>> batchLoadableCollections = new Dictionary<string, LinkedHashMap<CollectionEntry, IPersistentCollection>>(8);
33+
private readonly IDictionary<string, LinkedHashMap<CollectionEntry, IPersistentCollection>> batchLoadableCollections = new Dictionary<string, LinkedHashMap<CollectionEntry, IPersistentCollection>>(8);
3434
/// <summary>
3535
/// The owning persistence context.
3636
/// </summary>
@@ -155,7 +155,7 @@ public void AddBatchLoadableCollection(IPersistentCollection collection, Collect
155155
map = new LinkedHashMap<CollectionEntry, IPersistentCollection>();
156156
batchLoadableCollections.Add(persister.Role, map);
157157
}
158-
map[ce]=collection;
158+
map[ce] = collection;
159159
}
160160

161161
/// <summary>
@@ -189,7 +189,7 @@ public object[] GetCollectionBatch(ICollectionPersister collectionPersister, obj
189189

190190
if (batchLoadableCollections.TryGetValue(collectionPersister.Role, out var map))
191191
{
192-
foreach (KeyValuePair<CollectionEntry,IPersistentCollection> me in map)
192+
foreach (KeyValuePair<CollectionEntry, IPersistentCollection> me in map)
193193
{
194194
var ce = me.Key;
195195
var collection = me.Value;
@@ -205,11 +205,7 @@ public object[] GetCollectionBatch(ICollectionPersister collectionPersister, obj
205205

206206
if (collection.WasInitialized)
207207
{
208-
// should never happen
209-
if (log.IsWarnEnabled())
210-
{
211-
log.Warn("Encountered initialized collection in BatchFetchQueue, this should not happen.");
212-
}
208+
log.Warn("Encountered initialized collection in BatchFetchQueue, this should not happen.");
213209
continue;
214210
}
215211

@@ -245,7 +241,7 @@ public object[] GetCollectionBatch(ICollectionPersister collectionPersister, obj
245241
}
246242
}
247243
}
248-
244+
249245
return keys; //we ran out of keys to try
250246
}
251247

@@ -258,15 +254,15 @@ public object[] GetCollectionBatch(ICollectionPersister collectionPersister, obj
258254
/// <param name="id">The identifier of the entity currently demanding load.</param>
259255
/// <param name="batchSize">The maximum number of keys to return</param>
260256
/// <returns>an array of identifiers, of length batchSize (possibly padded with nulls)</returns>
261-
public object[] GetEntityBatch(IEntityPersister persister,object id,int batchSize)
257+
public object[] GetEntityBatch(IEntityPersister persister, object id, int batchSize)
262258
{
263259
object[] ids = new object[batchSize];
264260
ids[0] = id; //first element of array is reserved for the actual instance we are loading!
265261
int i = 1;
266262
int end = -1;
267263
bool checkForEnd = false;
268264

269-
if (batchLoadableEntityKeys.TryGetValue(persister.EntityName,out var set))//TODO: this needn't exclude subclasses...
265+
if (batchLoadableEntityKeys.TryGetValue(persister.EntityName, out var set))
270266
{
271267
foreach (var key in set)
272268
{

src/NHibernate/Engine/StatefulPersistenceContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ public void AddUninitializedCollection(ICollectionPersister persister, IPersiste
835835
{
836836
CollectionEntry ce = new CollectionEntry(collection, persister, id, flushing);
837837
AddCollection(collection, ce, id);
838-
if (persister.BatchSize > 0)
838+
if (persister.BatchSize > 1)
839839
{
840840
batchFetchQueue.AddBatchLoadableCollection(collection, ce);
841841
}

0 commit comments

Comments
 (0)