Skip to content

Commit e842cc5

Browse files
authored
Refactor sequential select related members in AbstractEntityPersister (#3373)
* Rename GetSubclassPropertyTableNumber(string propertyName, string entityName) to GetSubclassJoinPropertyTableNumber * Skip dictionary initialization logic if not required
1 parent 3875011 commit e842cc5

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/NHibernate/Persister/Entity/AbstractEntityPersister.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public virtual void BindValues(DbCommand ps)
263263

264264
// This must be a Lazy<T>, because instances of this class must be thread safe.
265265
private readonly Lazy<string[]> defaultUniqueKeyPropertyNamesForSelectId;
266-
private readonly Dictionary<string, int> propertyTableNumbersByNameAndSubclass = new Dictionary<string, int>();
266+
private readonly Dictionary<string, int> propertySubclassJoinTableNumbersByName;
267267

268268
protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
269269
ISessionFactoryImplementor factory)
@@ -441,6 +441,17 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
441441
List<bool> columnSelectables = new List<bool>();
442442
List<bool> propNullables = new List<bool>();
443443

444+
if (persistentClass.SubclassJoinClosureIterator.Any())
445+
{
446+
propertySubclassJoinTableNumbersByName = new Dictionary<string, int>();
447+
foreach (Property prop in persistentClass.SubclassPropertyClosureIterator)
448+
{
449+
var joinNumber = persistentClass.GetJoinNumber(prop);
450+
if (joinNumber != 0)
451+
propertySubclassJoinTableNumbersByName[prop.PersistentClass.EntityName + '.' + prop.Name] = joinNumber;
452+
}
453+
}
454+
444455
foreach (Property prop in persistentClass.SubclassPropertyClosureIterator)
445456
{
446457
names.Add(prop.Name);
@@ -449,8 +460,6 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
449460
definedBySubclass.Add(isDefinedBySubclass);
450461
propNullables.Add(prop.IsOptional || isDefinedBySubclass); //TODO: is this completely correct?
451462
types.Add(prop.Type);
452-
propertyTableNumbersByNameAndSubclass[prop.PersistentClass.EntityName + '.' + prop.Name] =
453-
persistentClass.GetJoinNumber(prop);
454463

455464
string[] cols = new string[prop.ColumnSpan];
456465
string[] forms = new string[prop.ColumnSpan];
@@ -1125,12 +1134,15 @@ protected virtual bool IsIdOfTable(int property, int table)
11251134

11261135
protected abstract int GetSubclassPropertyTableNumber(int i);
11271136

1128-
internal int GetSubclassPropertyTableNumber(string propertyName, string entityName)
1137+
internal int GetSubclassJoinPropertyTableNumber(string propertyName, string entityName)
11291138
{
1139+
if (propertySubclassJoinTableNumbersByName == null)
1140+
return 0;
1141+
11301142
var type = propertyMapping.ToType(propertyName);
11311143
if (type.IsAssociationType && ((IAssociationType) type).UseLHSPrimaryKey)
11321144
return 0;
1133-
propertyTableNumbersByNameAndSubclass.TryGetValue(entityName + '.' + propertyName, out var tabnum);
1145+
propertySubclassJoinTableNumbersByName.TryGetValue(entityName + '.' + propertyName, out var tabnum);
11341146
return tabnum;
11351147
}
11361148

@@ -4878,7 +4890,7 @@ internal SqlString GenerateSequentialSelect(AbstractEntityPersister subclassPers
48784890
var classes = subclassPersister.PropertySubclassNames;
48794891
for (var i = 0; i < props.Length; i++)
48804892
{
4881-
var propTableNumber = GetSubclassPropertyTableNumber(props[i], classes[i]);
4893+
var propTableNumber = GetSubclassJoinPropertyTableNumber(props[i], classes[i]);
48824894
if (IsSubclassTableSequentialSelect(propTableNumber) && !IsSubclassTableLazy(propTableNumber))
48834895
{
48844896
tableNumbers.Add(propTableNumber);

src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ protected override void AddDiscriminatorToInsert(SqlInsertBuilder insert)
696696
protected override bool IsSubclassPropertyDeferred(string propertyName, string entityName)
697697
{
698698
return
699-
hasSequentialSelects && IsSubclassTableSequentialSelect(base.GetSubclassPropertyTableNumber(propertyName, entityName));
699+
hasSequentialSelects && IsSubclassTableSequentialSelect(GetSubclassPropertyTableNumber(propertyName, entityName));
700700
}
701701

702702
protected override bool IsPropertyDeferred(int propertyIndex)
@@ -713,9 +713,9 @@ public override bool HasSequentialSelect
713713

714714
//Since v5.3
715715
[Obsolete("This method has no more usage in NHibernate and will be removed in a future version.")]
716-
public new int GetSubclassPropertyTableNumber(string propertyName, string entityName)
716+
public int GetSubclassPropertyTableNumber(string propertyName, string entityName)
717717
{
718-
return base.GetSubclassPropertyTableNumber(propertyName, entityName);
718+
return GetSubclassJoinPropertyTableNumber(propertyName, entityName);
719719
}
720720

721721
//Since v5.3

0 commit comments

Comments
 (0)