-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathProperty.cs
293 lines (257 loc) · 6.36 KB
/
Property.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate.Engine;
using NHibernate.Properties;
using NHibernate.Type;
using NHibernate.Util;
namespace NHibernate.Mapping
{
/// <summary>
/// Mapping for a property of a .NET class (entity
/// or component).
/// </summary>
[Serializable]
public class Property : IMetaAttributable
{
private string name;
private IValue propertyValue;
private string cascade;
private bool updateable = true;
private bool insertable = true;
private bool selectable = true;
private string propertyAccessorName;
private bool optional;
private IDictionary<string, MetaAttribute> metaAttributes;
private PersistentClass persistentClass;
private bool isOptimisticLocked;
private PropertyGeneration generation = PropertyGeneration.Never;
private bool isLazy;
private bool isNaturalIdentifier;
public Property()
{
}
public Property(IValue propertyValue)
{
this.propertyValue = propertyValue;
}
public IType Type
{
get { return propertyValue.Type; }
}
/// <summary>
/// Gets the number of columns this property uses in the db.
/// </summary>
public int ColumnSpan
{
get { return propertyValue.ColumnSpan; }
}
/// <summary>
/// Gets an <see cref="ICollection"/> of <see cref="Column"/>s.
/// </summary>
public IEnumerable<ISelectable> ColumnIterator
{
get { return propertyValue.ColumnIterator; }
}
/// <summary>
/// Gets or Sets the name of the Property in the class.
/// </summary>
public string Name
{
get { return name; }
set { name = value; }
}
public bool IsComposite
{
get { return propertyValue is Component; }
}
public IValue Value
{
get { return propertyValue; }
set { propertyValue = value; }
}
public CascadeStyle CascadeStyle
{
get
{
IType type = propertyValue.Type;
if (type.IsComponentType && !type.IsAnyType)
{
IAbstractComponentType actype = (IAbstractComponentType)propertyValue.Type;
int length = actype.Subtypes.Length;
for (int i = 0; i < length; i++)
{
if (actype.GetCascadeStyle(i) != CascadeStyle.None)
{
return CascadeStyle.All;
}
}
return CascadeStyle.None;
}
else if (string.IsNullOrEmpty(cascade) || cascade.Equals("none"))
{
return CascadeStyle.None;
}
else
{
string[] tokens = cascade.Split(new char[] { ',' });
if (tokens.Length == 0) return CascadeStyle.None;
CascadeStyle[] styles = new CascadeStyle[tokens.Length];
int i = 0;
foreach (string token in tokens)
{
styles[i++] = CascadeStyle.GetCascadeStyle(token.Trim());
}
if (tokens.Length == 1) return styles[0];
else return new CascadeStyle.MultipleCascadeStyle(styles);
}
}
}
public string Cascade
{
get { return cascade; }
set { cascade = value; }
}
public bool IsUpdateable
{
get
{
bool[] columnUpdateability = propertyValue.ColumnUpdateability;
return updateable &&
(
// columnUpdateability.Length == 0 ||
!ArrayHelper.IsAllFalse(columnUpdateability)
);
}
set { updateable = value; }
}
public bool IsInsertable
{
get
{
bool[] columnInsertability = propertyValue.ColumnInsertability;
return insertable &&
(
columnInsertability.Length == 0 ||
!ArrayHelper.IsAllFalse(columnInsertability)
);
}
set { insertable = value; }
}
/// <summary></summary>
public bool IsNullable
{
get { return propertyValue == null || propertyValue.IsNullable; }
}
public bool IsOptional
{
get { return optional || IsNullable; }
set { optional = value; }
}
public string PropertyAccessorName
{
get { return propertyAccessorName; }
set { propertyAccessorName = value; }
}
public IGetter GetGetter(System.Type clazz)
{
return PropertyAccessor.GetGetter(clazz, name);
}
public ISetter GetSetter(System.Type clazz)
{
return PropertyAccessor.GetSetter(clazz, name);
}
protected virtual IPropertyAccessor PropertyAccessor
{
get { return PropertyAccessorFactory.GetPropertyAccessor(PropertyAccessorName); }
}
public virtual bool IsBasicPropertyAccessor
{
// NH Different behavior : see IPropertyAccessor.CanAccessThroughReflectionOptimizer (ref. NH-1304)
get { return PropertyAccessor.CanAccessThroughReflectionOptimizer; }
}
public IDictionary<string, MetaAttribute> MetaAttributes
{
get { return metaAttributes; }
set { metaAttributes = value; }
}
public MetaAttribute GetMetaAttribute(string attributeName)
{
if (metaAttributes == null)
{
return null;
}
MetaAttribute result;
metaAttributes.TryGetValue(attributeName, out result);
return result;
}
public bool IsValid(IMapping mapping)
{
return Value.IsValid(mapping);
}
public string NullValue
{
get
{
if (propertyValue is SimpleValue)
{
return ((SimpleValue)propertyValue).NullValue;
}
else
return null;
}
}
public PersistentClass PersistentClass
{
get { return persistentClass; }
set { persistentClass = value; }
}
public bool IsSelectable
{
get { return selectable; }
set { selectable = value; }
}
public bool IsOptimisticLocked
{
get { return isOptimisticLocked; }
set { isOptimisticLocked = value; }
}
public PropertyGeneration Generation
{
get { return generation; }
set { generation = value; }
}
public bool IsLazy
{
get
{
// NH Specific: Hibernate doesn't make a distinction between
// lazy and no-proxy, but NHibernate does. While Hibernate tracks
// just whatever a property is lazy, we need to track lazy/no-proxy separately.
return isLazy;
}
set { isLazy = value; }
}
public string LazyGroup { get; set; }
public virtual bool BackRef
{
get { return false; }
}
public bool IsNaturalIdentifier
{
get { return isNaturalIdentifier; }
set { isNaturalIdentifier = value; }
}
// both many-to-one and one-to-one are represented as a
// Property. EntityPersister is relying on this value to
// determine "lazy fetch groups" in terms of field-level
// interception. So we need to make sure that we return
// true here for the case of many-to-one and one-to-one
// with lazy="no-proxy"
public bool UnwrapProxy { get; set; }
public bool IsEntityRelation
{
get { return (Value as ToOne) != null; }
}
}
}