forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionLoader.cs
71 lines (63 loc) · 2.27 KB
/
CollectionLoader.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
63
64
65
66
67
68
69
70
71
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>
/// Superclass for loaders that initialize collections
/// <seealso cref="OneToManyLoader" />
/// <seealso cref="BasicCollectionLoader" />
/// </summary>
public class CollectionLoader : OuterJoinLoader, ICollectionInitializer
{
private readonly IQueryableCollection collectionPersister;
private IParameterSpecification[] parametersSpecifications;
public CollectionLoader(IQueryableCollection persister, ISessionFactoryImplementor factory,
IDictionary<string, IFilter> enabledFilters) : base(factory, enabledFilters)
{
collectionPersister = persister;
}
public override bool IsSubselectLoadingEnabled
{
get { return HasSubselectLoadableCollections(); }
}
protected IType KeyType
{
get { return collectionPersister.KeyType; }
}
public virtual void Initialize(object id, ISessionImplementor session)
{
LoadCollection(session, id, KeyType);
}
public override string ToString()
{
return GetType().FullName + '(' + collectionPersister.Role + ')';
}
protected virtual IEnumerable<IParameterSpecification> CreateParameterSpecificationsAndAssignBackTrack(IEnumerable<Parameter> sqlPatameters)
{
// This implementation can manage even the case of batch-loading
var specifications = new List<IParameterSpecification>();
int position = 0;
var parameters = sqlPatameters.ToArray();
for (var sqlParameterPos = 0; sqlParameterPos < parameters.Length; )
{
var specification = new PositionalParameterSpecification(1, 0, position++) { ExpectedType = KeyType };
var paramTrackers = specification.GetIdsForBackTrack(Factory);
foreach (var paramTracker in paramTrackers)
{
parameters[sqlParameterPos++].BackTrack = paramTracker;
}
specifications.Add(specification);
}
return specifications;
}
protected override IEnumerable<IParameterSpecification> GetParameterSpecifications()
{
return parametersSpecifications ?? (parametersSpecifications = CreateParameterSpecificationsAndAssignBackTrack(SqlString.GetParameters()).ToArray());
}
}
}