forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractComponentTuplizer.cs
125 lines (103 loc) · 3.4 KB
/
AbstractComponentTuplizer.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using NHibernate.Engine;
using NHibernate.Properties;
namespace NHibernate.Tuple.Component
{
/// <summary> Support for tuplizers relating to components. </summary>
[Serializable]
public abstract class AbstractComponentTuplizer : IComponentTuplizer
{
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(AbstractComponentTuplizer));
protected internal int propertySpan;
protected internal IGetter[] getters;
protected internal ISetter[] setters;
protected internal IInstantiator instantiator;
protected internal bool hasCustomAccessors;
protected internal AbstractComponentTuplizer(Mapping.Component component)
{
propertySpan = component.PropertySpan;
getters = new IGetter[propertySpan];
setters = new ISetter[propertySpan];
bool foundCustomAccessor = false;
int i = 0;
foreach (Mapping.Property prop in component.PropertyIterator)
{
getters[i] = BuildGetter(component, prop);
setters[i] = BuildSetter(component, prop);
if (!prop.IsBasicPropertyAccessor)
{
foundCustomAccessor = true;
}
i++;
}
if (log.IsDebugEnabled())
{
log.Debug("{0} accessors found for component: {1}", foundCustomAccessor ? "Custom" : "No custom",
component.ComponentClassName);
}
hasCustomAccessors = foundCustomAccessor;
// Only to be secure that we can access to every things
string[] getterNames = new string[propertySpan];
string[] setterNames = new string[propertySpan];
System.Type[] propTypes = new System.Type[propertySpan];
for (int j = 0; j < propertySpan; j++)
{
getterNames[j] = getters[j].PropertyName;
setterNames[j] = setters[j].PropertyName;
propTypes[j] = getters[j].ReturnType;
}
// Fix for NH-3119
//instantiator = BuildInstantiator(component);
}
#region IComponentTuplizer Members
public virtual object GetParent(object component)
{
return null;
}
public virtual void SetParent(object component, object parent, ISessionFactoryImplementor factory)
{
throw new NotSupportedException();
}
public virtual bool HasParentProperty
{
get { return false; }
}
#endregion
#region ITuplizer Members
public abstract System.Type MappedClass { get; }
public virtual object[] GetPropertyValues(object component)
{
object[] values = new object[propertySpan];
// NH Different behavior : for NH-1101
if (component != null)
for (int i = 0; i < propertySpan; i++)
values[i] = GetPropertyValue(component, i);
return values;
}
public virtual void SetPropertyValues(object component, object[] values)
{
for (int i = 0; i < propertySpan; i++)
{
setters[i].Set(component, values[i]);
}
}
public virtual object GetPropertyValue(object component, int i)
{
// NH Different behavior : for NH-1101
return component == null ? null : getters[i].Get(component);
}
/// <summary> This method does not populate the component parent</summary>
public virtual object Instantiate()
{
return instantiator.Instantiate();
}
public virtual bool IsInstance(object obj)
{
return instantiator.IsInstance(obj);
}
#endregion
protected internal abstract IInstantiator BuildInstantiator(Mapping.Component component);
protected internal abstract IGetter BuildGetter(Mapping.Component component, Mapping.Property prop);
protected internal abstract ISetter BuildSetter(Mapping.Component component, Mapping.Property prop);
}
}