forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersistentClass.cs
1168 lines (1042 loc) · 33.3 KB
/
PersistentClass.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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Util;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace NHibernate.Mapping
{
/// <summary>
/// Base class for the <see cref="RootClazz" /> mapped by <c><class></c> and a
/// <see cref="Subclass"/> that is mapped by <c><subclass></c> or
/// <c><joined-subclass></c>.
/// </summary>
[Serializable]
public abstract class PersistentClass : IFilterable, IMetaAttributable, ISqlCustomizable
{
private static readonly Alias PKAlias = new Alias(15, "PK");
/// <summary></summary>
public const string NullDiscriminatorMapping = "null";
/// <summary></summary>
public const string NotNullDiscriminatorMapping = "not null";
private string entityName;
private string className;
private string proxyInterfaceName;
private string discriminatorValue;
private bool lazy;
private readonly List<Property> properties = new List<Property>();
private readonly List<Subclass> subclasses = new List<Subclass>();
private readonly List<Property> subclassProperties = new List<Property>();
private readonly List<Table> subclassTables = new List<Table>();
private bool dynamicInsert;
private bool dynamicUpdate;
private int? batchSize;
private bool selectBeforeUpdate;
private IDictionary<string, MetaAttribute> metaAttributes;
private readonly List<Join> joins = new List<Join>();
private readonly List<Join> subclassJoins = new List<Join>();
private readonly Dictionary<string, string> filters = new Dictionary<string, string>();
private readonly HashSet<string> synchronizedTables = new HashSet<string>();
private string loaderName;
private bool? isAbstract;
private bool hasSubselectLoadableCollections;
private Component identifierMapper;
private SqlString customSQLInsert;
private bool customInsertCallable;
private ExecuteUpdateResultCheckStyle insertCheckStyle;
private SqlString customSQLUpdate;
private bool customUpdateCallable;
private ExecuteUpdateResultCheckStyle updateCheckStyle;
private SqlString customSQLDelete;
private bool customDeleteCallable;
private ExecuteUpdateResultCheckStyle deleteCheckStyle;
private string temporaryIdTableName;
private string temporaryIdTableDDL;
private IDictionary<EntityMode, string> tuplizerImpls;
private Versioning.OptimisticLock optimisticLockMode;
private System.Type mappedClass;
private System.Type proxyInterface;
public string ClassName
{
get { return className; }
set
{
className = value == null ? null : string.Intern(value);
mappedClass = null;
}
}
public string ProxyInterfaceName
{
get { return proxyInterfaceName; }
set
{
proxyInterfaceName = value;
proxyInterface = null;
}
}
/// <summary>
/// Gets the <see cref="System.Type"/> that is being mapped.
/// </summary>
/// <value>The <see cref="System.Type"/> that is being mapped.</value>
/// <remarks>
/// The value of this is set by the <c>name</c> attribute on the <c><class></c>
/// element.
/// </remarks>
public virtual System.Type MappedClass
{
get
{
if (mappedClass == null)
{
if (className == null)
return null;
try
{
mappedClass = ReflectHelper.ClassForName(className);
}
catch (Exception cnfe)
{
throw new MappingException("entity class not found: " + className, cnfe);
}
}
return mappedClass;
}
}
/// <summary>
/// Gets or sets the <see cref="System.Type"/> to use as a Proxy.
/// </summary>
/// <value>The <see cref="System.Type"/> to use as a Proxy.</value>
/// <remarks>
/// The value of this is set by the <c>proxy</c> attribute.
/// </remarks>
public virtual System.Type ProxyInterface
{
get
{
if (proxyInterface == null)
{
if (proxyInterfaceName == null)
return null;
try
{
proxyInterface = ReflectHelper.ClassForName(proxyInterfaceName);
}
catch (Exception cnfe)
{
throw new MappingException("proxy class not found: " + proxyInterfaceName, cnfe);
}
}
return proxyInterface;
}
}
public abstract int SubclassId { get; }
/// <summary>
/// Gets or Sets if the Insert Sql is built dynamically.
/// </summary>
/// <value><see langword="true" /> if the Sql is built at runtime.</value>
/// <remarks>
/// The value of this is set by the <c>dynamic-insert</c> attribute.
/// </remarks>
public virtual bool DynamicInsert
{
get { return dynamicInsert; }
set { dynamicInsert = value; }
}
/// <summary>
/// Gets or Sets if the Update Sql is built dynamically.
/// </summary>
/// <value><see langword="true" /> if the Sql is built at runtime.</value>
/// <remarks>
/// The value of this is set by the <c>dynamic-update</c> attribute.
/// </remarks>
public virtual bool DynamicUpdate
{
get { return dynamicUpdate; }
set { dynamicUpdate = value; }
}
/// <summary>
/// Gets or Sets the value to use as the discriminator for the Class.
/// </summary>
/// <value>
/// A value that distinguishes this subclass in the database.
/// </value>
/// <remarks>
/// The value of this is set by the <c>discriminator-value</c> attribute. Each <c><subclass></c>
/// in a hierarchy must define a unique <c>discriminator-value</c>. The default value
/// is the class name if no value is supplied.
/// </remarks>
public virtual string DiscriminatorValue
{
get { return discriminatorValue; }
set { discriminatorValue = value; }
}
/// <summary>
/// Gets the number of subclasses that inherit either directly or indirectly.
/// </summary>
/// <value>The number of subclasses that inherit from this PersistentClass.</value>
public virtual int SubclassSpan
{
get
{
int n = subclasses.Count;
foreach (Subclass sc in subclasses)
n += sc.SubclassSpan;
return n;
}
}
/// <summary>
/// Iterate over subclasses in a special 'order', most derived subclasses first.
/// </summary>
/// <value>
/// It will recursively go through Subclasses so that if a SubclassType has Subclasses
/// it will pick those up also.
/// </value>
public virtual IEnumerable<Subclass> SubclassIterator
{
get
{
return subclasses.SelectMany(s => s.SubclassIterator).Concat(subclasses);
}
}
public virtual IEnumerable<PersistentClass> SubclassClosureIterator
{
get
{
return new[] {this}.Concat(SubclassIterator.SelectMany(x => x.SubclassClosureIterator));
}
}
public virtual Table IdentityTable
{
get { return RootTable; }
}
/// <summary>
/// Gets an <see cref="IEnumerable"/> of <see cref="Subclass"/> objects
/// that directly inherit from this PersistentClass.
/// </summary>
/// <value>
/// An <see cref="IEnumerable"/> of <see cref="Subclass"/> objects
/// that directly inherit from this PersistentClass.
/// </value>
public virtual IEnumerable<Subclass> DirectSubclasses
{
get { return subclasses; }
}
public virtual string EntityName
{
get { return entityName; }
set { entityName = value == null ? null : String.Intern(value); }
}
/// <summary>
/// When implemented by a class, gets a boolean indicating if this
/// mapped class is inherited from another.
/// </summary>
/// <value>
/// <see langword="true" /> if this class is a <c>subclass</c> or <c>joined-subclass</c>
/// that inherited from another <c>class</c>.
/// </value>
public abstract bool IsInherited { get; }
/// <summary>
/// When implemented by a class, gets a boolean indicating if the mapped class
/// has a version property.
/// </summary>
/// <value><see langword="true" /> if there is a <c><version></c> property.</value>
public abstract bool IsVersioned { get; }
/// <summary>
/// When implemented by a class, gets an <see cref="IEnumerable"/>
/// of <see cref="Property"/> objects that this mapped class contains.
/// </summary>
/// <value>
/// An <see cref="IEnumerable"/> 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 abstract IEnumerable<Property> PropertyClosureIterator { get; }
/// <summary>
/// When implemented by a class, gets an <see cref="IEnumerable"/>
/// of <see cref="Table"/> objects that this mapped class reads from
/// and writes to.
/// </summary>
/// <value>
/// An <see cref="IEnumerable"/> 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 abstract IEnumerable<Table> TableClosureIterator { get; }
public abstract IEnumerable<IKeyValue> KeyClosureIterator { get; }
/// <summary>
/// Gets an <see cref="IEnumerable"/> of <see cref="Property"/> objects that
/// this mapped class contains and that all of its subclasses contain.
/// </summary>
/// <value>
/// An <see cref="IEnumerable"/> of <see cref="Property"/> objects that
/// this mapped class contains and that all of its subclasses contain.
/// </value>
public virtual IEnumerable<Property> SubclassPropertyClosureIterator
{
get
{
return PropertyClosureIterator
.Concat(subclassProperties)
.Concat(subclassJoins.SelectMany(x => x.PropertyIterator));
}
}
public virtual IEnumerable<Join> SubclassJoinClosureIterator
{
get { return JoinClosureIterator.Concat(subclassJoins); }
}
/// <summary>
/// Gets an <see cref="IEnumerable"/> of all of the <see cref="Table"/> objects that the
/// subclass finds its information in.
/// </summary>
/// <value>An <see cref="IEnumerable"/> of <see cref="Table"/> objects.</value>
/// <remarks>It adds the TableClosureIterator and the subclassTables into the IEnumerable.</remarks>
public virtual IEnumerable<Table> SubclassTableClosureIterator
{
get { return TableClosureIterator.Concat(subclassTables); }
}
public bool IsLazy
{
get { return lazy; }
set { lazy = value; }
}
/// <summary>
/// When implemented by a class, gets or sets the <see cref="System.Type"/> of the Persister.
/// </summary>
public abstract System.Type EntityPersisterClass { get; set; }
/// <summary>
/// When implemented by a class, 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 class that is mapped in the <c>class</c> element.
/// </value>
public abstract Table RootTable { get; }
/// <summary>
///
/// </summary>
public int? BatchSize
{
get { return batchSize; }
set { batchSize = value; }
}
/// <summary>
///
/// </summary>
public bool SelectBeforeUpdate
{
get { return selectBeforeUpdate; }
set { selectBeforeUpdate = value; }
}
/// <summary>
/// Build a collection of properties which are "referenceable".
/// </summary>
/// <remarks>
/// See <see cref="GetReferencedProperty"/> for a discussion of "referenceable".
/// </remarks>
public virtual IEnumerable<Property> ReferenceablePropertyIterator
{
get { return PropertyClosureIterator; }
}
/// <summary>
///
/// </summary>
public bool IsDiscriminatorValueNotNull
{
get { return NotNullDiscriminatorMapping.Equals(DiscriminatorValue); }
}
/// <summary>
///
/// </summary>
public bool IsDiscriminatorValueNull
{
get { return NullDiscriminatorMapping.Equals(DiscriminatorValue); }
}
public IDictionary<string, MetaAttribute> MetaAttributes
{
get { return metaAttributes; }
set { metaAttributes = value; }
}
public virtual IEnumerable<Join> JoinIterator
{
get { return joins; }
}
public virtual IEnumerable<Join> JoinClosureIterator
{
get { return joins; }
}
public virtual int JoinClosureSpan
{
get { return joins.Count; }
}
public virtual int PropertyClosureSpan
{
get { return properties.Count + joins.Sum(j => j.PropertySpan); }
}
/// <summary>
/// Build an iterator over the properties defined on this class. The returned
/// iterator only accounts for "normal" properties (i.e. non-identifier
/// properties).
/// </summary>
/// <value>
/// An <see cref="IEnumerable"/> of <see cref="Property"/> objects.
/// </value>
/// <remarks>
/// Differs from <see cref="UnjoinedPropertyIterator"/> in that the iterator
/// we return here will include properties defined as part of a join.
/// </remarks>
public virtual IEnumerable<Property> PropertyIterator
{
get
{
return properties.Concat(joins.SelectMany(x => x.PropertyIterator));
}
}
/// <summary>
/// Build an enumerable over the properties defined on this class <b>which
/// are not defined as part of a join</b>.
/// As with <see cref="PropertyIterator"/> the returned iterator only accounts
/// for non-identifier properties.
/// </summary>
/// <returns> An enumerable over the non-joined "normal" properties.</returns>
public virtual IEnumerable<Property> UnjoinedPropertyIterator
{
get { return properties; }
}
public bool IsCustomInsertCallable
{
get { return customInsertCallable; }
}
public ExecuteUpdateResultCheckStyle CustomSQLInsertCheckStyle
{
get { return insertCheckStyle; }
}
public bool IsCustomUpdateCallable
{
get { return customUpdateCallable; }
}
public ExecuteUpdateResultCheckStyle CustomSQLUpdateCheckStyle
{
get { return updateCheckStyle; }
}
public bool IsCustomDeleteCallable
{
get { return customDeleteCallable; }
}
public ExecuteUpdateResultCheckStyle CustomSQLDeleteCheckStyle
{
get { return deleteCheckStyle; }
}
public virtual IDictionary<string, string> FilterMap
{
get { return filters; }
}
/// <summary>
///
/// </summary>
public abstract bool IsJoinedSubclass { get; }
public string LoaderName
{
get { return loaderName; }
set { loaderName = value == null ? null : string.Intern(value); }
}
public virtual ISet<string> SynchronizedTables
{
get
{
return synchronizedTables;
}
}
protected internal virtual IEnumerable<Property> NonDuplicatedPropertyIterator
{
get { return UnjoinedPropertyIterator; }
}
protected virtual internal IEnumerable<ISelectable> DiscriminatorColumnIterator
{
get { return new CollectionHelper.EmptyEnumerableClass<ISelectable>(); }
}
public virtual bool HasSubselectLoadableCollections
{
get { return hasSubselectLoadableCollections; }
set { hasSubselectLoadableCollections = value; }
}
public string TemporaryIdTableName
{
get { return temporaryIdTableName; }
}
public string TemporaryIdTableDDL
{
get { return temporaryIdTableDDL; }
}
public virtual IDictionary<EntityMode, string> TuplizerMap
{
get
{
return tuplizerImpls == null ? null : new ReadOnlyDictionary<EntityMode, string>(tuplizerImpls);
}
}
internal abstract int NextSubclassId();
/// <summary>
/// Adds a <see cref="Subclass"/> to the class hierarchy.
/// </summary>
/// <param name="subclass">The <see cref="Subclass"/> to add to the hierarchy.</param>
public virtual void AddSubclass(Subclass subclass)
{
// Inheritable cycle detection (paranoid check)
PersistentClass superclass = Superclass;
while (superclass != null)
{
if (subclass.EntityName.Equals(superclass.EntityName))
{
throw new MappingException(
string.Format("Circular inheritance mapping detected: {0} will have itself as superclass when extending {1}",
subclass.EntityName, EntityName));
}
superclass = superclass.Superclass;
}
subclasses.Add(subclass);
}
/// <summary>
/// Gets a boolean indicating if this PersistentClass has any subclasses.
/// </summary>
/// <value><see langword="true" /> if this PeristentClass has any subclasses.</value>
public virtual bool HasSubclasses
{
get { return subclasses.Count > 0; }
}
/// <summary>
/// Change the property definition or add a new property definition
/// </summary>
/// <param name="p">The <see cref="Property"/> to add.</param>
public virtual void AddProperty(Property p)
{
properties.Add(p);
p.PersistentClass = this;
}
/// <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>
/// The value of this is set by the <c>table</c> attribute.
/// </remarks>
public abstract Table Table { get; }
/// <summary>
/// When implemented by a class, gets or set a boolean indicating
/// if the mapped class has properties that can be changed.
/// </summary>
/// <value><see langword="true" /> if the object is mutable.</value>
/// <remarks>
/// The value of this is set by the <c>mutable</c> attribute.
/// </remarks>
public abstract bool IsMutable { get; set; }
/// <summary>
/// When implemented by a class, gets a boolean indicating
/// if the mapped class has a Property for the <c>id</c>.
/// </summary>
/// <value><see langword="true" /> if there is a Property for the <c>id</c>.</value>
public abstract bool HasIdentifierProperty { get; }
/// <summary>
/// When implemented by a class, gets or sets the <see cref="Property"/>
/// that is used as the <c>id</c>.
/// </summary>
/// <value>
/// The <see cref="Property"/> that is used as the <c>id</c>.
/// </value>
public abstract Property IdentifierProperty { get; set; }
/// <summary>
/// When implemented by a class, gets or sets the <see cref="SimpleValue"/>
/// that contains information about the identifier.
/// </summary>
/// <value>The <see cref="SimpleValue"/> that contains information about the identifier.</value>
public abstract IKeyValue Identifier { get; set; }
/// <summary>
/// When implemented by a class, gets or sets the <see cref="Property"/>
/// that is used as the version.
/// </summary>
/// <value>The <see cref="Property"/> that is used as the version.</value>
public abstract Property Version { get; set; }
/// <summary>
/// When implemented by a class, gets or sets the <see cref="SimpleValue"/>
/// that contains information about the discriminator.
/// </summary>
/// <value>The <see cref="SimpleValue"/> that contains information about the discriminator.</value>
public abstract IValue Discriminator { get; set; }
/// <summary>
/// When implemented by a class, gets or sets if the mapped class has subclasses or is
/// a subclass.
/// </summary>
/// <value>
/// <see langword="true" /> if the mapped class has subclasses or is a subclass.
/// </value>
public abstract bool IsPolymorphic { get; set; }
/// <summary>
/// When implemented by a class, 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 abstract string CacheConcurrencyStrategy { get; set; }
/// <summary>
/// When implemented by a class, 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 abstract PersistentClass Superclass { get; set; }
/// <summary>
/// When implemented by a class, gets or sets a boolean indicating if
/// explicit polymorphism should be used in Queries.
/// </summary>
/// <value>
/// <see langword="true" /> if only classes queried on should be returned, <see langword="false" />
/// if any class in the heirarchy should implicitly be returned.</value>
/// <remarks>
/// The value of this is set by the <c>polymorphism</c> attribute.
/// </remarks>
public abstract bool IsExplicitPolymorphism { get; set; }
/// <summary>
///
/// </summary>
public abstract bool IsDiscriminatorInsertable { get; set; }
/// <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>
public virtual void AddSubclassProperty(Property p)
{
subclassProperties.Add(p);
}
public virtual void AddSubclassJoin(Join join)
{
subclassJoins.Add(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>
public virtual void AddSubclassTable(Table table)
{
subclassTables.Add(table);
}
public virtual bool IsClassOrSuperclassJoin(Join join)
{
return joins.Contains(join);
}
public virtual bool IsClassOrSuperclassTable(Table closureTable)
{
return Table == closureTable;
}
/// <summary>
/// When implemented by a class, gets or sets a boolean indicating if the identifier is
/// embedded in the class.
/// </summary>
/// <value><see langword="true" /> if the class identifies itself.</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 abstract bool HasEmbeddedIdentifier { get; set; }
/// <summary>
/// When implemented by a class, gets the <see cref="Mapping.RootClass"/> of the class
/// that is mapped in the <c>class</c> element.
/// </summary>
/// <value>
/// The <see cref="Mapping.RootClass"/> of the class that is mapped in the <c>class</c> element.
/// </value>
public abstract RootClass RootClazz { get; }
/// <summary>
/// When implemented by a class, 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 abstract IKeyValue Key { get; set; }
/// <summary>
/// Creates the <see cref="PrimaryKey"/> for the <see cref="Table"/>
/// this type is persisted in.
/// </summary>
/// <param name="dialect">The <see cref="Dialect.Dialect"/> that is used to Alias columns.</param>
//Since v5.2
[Obsolete("Please use overload without delegate parameter")]
public virtual void CreatePrimaryKey(Dialect.Dialect dialect)
{
//Primary key constraint
PrimaryKey pk = new PrimaryKey();
Table table = Table;
pk.Table = table;
pk.Name = PKAlias.ToAliasString(table.Name);
table.PrimaryKey = pk;
pk.AddColumns(Key.ColumnIterator);
}
/// <summary>
/// Creates the <see cref="PrimaryKey"/> for the <see cref="Table"/>
/// this type is persisted in.
/// </summary>
public virtual void CreatePrimaryKey()
{
//6.0 TODO: Inline the following method call and remove the obsolete method.
#pragma warning disable 618
CreatePrimaryKey(null);
#pragma warning restore 618
}
/// <summary>
/// When implemented by a class, gets or sets 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>
/// <remarks>
/// The value of this is set by the <c>where</c> attribute.
/// </remarks>
public abstract string Where { get; set; }
/// <summary>
/// Given a property path, locate the appropriate referenceable property reference.
/// </summary>
/// <remarks>
/// A referenceable property is a property which can be a target of a foreign-key
/// mapping (an identifier or explicitly named in a property-ref).
/// </remarks>
/// <param name="propertyPath">The property path to resolve into a property reference.</param>
/// <returns>The property reference (never null).</returns>
/// <exception cref="MappingException">If the property could not be found.</exception>
public Property GetReferencedProperty(string propertyPath)
{
try
{
return GetRecursiveProperty(propertyPath, ReferenceablePropertyIterator);
}
catch (MappingException e)
{
throw new MappingException(
"property-ref [" + propertyPath + "] not found on entity [" + EntityName + "]", e
);
}
}
public Property GetRecursiveProperty(string propertyPath)
{
try
{
return GetRecursiveProperty(propertyPath, PropertyIterator);
}
catch (MappingException e)
{
throw new MappingException("property [" + propertyPath + "] not found on entity [" + EntityName + "]", e);
}
}
private Property GetRecursiveProperty(string propertyPath, IEnumerable<Property> iter)
{
Property property = null;
StringTokenizer st = new StringTokenizer(propertyPath, ".", false);
try
{
foreach (string element in st)
{
if (property == null)
{
// we are processing the root of the propertyPath, so we have the following
// considerations:
// 1) specifically account for identifier properties
// 2) specifically account for embedded composite-identifiers
// 3) perform a normal property lookup
Property identifierProperty = IdentifierProperty;
if (identifierProperty != null && identifierProperty.Name.Equals(element))
{
// we have a mapped identifier property and the root of
// the incoming property path matched that identifier
// property
property = identifierProperty;
}
else if (identifierProperty == null)
{
var component = Identifier as Component;
if (component != null)
{
// we have an embedded composite identifier
try
{
identifierProperty = GetProperty(element, component.PropertyIterator);
if (identifierProperty != null)
{
// the root of the incoming property path matched one
// of the embedded composite identifier properties
property = identifierProperty;
}
}
catch (MappingException)
{
// ignore it...
}
}
}
if (property == null)
{
property = GetProperty(element, iter);
}
}
else
{
//flat recursive algorithm
property = ((Component)property.Value).GetProperty(element);
}
}
}
catch (MappingException ex)
{
throw new MappingException("property [" + propertyPath + "] not found on entity [" + EntityName + "]", ex);
}
return property;
}
private Property GetProperty(string propertyName, IEnumerable<Property> iter)
{
var propName = StringHelper.Root(propertyName);
foreach (var prop in iter)
{
if (prop.Name.Equals(propName))
{
return prop;
}
}
throw new MappingException(string.Format("property not found: {0} on entity {1}", propertyName, EntityName));
}
public Property GetProperty(string propertyName)
{
IEnumerable<Property> iter = PropertyClosureIterator;
Property identifierProperty = IdentifierProperty;
if (identifierProperty != null && identifierProperty.Name.Equals(StringHelper.Root(propertyName)))
{
return identifierProperty;
}
else
{
return GetProperty(propertyName, iter);
}
}
public virtual Versioning.OptimisticLock OptimisticLockMode
{
get { return optimisticLockMode; }
set { optimisticLockMode = value; }
}
/// <summary>
///
/// </summary>
/// <param name="mapping"></param>
public virtual void Validate(IMapping mapping)
{
foreach (Property prop in PropertyIterator)
{
if (!prop.IsValid(mapping))
{
throw new MappingException(
string.Format("property mapping has wrong number of columns: {0} type: {1}",
StringHelper.Qualify(EntityName, prop.Name), prop.Type.Name));
}
}
CheckPropertyDuplication();
CheckColumnDuplication();
}
private void CheckPropertyDuplication()
{
var names = new HashSet<string>();
foreach (Property prop in PropertyIterator)
{
if (!names.Add(prop.Name))
throw new MappingException("Duplicate property mapping of " + prop.Name + " found in " + EntityName);
}
}
public MetaAttribute GetMetaAttribute(string attributeName)
{
if (metaAttributes == null)
return null;
MetaAttribute result;
metaAttributes.TryGetValue(attributeName, out result);
return result;
}
public override string ToString()
{
return GetType().FullName + '(' + EntityName + ')';
}
public virtual void AddJoin(Join join)
{
joins.Add(join);
join.PersistentClass = this;
}
public virtual int GetJoinNumber(Property prop)
{
int result = 1;
foreach (Join join in SubclassJoinClosureIterator)
{
if (join.ContainsProperty(prop))
return result;
result++;
}
return 0;
}
public void SetCustomSQLInsert(string sql, bool callable, ExecuteUpdateResultCheckStyle checkStyle)
{
customSQLInsert = SqlString.Parse(sql);
customInsertCallable = callable;
insertCheckStyle = checkStyle;
}
public SqlString CustomSQLInsert
{
get { return customSQLInsert; }
}
public void SetCustomSQLUpdate(string sql, bool callable, ExecuteUpdateResultCheckStyle checkStyle)