forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubselectOneToManyLoader.cs
62 lines (56 loc) · 2.59 KB
/
SubselectOneToManyLoader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Collections.Generic;
using System.Linq;
using NHibernate.Engine;
using NHibernate.Param;
using NHibernate.Persister.Collection;
using NHibernate.SqlCommand;
using NHibernate.Type;
namespace NHibernate.Loader.Collection
{
/// <summary>
/// Implements subselect fetching for a one to many association
/// </summary>
public partial class SubselectOneToManyLoader : OneToManyLoader
{
private const int BatchSizeForSubselectFetching = 1;
private readonly object[] keys;
private readonly IDictionary<string, TypedValue> namedParameters;
private readonly IType[] types;
private readonly object[] values;
private readonly List<IParameterSpecification> parametersSpecifications;
public SubselectOneToManyLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys,
QueryParameters queryParameters,
ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
: base(persister, BatchSizeForSubselectFetching, factory, enabledFilters)
{
keys = new object[entityKeys.Count];
int i = 0;
foreach (EntityKey entityKey in entityKeys)
{
keys[i++] = entityKey.Identifier;
}
// NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters
namedParameters = new Dictionary<string, TypedValue>(queryParameters.NamedParameters);
parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList();
var processedRowSelection = queryParameters.ProcessedRowSelection;
SqlString finalSubquery = subquery;
if (queryParameters.ProcessedRowSelection != null && !SubselectClauseExtractor.HasOrderBy(queryParameters.ProcessedSql))
{
// when the original query has an "ORDER BY" we can't re-apply the pagination.
// This is a simplification, we should actually check which is the "ORDER BY" clause because when the "ORDER BY" is just for the PK we can re-apply "ORDER BY" and pagination.
finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters);
}
InitializeFromWalker(persister, finalSubquery, BatchSizeForSubselectFetching, enabledFilters, factory);
types = queryParameters.PositionalParameterTypes;
values = queryParameters.PositionalParameterValues;
}
public override void Initialize(object id, ISessionImplementor session)
{
LoadCollectionSubselect(session, keys, values, types, namedParameters, KeyType);
}
protected override IEnumerable<IParameterSpecification> GetParameterSpecifications()
{
return parametersSpecifications;
}
}
}