forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponentMetamodel.cs
88 lines (74 loc) · 2.35 KB
/
ComponentMetamodel.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
namespace NHibernate.Tuple.Component
{
/// <summary> Centralizes metamodel information about a component. </summary>
public class ComponentMetamodel
{
private readonly string role;
private readonly bool isKey;
private readonly int propertySpan;
private readonly StandardProperty[] properties;
private readonly Dictionary<string, int> propertyIndexes;
public ComponentMetamodel(Mapping.Component component)
{
role = component.RoleName;
isKey = component.IsKey;
propertySpan = component.PropertySpan;
properties = new StandardProperty[PropertySpan];
propertyIndexes = new Dictionary<string, int>(propertySpan);
int i = 0;
foreach (Mapping.Property property in component.PropertyIterator)
{
properties[i] = PropertyFactory.BuildStandardProperty(property, false);
propertyIndexes[property.Name] = i;
i++;
}
EntityMode = component.HasPocoRepresentation ? EntityMode.Poco : EntityMode.Map;
var componentTuplizerFactory = new ComponentTuplizerFactory();
var tuplizerClassName = component.GetTuplizerImplClassName(EntityMode);
ComponentTuplizer = tuplizerClassName == null
? componentTuplizerFactory.BuildDefaultComponentTuplizer(EntityMode, component)
: componentTuplizerFactory.BuildComponentTuplizer(tuplizerClassName, component);
}
public string Role
{
get { return role; }
}
public bool IsKey
{
get { return isKey; }
}
public int PropertySpan
{
get { return propertySpan; }
}
public StandardProperty[] Properties
{
get { return properties; }
}
public StandardProperty GetProperty(int index)
{
if (index < 0 || index >= propertySpan)
{
throw new ArgumentOutOfRangeException("index", string.Format("illegal index value for component property access [request={0}, span={1}]", index, propertySpan));
}
return properties[index];
}
public int GetPropertyIndex(string propertyName)
{
int index;
if (!propertyIndexes.TryGetValue(propertyName, out index))
{
throw new HibernateException("component does not contain such a property [" + propertyName + "]");
}
return index;
}
public StandardProperty GetProperty(string propertyName)
{
return properties[GetPropertyIndex(propertyName)];
}
public EntityMode EntityMode { get; }
public IComponentTuplizer ComponentTuplizer { get; }
}
}