-
Notifications
You must be signed in to change notification settings - Fork 922
/
SingleTableEntityPersister.cs
796 lines (681 loc) · 25 KB
/
SingleTableEntityPersister.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using NHibernate.Cache;
using NHibernate.Engine;
using NHibernate.Mapping;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NHibernate.Util;
namespace NHibernate.Persister.Entity
{
/// <summary>
/// Default implementation of the <c>ClassPersister</c> interface. Implements the
/// "table-per-class hierarchy" mapping strategy for an entity class.
/// </summary>
public class SingleTableEntityPersister : AbstractEntityPersister, IQueryable
{
// the class hierarchy structure
private readonly int joinSpan;
private IType[] identifierTypes;
private readonly string[] qualifiedTableNames;
private readonly bool[] isInverseTable;
private readonly bool[] isNullableTable;
private readonly string[][] keyColumnNames;
private readonly bool[] cascadeDeleteEnabled;
private readonly bool hasSequentialSelects; // TODO 6.0: Remove
private readonly bool _hasSequentialSelect;
private readonly string[] spaces;
private readonly string[] subclassClosure;
private readonly string[] subclassTableNameClosure;
private readonly bool[] subclassTableIsLazyClosure;
private readonly bool[] isInverseSubclassTable;
private readonly bool[] isNullableSubclassTable;
private readonly bool[] subclassTableSequentialSelect;
private readonly string[][] subclassTableKeyColumnClosure;
private readonly bool[] isClassOrSuperclassTable;
// properties of this class, including inherited properties
private readonly int[] propertyTableNumbers;
// if the id is a property of the base table eg join to property-ref
// if the id is not a property the value will be null
private readonly Dictionary<int, int> tableIdPropertyNumbers;
// the closure of all columns used by the entire hierarchy including
// subclasses and superclasses of this class
private readonly int[] subclassPropertyTableNumberClosure;
private readonly int[] subclassColumnTableNumberClosure;
private readonly int[] subclassFormulaTableNumberClosure;
// discriminator column
private readonly Dictionary<object, string> subclassesByDiscriminatorValue = new Dictionary<object, string>();
private readonly bool forceDiscriminator;
private readonly string discriminatorColumnName;
private readonly string discriminatorFormula;
private readonly string discriminatorFormulaTemplate;
private readonly string discriminatorAlias;
private readonly IType discriminatorType;
private readonly string discriminatorSQLValue;
private readonly object discriminatorValue;
private readonly bool discriminatorInsertable;
private readonly string[] constraintOrderedTableNames;
private readonly string[][] constraintOrderedKeyColumnNames;
//private readonly IDictionary propertyTableNumbersByName = new Hashtable();
private SqlString _sequentialSelectString;
private static readonly object NullDiscriminator = new object();
private static readonly object NotNullDiscriminator = new object();
//provided so we can join to keys other than the primary key
private readonly Dictionary<int, string[]> joinToKeyColumns;
public SingleTableEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory, IMapping mapping)
: base(persistentClass, cache, factory)
{
#region CLASS + TABLE
joinSpan = persistentClass.JoinClosureSpan + 1;
identifierTypes = new IType[joinSpan];
qualifiedTableNames = new string[joinSpan];
isInverseTable = new bool[joinSpan];
isNullableTable = new bool[joinSpan];
keyColumnNames = new string[joinSpan][];
Table table = persistentClass.RootTable;
identifierTypes[0] = IdentifierType;
qualifiedTableNames[0] =table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
isInverseTable[0] = false;
isNullableTable[0] = false;
keyColumnNames[0] = IdentifierColumnNames;
cascadeDeleteEnabled = new bool[joinSpan];
// Custom sql
customSQLInsert = new SqlString[joinSpan];
customSQLUpdate = new SqlString[joinSpan];
customSQLDelete = new SqlString[joinSpan];
insertCallable = new bool[joinSpan];
updateCallable = new bool[joinSpan];
deleteCallable = new bool[joinSpan];
insertResultCheckStyles = new ExecuteUpdateResultCheckStyle[joinSpan];
updateResultCheckStyles = new ExecuteUpdateResultCheckStyle[joinSpan];
deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[joinSpan];
customSQLInsert[0] = persistentClass.CustomSQLInsert;
insertCallable[0] = customSQLInsert[0] != null && persistentClass.IsCustomInsertCallable;
insertResultCheckStyles[0] = persistentClass.CustomSQLInsertCheckStyle
?? ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLInsert[0], insertCallable[0]);
customSQLUpdate[0] = persistentClass.CustomSQLUpdate;
updateCallable[0] = customSQLUpdate[0] != null && persistentClass.IsCustomUpdateCallable;
updateResultCheckStyles[0] = persistentClass.CustomSQLUpdateCheckStyle
?? ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLUpdate[0], updateCallable[0]);
customSQLDelete[0] = persistentClass.CustomSQLDelete;
deleteCallable[0] = customSQLDelete[0] != null && persistentClass.IsCustomDeleteCallable;
deleteResultCheckStyles[0] = persistentClass.CustomSQLDeleteCheckStyle
?? ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLDelete[0], deleteCallable[0]);
#endregion
#region JOINS
int j = 1;
foreach (Join join in persistentClass.JoinClosureIterator)
{
identifierTypes[j] = join.Key.Type;
qualifiedTableNames[j] = join.Table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
isInverseTable[j] = join.IsInverse;
isNullableTable[j] = join.IsOptional;
cascadeDeleteEnabled[j] = join.Key.IsCascadeDeleteEnabled && factory.Dialect.SupportsCascadeDelete;
customSQLInsert[j] = join.CustomSQLInsert;
insertCallable[j] = customSQLInsert[j] != null && join.IsCustomInsertCallable;
insertResultCheckStyles[j] = join.CustomSQLInsertCheckStyle
??
ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLInsert[j], insertCallable[j]);
customSQLUpdate[j] = join.CustomSQLUpdate;
updateCallable[j] = customSQLUpdate[j] != null && join.IsCustomUpdateCallable;
updateResultCheckStyles[j] = join.CustomSQLUpdateCheckStyle
??
ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLUpdate[j], updateCallable[j]);
customSQLDelete[j] = join.CustomSQLDelete;
deleteCallable[j] = customSQLDelete[j] != null && join.IsCustomDeleteCallable;
deleteResultCheckStyles[j] = join.CustomSQLDeleteCheckStyle
??
ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLDelete[j], deleteCallable[j]);
keyColumnNames[j] = join.Key.ColumnIterator.OfType<Column>().Select(col => col.GetQuotedName(factory.Dialect)).ToArray();
j++;
}
constraintOrderedTableNames = new string[qualifiedTableNames.Length];
constraintOrderedKeyColumnNames = new string[qualifiedTableNames.Length][];
for (int i = qualifiedTableNames.Length - 1, position = 0; i >= 0; i--, position++)
{
constraintOrderedTableNames[position] = qualifiedTableNames[i];
constraintOrderedKeyColumnNames[position] = keyColumnNames[i];
}
spaces = qualifiedTableNames.Concat(persistentClass.SynchronizedTables).ToArray();
bool lazyAvailable = IsInstrumented;
bool hasDeferred = false; // TODO 6.0: Remove
List<string> subclassTables = new List<string>();
List<string[]> joinKeyColumns = new List<string[]>();
//provided so we can join to keys other than the primary key
joinToKeyColumns = new Dictionary<int, string[]>();
//Columns that also function as Id's
List<Column> idColumns = new List<Column>();
tableIdPropertyNumbers = new Dictionary<int, int>();
List<bool> isConcretes = new List<bool>();
List<bool> isDeferreds = new List<bool>();
List<bool> isInverses = new List<bool>();
List<bool> isNullables = new List<bool>();
List<bool> isLazies = new List<bool>();
subclassTables.Add(qualifiedTableNames[0]);
joinKeyColumns.Add(IdentifierColumnNames);
isConcretes.Add(true);
isDeferreds.Add(false);
isInverses.Add(false);
isNullables.Add(false);
isLazies.Add(false);
foreach (Join join in persistentClass.SubclassJoinClosureIterator)
{
isConcretes.Add(persistentClass.IsClassOrSuperclassJoin(join));
isDeferreds.Add(join.IsSequentialSelect);
isInverses.Add(join.IsInverse);
isNullables.Add(join.IsOptional);
isLazies.Add(lazyAvailable && join.IsLazy);
if (join.IsSequentialSelect)
_hasSequentialSelect = true;
if (join.IsSequentialSelect && !persistentClass.IsClassOrSuperclassJoin(join))
hasDeferred = true;
subclassTables.Add(join.Table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName));
var keyCols = join.Key.ColumnIterator.OfType<Column>().Select(col => col.GetQuotedName(factory.Dialect)).ToArray();
joinKeyColumns.Add(keyCols);
//are we joining to other than the primary key?
if (join.RefIdProperty != null)
{
var curTableIndex = joinKeyColumns.Count - 1;
//there should only ever be one key
var toKeyCols = new List<string>(join.RefIdProperty.ColumnSpan);
foreach (Column col in join.RefIdProperty.ColumnIterator)
{
toKeyCols.Add(col.GetQuotedName(factory.Dialect));
//find out what property index this is
int i = 0;
foreach (var prop in persistentClass.PropertyClosureIterator)
{
if (prop == @join.RefIdProperty)
{
tableIdPropertyNumbers.Add(curTableIndex, i);
break;
}
i++;
}
idColumns.Add(col);
}
joinToKeyColumns.Add(curTableIndex, toKeyCols.ToArray());
}
}
subclassTableSequentialSelect = isDeferreds.ToArray();
subclassTableNameClosure = subclassTables.ToArray();
subclassTableIsLazyClosure = isLazies.ToArray();
subclassTableKeyColumnClosure = joinKeyColumns.ToArray();
isClassOrSuperclassTable = isConcretes.ToArray();
isInverseSubclassTable = isInverses.ToArray();
isNullableSubclassTable = isNullables.ToArray();
hasSequentialSelects = hasDeferred;
#endregion
#region DISCRIMINATOR
if (persistentClass.IsPolymorphic)
{
IValue discrimValue = persistentClass.Discriminator;
if (discrimValue == null)
throw new MappingException("Discriminator mapping required for single table polymorphic persistence");
forceDiscriminator = persistentClass.IsForceDiscriminator;
var selectable = discrimValue.ColumnIterator.First();
if (discrimValue.HasFormula)
{
Formula formula = (Formula)selectable;
discriminatorFormula = formula.FormulaString;
discriminatorFormulaTemplate = formula.GetTemplate(factory.Dialect, factory.SQLFunctionRegistry);
discriminatorColumnName = null;
discriminatorAlias = Discriminator_Alias;
}
else
{
Column column = (Column)selectable;
discriminatorColumnName = column.GetQuotedName(factory.Dialect);
discriminatorAlias = column.GetAlias(factory.Dialect, persistentClass.RootTable);
discriminatorFormula = null;
discriminatorFormulaTemplate = null;
}
discriminatorType = persistentClass.Discriminator.Type;
if (persistentClass.IsDiscriminatorValueNull)
{
discriminatorValue = NullDiscriminator;
discriminatorSQLValue = InFragment.Null;
discriminatorInsertable = false;
}
else if (persistentClass.IsDiscriminatorValueNotNull)
{
discriminatorValue = NotNullDiscriminator;
discriminatorSQLValue = InFragment.NotNull;
discriminatorInsertable = false;
}
else
{
discriminatorInsertable = persistentClass.IsDiscriminatorInsertable && !discrimValue.HasFormula;
try
{
IDiscriminatorType dtype = (IDiscriminatorType)discriminatorType;
discriminatorValue = dtype.StringToObject(persistentClass.DiscriminatorValue);
discriminatorSQLValue = dtype.ObjectToSQLString(discriminatorValue, factory.Dialect);
}
catch (InvalidCastException cce)
{
throw new MappingException(
string.Format("Illegal discriminator type: {0} of entity {1}", discriminatorType.Name, persistentClass.EntityName), cce);
}
catch (Exception e)
{
throw new MappingException("Could not format discriminator value to SQL string of entity " + persistentClass.EntityName, e);
}
}
}
else
{
forceDiscriminator = false;
discriminatorInsertable = false;
discriminatorColumnName = null;
discriminatorAlias = null;
discriminatorType = null;
discriminatorValue = null;
discriminatorSQLValue = null;
discriminatorFormula = null;
discriminatorFormulaTemplate = null;
}
#endregion
#region PROPERTIES
propertyTableNumbers = new int[PropertySpan];
int i2 = 0;
foreach (Property prop in persistentClass.PropertyClosureIterator)
{
propertyTableNumbers[i2++] = persistentClass.GetJoinNumber(prop);
}
List<int> columnJoinNumbers = new List<int>();
List<int> formulaJoinedNumbers = new List<int>();
List<int> propertyJoinNumbers = new List<int>();
foreach (Property prop in persistentClass.SubclassPropertyClosureIterator)
{
int join = persistentClass.GetJoinNumber(prop);
propertyJoinNumbers.Add(join);
foreach (ISelectable thing in prop.ColumnIterator)
{
if (thing.IsFormula)
formulaJoinedNumbers.Add(join);
else
columnJoinNumbers.Add(join);
}
}
subclassColumnTableNumberClosure = columnJoinNumbers.ToArray();
subclassFormulaTableNumberClosure = formulaJoinedNumbers.ToArray();
subclassPropertyTableNumberClosure = propertyJoinNumbers.ToArray();
int subclassSpan = persistentClass.SubclassSpan + 1;
subclassClosure = new string[subclassSpan];
subclassClosure[0] = EntityName;
if (persistentClass.IsPolymorphic)
subclassesByDiscriminatorValue[discriminatorValue] = EntityName;
#endregion
#region SUBCLASSES
if (persistentClass.IsPolymorphic)
{
int k = 1;
foreach (Subclass sc in persistentClass.SubclassIterator)
{
subclassClosure[k++] = sc.EntityName;
if (sc.IsDiscriminatorValueNull)
{
subclassesByDiscriminatorValue[NullDiscriminator] = sc.EntityName;
}
else if (sc.IsDiscriminatorValueNotNull)
{
subclassesByDiscriminatorValue[NotNullDiscriminator] = sc.EntityName;
}
else
{
if (discriminatorType == null)
throw new MappingException("Not available discriminator type of entity " + persistentClass.EntityName);
try
{
IDiscriminatorType dtype = (IDiscriminatorType)discriminatorType;
subclassesByDiscriminatorValue[dtype.StringToObject(sc.DiscriminatorValue)] = sc.EntityName;
}
catch (InvalidCastException cce)
{
throw new MappingException(
string.Format("Illegal discriminator type: {0} of entity {1}", discriminatorType.Name, persistentClass.EntityName), cce);
}
catch (Exception e)
{
throw new MappingException("Error parsing discriminator value of entity " + persistentClass.EntityName, e);
}
}
}
}
#endregion
InitLockers();
InitSubclassPropertyAliasesMap(persistentClass);
PostConstruct(mapping);
}
public override string DiscriminatorColumnName
{
get { return discriminatorColumnName; }
}
protected override string DiscriminatorFormulaTemplate
{
get { return discriminatorFormulaTemplate; }
}
public override IType DiscriminatorType
{
get { return discriminatorType; }
}
public override string DiscriminatorSQLValue
{
get { return discriminatorSQLValue; }
}
public override object DiscriminatorValue
{
get { return discriminatorValue; }
}
public override string[] SubclassClosure
{
get { return subclassClosure; }
}
public override string[] PropertySpaces
{
get { return spaces; }
}
protected internal override int[] PropertyTableNumbersInSelect
{
get { return propertyTableNumbers; }
}
protected override int[] SubclassColumnTableNumberClosure
{
get { return subclassColumnTableNumberClosure; }
}
protected override int[] SubclassFormulaTableNumberClosure
{
get { return subclassFormulaTableNumberClosure; }
}
protected internal override int[] PropertyTableNumbers
{
get { return propertyTableNumbers; }
}
public override bool IsMultiTable
{
get { return TableSpan > 1; }
}
public override string[] ConstraintOrderedTableNameClosure
{
get { return constraintOrderedTableNames; }
}
public override IType GetIdentifierType(int j)
{
return identifierTypes[j];
}
public override string[][] ConstraintOrderedTableKeyColumnClosure
{
get { return constraintOrderedKeyColumnNames; }
}
protected override bool IsInverseTable(int j)
{
return isInverseTable[j];
}
protected override bool IsInverseSubclassTable(int j)
{
return isInverseSubclassTable[j];
}
protected internal override string DiscriminatorAlias
{
get { return discriminatorAlias; }
}
public override string TableName
{
get { return qualifiedTableNames[0]; }
}
public override string GetSubclassForDiscriminatorValue(object value)
{
string result;
if (value == null)
{
subclassesByDiscriminatorValue.TryGetValue(NullDiscriminator, out result);
}
else
{
if (!subclassesByDiscriminatorValue.TryGetValue(value, out result))
subclassesByDiscriminatorValue.TryGetValue(NotNullDiscriminator, out result);
}
return result;
}
protected bool IsDiscriminatorFormula
{
get { return discriminatorColumnName == null; }
}
protected string DiscriminatorFormula
{
get { return discriminatorFormula; }
}
protected override string GetTableName(int table)
{
return qualifiedTableNames[table];
}
protected override string[] GetKeyColumns(int table)
{
return keyColumnNames[table];
}
protected override bool IsTableCascadeDeleteEnabled(int j)
{
return cascadeDeleteEnabled[j];
}
protected override object GetJoinTableId(int table, object obj)
{
//0 is the base table there is no join
if (table == 0)
return null;
//check index first for speed
var refIdColumn = GetRefIdColumnOfTable(table);
if (refIdColumn == null)
return null;
object[] fields = GetPropertyValues(obj);
return GetJoinTableId(table, refIdColumn, fields);
}
//gets the identifier for a join table if other than pk
protected override object GetJoinTableId(int table, object[] fields)
{
//0 is the base table there is no join
if (table == 0)
return null;
return GetJoinTableId(table, GetRefIdColumnOfTable(table), fields);
}
private static object GetJoinTableId(int table, int? index, object[] fields)
{
if (index == null)
return null;
return fields[index.Value];
}
//if the table's id is a reference column, returns the index of that property
//returns null if not found
protected override int? GetRefIdColumnOfTable(int table)
{
int value;
if (tableIdPropertyNumbers.TryGetValue(table, out value))
return value;
return null;
}
protected override bool IsIdOfTable(int property, int table)
{
return GetRefIdColumnOfTable(table) == property;
}
protected override bool IsPropertyOfTable(int property, int table)
{
return propertyTableNumbers[property] == table;
}
protected override bool IsSubclassTableSequentialSelect(int table)
{
return subclassTableSequentialSelect[table] && !isClassOrSuperclassTable[table];
}
public override string FromTableFragment(string name)
{
return TableName + " " + name;
}
public override string FilterFragment(string alias)
{
string result = DiscriminatorFilterFragment(alias);
if (HasWhere)
result += " and " + GetSQLWhereString(alias);
return result;
}
public override string OneToManyFilterFragment(string alias)
{
return forceDiscriminator ? DiscriminatorFilterFragment(alias) : string.Empty;
}
private string DiscriminatorFilterFragment(string alias)
{
const string abstractClassWithNoSubclassExceptionMessageTemplate =
@"The class {0} can't be instatiated and does not have mapped subclasses;
possible solutions:
- don't map the abstract class
- map its subclasses.";
if (NeedsDiscriminator)
{
InFragment frag = new InFragment();
if (IsDiscriminatorFormula)
{
frag.SetFormula(alias, DiscriminatorFormulaTemplate);
}
else
{
frag.SetColumn(alias, DiscriminatorColumnName);
}
string[] subclasses = SubclassClosure;
int validValuesForInFragment = 0;
foreach (string t in subclasses)
{
var queryable = (IQueryable) Factory.GetEntityPersister(t);
if (!queryable.IsAbstract)
{
frag.AddValue(queryable.DiscriminatorSQLValue);
validValuesForInFragment++;
}
}
if(validValuesForInFragment == 0)
{
throw new NotSupportedException(string.Format(abstractClassWithNoSubclassExceptionMessageTemplate, subclasses[0]));
}
StringBuilder buf = new StringBuilder(50).Append(" and ").Append(frag.ToFragmentString().ToString());
return buf.ToString();
}
else
{
return string.Empty;
}
}
private bool NeedsDiscriminator
{
get { return forceDiscriminator || IsInherited; }
}
public override string GetSubclassPropertyTableName(int i)
{
return subclassTableNameClosure[subclassPropertyTableNumberClosure[i]];
}
protected override void AddDiscriminatorToSelect(SelectFragment select, string name, string suffix)
{
if (IsDiscriminatorFormula)
select.AddFormula(name, DiscriminatorFormulaTemplate, DiscriminatorAlias);
else
select.AddColumn(name, DiscriminatorColumnName, DiscriminatorAlias);
}
protected override int GetSubclassPropertyTableNumber(int i)
{
return subclassPropertyTableNumberClosure[i];
}
protected override int TableSpan
{
get { return joinSpan; }
}
protected override void AddDiscriminatorToInsert(SqlInsertBuilder insert)
{
if (discriminatorInsertable)
insert.AddColumn(DiscriminatorColumnName, DiscriminatorSQLValue);
}
//Since v5.3
[Obsolete("This method has no more usage in NHibernate and will be removed in a future version.")]
protected override bool IsSubclassPropertyDeferred(string propertyName, string entityName)
{
return
hasSequentialSelects && IsSubclassTableSequentialSelect(GetSubclassPropertyTableNumber(propertyName, entityName));
}
protected override bool IsPropertyDeferred(int propertyIndex)
{
return _hasSequentialSelect && subclassTableSequentialSelect[GetSubclassPropertyTableNumber(propertyIndex)];
}
//Since v5.3
[Obsolete("This property has no more usage in NHibernate and will be removed in a future version.")]
public override bool HasSequentialSelect
{
get { return hasSequentialSelects; }
}
//Since v5.3
[Obsolete("This method has no more usage in NHibernate and will be removed in a future version.")]
public int GetSubclassPropertyTableNumber(string propertyName, string entityName)
{
return GetSubclassJoinPropertyTableNumber(propertyName, entityName);
}
//Since v5.3
[Obsolete("This method has no more usage in NHibernate and will be removed in a future version.")]
protected override SqlString GetSequentialSelect(string entityName)
{
var persister = Factory.GetEntityPersister(entityName) as SingleTableEntityPersister;
return persister?.GetSequentialSelect();
}
protected override SqlString GetSequentialSelect()
{
return _sequentialSelectString;
}
//provide columns to join to if the key is other than the primary key
protected override string[] GetJoinIdKeyColumns(int j)
{
string[] key;
if (joinToKeyColumns.TryGetValue(j, out key))
return key;
return base.GetJoinIdKeyColumns(j);
}
protected override string[] GetSubclassTableKeyColumns(int j)
{
return subclassTableKeyColumnClosure[j];
}
public override string GetSubclassTableName(int j)
{
return subclassTableNameClosure[j];
}
protected override int SubclassTableSpan
{
get { return subclassTableNameClosure.Length; }
}
protected override bool IsClassOrSuperclassTable(int j)
{
return isClassOrSuperclassTable[j];
}
protected internal override bool IsSubclassTableLazy(int j)
{
return subclassTableIsLazyClosure[j];
}
protected override bool IsNullableTable(int j)
{
return isNullableTable[j];
}
protected override bool IsNullableSubclassTable(int j)
{
return isNullableSubclassTable[j];
}
public override string GetPropertyTableName(string propertyName)
{
int? index = EntityMetamodel.GetPropertyIndexOrNull(propertyName);
if (!index.HasValue) return null;
return qualifiedTableNames[propertyTableNumbers[index.Value]];
}
public override void PostInstantiate()
{
base.PostInstantiate();
if (_hasSequentialSelect && !IsAbstract)
{
var rootLoadable = (AbstractEntityPersister) Factory.GetEntityPersister(RootEntityName);
_sequentialSelectString = rootLoadable.GenerateSequentialSelect(this);
}
}
}
}