forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubclass.cs
510 lines (458 loc) · 14.5 KB
/
Subclass.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using NHibernate.Engine;
using NHibernate.Util;
namespace NHibernate.Mapping
{
/// <summary>
/// Declaration of a System.Type mapped with the <c><subclass></c> or
/// <c><joined-subclass></c> element.
/// </summary>
[Serializable]
public class Subclass : PersistentClass
{
private PersistentClass superclass;
private System.Type classPersisterClass;
private readonly int subclassId;
/// <summary>
/// Initializes a new instance of the <see cref="Subclass"/> class.
/// </summary>
/// <param name="superclass">The <see cref="PersistentClass"/> that is the superclass.</param>
public Subclass(PersistentClass superclass)
{
this.superclass = superclass;
subclassId = superclass.NextSubclassId();
}
public override int SubclassId
{
get { return subclassId; }
}
/// <summary>
/// Gets a boolean indicating if this mapped class is inherited from another.
/// </summary>
/// <value>
/// <see langword="true" /> because this is a SubclassType.
/// </value>
public override bool IsInherited
{
get { return true; }
}
/// <summary>
/// Gets an <see cref="ICollection"/> of <see cref="Property"/> objects that this mapped class contains.
/// </summary>
/// <value>
/// An <see cref="ICollection"/> of <see cref="Property"/> objects that
/// this mapped class contains.
/// </value>
/// <remarks>
/// This is all of the properties of this mapped class and each mapped class that
/// it is inheriting from.
/// </remarks>
public override IEnumerable<Property> PropertyClosureIterator
{
get { return Superclass.PropertyClosureIterator.Concat(PropertyIterator); }
}
/// <summary>
/// Gets an <see cref="ICollection"/> of <see cref="Table"/> objects that this
/// mapped class reads from and writes to.
/// </summary>
/// <value>
/// An <see cref="ICollection"/> of <see cref="Table"/> objects that
/// this mapped class reads from and writes to.
/// </value>
/// <remarks>
/// This is all of the tables of this mapped class and each mapped class that
/// it is inheriting from.
/// </remarks>
public override IEnumerable<Table> TableClosureIterator
{
get { return Superclass.TableClosureIterator.Concat(new[] {Table}); }
}
public override IEnumerable<IKeyValue> KeyClosureIterator
{
get { return Superclass.KeyClosureIterator.Concat(new[] {Key}); }
}
/// <summary>
/// Gets a boolean indicating if the mapped class has a version property.
/// </summary>
/// <value><see langword="true" /> if for the Superclass there is a Property for a <c>version</c>.</value>
public override bool IsVersioned
{
get { return Superclass.IsVersioned; }
}
/// <summary>
///
/// </summary>
public override System.Type EntityPersisterClass
{
get
{
if (classPersisterClass == null)
{
return Superclass.EntityPersisterClass;
}
else
{
return classPersisterClass;
}
}
set { classPersisterClass = value; }
}
/// <summary>
/// Gets the <see cref="Table"/> of the class
/// that is mapped in the <c>class</c> element.
/// </summary>
/// <value>
/// The <see cref="Table"/> of the Superclass that is mapped in the <c>class</c> element.
/// </value>
public override Table RootTable
{
get { return Superclass.RootTable; }
}
/// <summary>
///
/// </summary>
public override bool IsJoinedSubclass
{
get { return Table != RootTable; }
}
public override int JoinClosureSpan
{
get { return Superclass.JoinClosureSpan + base.JoinClosureSpan; }
}
public override int PropertyClosureSpan
{
get { return Superclass.PropertyClosureSpan + base.PropertyClosureSpan; }
}
public override IEnumerable<Join> JoinClosureIterator
{
get { return Superclass.JoinClosureIterator.Concat(base.JoinClosureIterator); }
}
public override ISet<string> SynchronizedTables
{
get
{
HashSet<string> result = new HashSet<string>();
result.UnionWith(base.SynchronizedTables);
result.UnionWith(Superclass.SynchronizedTables);
return result;
}
}
public override IDictionary<string, string> FilterMap
{
get {
var superclassFilters = Superclass.FilterMap;
var subclassFilters = base.FilterMap;
return superclassFilters.Union(
subclassFilters
).ToDictionary(k => k.Key, v => v.Value);
}
}
public override IDictionary<EntityMode, string> TuplizerMap
{
get
{
IDictionary<EntityMode, string> specificTuplizerDefs = base.TuplizerMap;
IDictionary<EntityMode, string> superclassTuplizerDefs = Superclass.TuplizerMap;
if (specificTuplizerDefs == null && superclassTuplizerDefs == null)
{
return null;
}
else
{
IDictionary<EntityMode, string> combined = new Dictionary<EntityMode, string>();
if (superclassTuplizerDefs != null)
{
ArrayHelper.AddAll(combined, superclassTuplizerDefs);
}
if (specificTuplizerDefs != null)
{
ArrayHelper.AddAll(combined, specificTuplizerDefs);
}
return new ReadOnlyDictionary<EntityMode, string>(combined);
}
}
}
internal override int NextSubclassId()
{
return Superclass.NextSubclassId();
}
/// <summary>
/// Gets or sets the CacheConcurrencyStrategy
/// to use to read/write instances of the persistent class to the Cache.
/// </summary>
/// <value>The CacheConcurrencyStrategy used with the Cache.</value>
public override string CacheConcurrencyStrategy
{
get { return Superclass.CacheConcurrencyStrategy; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets the <see cref="RootClazz"/> of the class that is mapped in the <c>class</c> element.
/// </summary>
/// <value>
/// The <see cref="RootClazz"/> of the Superclass that is mapped in the <c>class</c> element.
/// </value>
public override RootClass RootClazz
{
get { return Superclass.RootClazz; }
}
/// <summary>
/// Gets or sets the <see cref="PersistentClass"/> that this mapped class is extending.
/// </summary>
/// <value>
/// The <see cref="PersistentClass"/> that this mapped class is extending.
/// </value>
public override PersistentClass Superclass
{
get { return superclass; }
set { superclass = value; }
}
/// <summary>
/// Gets or sets the <see cref="Property"/> that is used as the <c>id</c>.
/// </summary>
/// <value>
/// The <see cref="Property"/> from the Superclass that is used as the <c>id</c>.
/// </value>
public override Property IdentifierProperty
{
get { return Superclass.IdentifierProperty; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets or sets the <see cref="SimpleValue"/> that contains information about the identifier.
/// </summary>
/// <value>The <see cref="SimpleValue"/> from the Superclass that contains information about the identifier.</value>
public override IKeyValue Identifier
{
get { return Superclass.Identifier; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets a boolean indicating if the mapped class has a Property for the <c>id</c>.
/// </summary>
/// <value><see langword="true" /> if in the Superclass there is a Property for the <c>id</c>.</value>
public override bool HasIdentifierProperty
{
get { return Superclass.HasIdentifierProperty; }
}
/// <summary>
/// Gets or sets the <see cref="SimpleValue"/> that contains information about the discriminator.
/// </summary>
/// <value>The <see cref="SimpleValue"/> from the Superclass that contains information about the discriminator.</value>
public override IValue Discriminator
{
get { return Superclass.Discriminator; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets or set a boolean indicating if the mapped class has properties that can be changed.
/// </summary>
/// <value><see langword="true" /> if the Superclass is mutable.</value>
public override bool IsMutable
{
get { return Superclass.IsMutable; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets or sets if the mapped class is a subclass.
/// </summary>
/// <value>
/// <see langword="true" /> since this mapped class is a subclass.
/// </value>
/// <remarks>
/// The setter should not be used to set the value to anything but <see langword="true" />.
/// </remarks>
public override bool IsPolymorphic
{
get { return true; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Add the <see cref="Property"/> to this PersistentClass.
/// </summary>
/// <param name="p">The <see cref="Property"/> to add.</param>
/// <remarks>
/// This also adds the <see cref="Property"/> to the Superclass' collection
/// of SubclassType Properties.
/// </remarks>
public override void AddProperty(Property p)
{
base.AddProperty(p);
Superclass.AddSubclassProperty(p);
}
public override void AddJoin(Join join)
{
base.AddJoin(join);
Superclass.AddSubclassJoin(join);
}
/// <summary>
/// Adds a <see cref="Property"/> that is implemented by a subclass.
/// </summary>
/// <param name="p">The <see cref="Property"/> implemented by a subclass.</param>
/// <remarks>
/// This also adds the <see cref="Property"/> to the Superclass' collection
/// of SubclassType Properties.
/// </remarks>
public override void AddSubclassProperty(Property p)
{
base.AddSubclassProperty(p);
Superclass.AddSubclassProperty(p);
}
public override void AddSubclassJoin(Join join)
{
base.AddSubclassJoin(join);
Superclass.AddSubclassJoin(join);
}
/// <summary>
/// Adds a <see cref="Table"/> that a subclass is stored in.
/// </summary>
/// <param name="table">The <see cref="Table"/> the subclass is stored in.</param>
/// <remarks>
/// This also adds the <see cref="Table"/> to the Superclass' collection
/// of SubclassType Tables.
/// </remarks>
public override void AddSubclassTable(Table table)
{
base.AddSubclassTable(table);
Superclass.AddSubclassTable(table);
}
/// <summary>
/// Gets or sets the <see cref="Property"/> that is used as the version.
/// </summary>
/// <value>The <see cref="Property"/> from the Superclass that is used as the version.</value>
public override Property Version
{
get { return Superclass.Version; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets or sets a boolean indicating if the identifier is
/// embedded in the class.
/// </summary>
/// <value><see langword="true" /> if the Superclass has an embedded identifier.</value>
/// <remarks>
/// An embedded identifier is true when using a <c>composite-id</c> specifying
/// properties of the class as the <c>key-property</c> instead of using a class
/// as the <c>composite-id</c>.
/// </remarks>
public override bool HasEmbeddedIdentifier
{
get { return Superclass.HasEmbeddedIdentifier; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets or sets the <see cref="SimpleValue"/> that contains information about the Key.
/// </summary>
/// <value>The <see cref="SimpleValue"/> that contains information about the Key.</value>
public override IKeyValue Key
{
get { return Superclass.Identifier; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets or sets a boolean indicating if explicit polymorphism should be used in Queries.
/// </summary>
/// <value>
/// The value of the Superclasses <c>IsExplicitPolymorphism</c> property.
/// </value>
public override bool IsExplicitPolymorphism
{
get { return Superclass.IsExplicitPolymorphism; }
set { /* Don't change the SuperClass */ }
}
/// <summary>
/// Gets the sql string that should be a part of the where clause.
/// </summary>
/// <value>
/// The sql string that should be a part of the where clause.
/// </value>
/// <exception cref="InvalidOperationException">
/// Thrown when the setter is called. The where clause can not be set on the
/// SubclassType, only the RootClass.
/// </exception>
public override string Where
{
get { return Superclass.Where; }
set { throw new InvalidOperationException("The Where string can not be set on the Subclass - use the RootClass instead."); }
}
/// <summary>
///
/// </summary>
public void CreateForeignKey()
{
if (!IsJoinedSubclass)
{
throw new AssertionFailure("Not a joined-subclass");
}
Key.CreateForeignKeyOfEntity(Superclass.EntityName);
}
public override bool IsLazyPropertiesCacheable
{
get { return Superclass.IsLazyPropertiesCacheable; }
}
public override bool IsClassOrSuperclassJoin(Join join)
{
return base.IsClassOrSuperclassJoin(join) || Superclass.IsClassOrSuperclassJoin(join);
}
public override bool IsClassOrSuperclassTable(Table closureTable)
{
return base.IsClassOrSuperclassTable(closureTable) || Superclass.IsClassOrSuperclassTable(closureTable);
}
/// <summary>
/// Gets or Sets the <see cref="Table"/> that this class is stored in.
/// </summary>
/// <value>The <see cref="Table"/> this class is stored in.</value>
/// <remarks>
/// This also adds the <see cref="Table"/> to the Superclass' collection
/// of SubclassType Tables.
/// </remarks>
public override Table Table
{
get { return Superclass.Table; }
}
public override bool IsForceDiscriminator
{
get { return Superclass.IsForceDiscriminator; }
}
/// <summary>
///
/// </summary>
public override bool IsDiscriminatorInsertable
{
get { return Superclass.IsDiscriminatorInsertable; }
set
{
throw new InvalidOperationException(
"The DiscriminatorInsertable property can not be set on the Subclass - use the Superclass instead.");
}
}
public override object Accept(IPersistentClassVisitor mv)
{
return mv.Accept(this);
}
public override bool HasSubselectLoadableCollections
{
get { return base.HasSubselectLoadableCollections || Superclass.HasSubselectLoadableCollections; }
set { base.HasSubselectLoadableCollections = value; }
}
public override string GetTuplizerImplClassName(EntityMode mode)
{
string impl = base.GetTuplizerImplClassName(mode);
if (impl == null)
impl = Superclass.GetTuplizerImplClassName(mode);
return impl;
}
public override Component IdentifierMapper
{
get { return superclass.IdentifierMapper; }
}
public override Versioning.OptimisticLock OptimisticLockMode
{
get { return superclass.OptimisticLockMode; }
}
}
}