Skip to content

Commit 2e56d25

Browse files
committed
Merge branch 'master' of https://github.com/nhibernate/nhibernate-core into sparse
2 parents 1acea53 + 038a4c3 commit 2e56d25

File tree

13 files changed

+35
-47
lines changed

13 files changed

+35
-47
lines changed

src/NHibernate.Test/Async/NHSpecificTest/NH2898/BinaryFormatterCache.cs

-25
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@ namespace NHibernate.Test.NHSpecificTest.NH2898
2323
public partial class BinaryFormatterCache : CacheBase
2424
{
2525

26-
public override Task<object> GetAsync(object key, CancellationToken cancellationToken)
27-
{
28-
try
29-
{
30-
var entry = _hashtable[key] as byte[];
31-
if (entry == null)
32-
return Task.FromResult<object>(null);
33-
34-
var fmt = new BinaryFormatter
35-
{
36-
#if !NETFX
37-
SurrogateSelector = new SerializationHelper.SurrogateSelector()
38-
#endif
39-
};
40-
using (var stream = new MemoryStream(entry))
41-
{
42-
return Task.FromResult<object>(fmt.Deserialize(stream));
43-
}
44-
}
45-
catch (System.Exception ex)
46-
{
47-
return Task.FromException<object>(ex);
48-
}
49-
}
50-
5126
public override Task PutAsync(object key, object value, CancellationToken cancellationToken)
5227
{
5328
try

src/NHibernate.Test/NHibernate.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<PackageReference Include="NHibernate.Caches.CoreDistributedCache.Memory" Version="5.9.0" />
6969
<PackageReference Include="NHibernate.Caches.Util.JsonSerializer" Version="5.9.0" />
7070
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.117" />
71-
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.14" />
71+
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0.2" />
7272
<PackageReference Include="NSubstitute" Version="5.1.0" />
7373
<PackageReference Include="NUnit" Version="3.14.0" />
7474
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" />

src/NHibernate/Criterion/EntityProjection.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using NHibernate.Engine;
4-
using NHibernate.Loader;
54
using NHibernate.Loader.Criteria;
65
using NHibernate.Persister.Entity;
76
using NHibernate.SqlCommand;
87
using NHibernate.Type;
8+
using NHibernate.Util;
9+
910
using IQueryable = NHibernate.Persister.Entity.IQueryable;
1011

1112
namespace NHibernate.Criterion
@@ -204,7 +205,7 @@ private void SetFields(ICriteriaQuery criteriaQuery)
204205
subcriteria,
205206
Persister.IdentifierPropertyName ?? string.Empty);
206207

207-
ColumnAliasSuffix = BasicLoader.GenerateSuffix(criteriaQuery.GetIndexForAlias());
208+
ColumnAliasSuffix = StringHelper.GenerateSuffix(criteriaQuery.GetIndexForAlias());
208209

209210
_identifierColumnAliases = Persister.GetIdentifierAliases(ColumnAliasSuffix);
210211

src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ internal string GetSuffix(FromElement fromElement)
485485
return suffix;
486486
}
487487

488-
suffix = _suffixes.Count == 0 ? string.Empty : _suffixes.Count.ToString() + '_';
488+
suffix = _suffixes.Count == 0 ? string.Empty : StringHelper.GenerateSuffix(_suffixes.Count);
489489
_suffixes.Add(fromElement, suffix);
490490

491491
return suffix;

src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ private static string GetSuffix(int size, int sequence)
532532

533533
private static string GenerateSuffix(int size, int k)
534534
{
535-
String suffix = size == 1 ? "" : k.ToString() + '_';
535+
String suffix = size == 1 ? "" : StringHelper.GenerateSuffix(k);
536536
return suffix;
537537
}
538538

src/NHibernate/Loader/BasicLoader.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ public static string[] GenerateSuffixes(int seed, int length)
9999

100100
for (int i = 0; i < length; i++)
101101
{
102-
suffixes[i] = GenerateSuffix(i + seed);
102+
suffixes[i] = StringHelper.GenerateSuffix(i + seed);
103103
}
104104

105105
return suffixes;
106106
}
107107

108108
public static string GenerateSuffix(int index)
109109
{
110-
return index.ToString() + StringHelper.Underscore;
110+
return StringHelper.GenerateSuffix(index);
111111
}
112112
}
113113
}

src/NHibernate/Mapping/Property.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public IEnumerable<ISelectable> ColumnIterator
6666
public string Name
6767
{
6868
get { return name; }
69-
set { name = value; }
69+
set { name = value == null ? null : string.Intern(value); }
7070
}
7171

7272
public bool IsComposite
@@ -122,7 +122,7 @@ public CascadeStyle CascadeStyle
122122
public string Cascade
123123
{
124124
get { return cascade; }
125-
set { cascade = value; }
125+
set { cascade = value == null ? null : string.Intern(value); }
126126
}
127127

128128
public bool IsUpdateable
@@ -168,7 +168,7 @@ public bool IsOptional
168168
public string PropertyAccessorName
169169
{
170170
get { return propertyAccessorName; }
171-
set { propertyAccessorName = value; }
171+
set { propertyAccessorName = value == null ? null : string.Intern(value); }
172172
}
173173

174174
public IGetter GetGetter(System.Type clazz)

src/NHibernate/Mapping/SimpleValue.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public IDictionary<string, string> IdentifierGeneratorProperties
6060
public string IdentifierGeneratorStrategy
6161
{
6262
get { return identifierGeneratorStrategy; }
63-
set { identifierGeneratorStrategy = value; }
63+
set { identifierGeneratorStrategy = value == null ? null : string.Intern(value); }
6464
}
6565

6666
public virtual bool IsComposite
@@ -127,7 +127,7 @@ public string TypeName
127127
if ((typeName == null && value != null) || (typeName != null && !typeName.Equals(value)))
128128
{
129129
// the property change
130-
typeName = value;
130+
typeName = value == null ? null : string.Intern(value);
131131
type = null; // invalidate type
132132
}
133133
}
@@ -353,7 +353,8 @@ public virtual void SetTypeUsingReflection(string className, string propertyName
353353
}
354354
try
355355
{
356-
typeName = ReflectHelper.ReflectedPropertyClass(className, propertyName, accesorName).AssemblyQualifiedName;
356+
var aqn = ReflectHelper.ReflectedPropertyClass(className, propertyName, accesorName).AssemblyQualifiedName;
357+
typeName = aqn == null ? null : string.Intern(aqn);
357358
}
358359
catch (HibernateException he)
359360
{
@@ -372,7 +373,8 @@ public virtual void SetTypeUsingReflection(System.Type propertyOwnerType, string
372373
}
373374
try
374375
{
375-
typeName = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName).AssemblyQualifiedName;
376+
var aqn = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName).AssemblyQualifiedName;
377+
typeName = aqn == null ? null : string.Intern(aqn);
376378
}
377379
catch (HibernateException he)
378380
{

src/NHibernate/Persister/Entity/AbstractEntityPersister.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2376,14 +2376,14 @@ protected void InitSubclassPropertyAliasesMap(PersistentClass model)
23762376
{
23772377
if (entityMetamodel.HasNonIdentifierPropertyNamedId)
23782378
{
2379-
subclassPropertyAliases[EntityPersister.EntityID + "." + idPropertyNames[i]] = new string[] { idAliases[i] };
2380-
subclassPropertyColumnNames[EntityPersister.EntityID + "." + IdentifierPropertyName + "." + idPropertyNames[i]] = new string[] { idColumnNames[i] };
2379+
subclassPropertyAliases[string.Intern(EntityPersister.EntityID + "." + idPropertyNames[i])] = new string[] { idAliases[i] };
2380+
subclassPropertyColumnNames[string.Intern(EntityPersister.EntityID + "." + IdentifierPropertyName + "." + idPropertyNames[i])] = new string[] { idColumnNames[i] };
23812381
}
23822382
// if (hasIdentifierProperty() && !ENTITY_ID.equals( getIdentifierPropertyName() ) ) {
23832383
if (HasIdentifierProperty)
23842384
{
2385-
subclassPropertyAliases[IdentifierPropertyName + "." + idPropertyNames[i]] = new string[] { idAliases[i] };
2386-
subclassPropertyColumnNames[IdentifierPropertyName + "." + idPropertyNames[i]] = new string[] { idColumnNames[i] };
2385+
subclassPropertyAliases[string.Intern(IdentifierPropertyName + "." + idPropertyNames[i])] = new string[] { idAliases[i] };
2386+
subclassPropertyColumnNames[string.Intern(IdentifierPropertyName + "." + idPropertyNames[i])] = new string[] { idColumnNames[i] };
23872387
}
23882388
else
23892389
{

src/NHibernate/Persister/Entity/AbstractPropertyMapping.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private static string ExtendPath(string path, string property)
211211
if (string.IsNullOrEmpty(path))
212212
return property;
213213

214-
return StringHelper.Qualify(path, property);
214+
return string.Intern(StringHelper.Qualify(path, property));
215215
}
216216

217217
public string[] GetColumnNames(string propertyName)

src/NHibernate/Tuple/Entity/EntityMetamodel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ private void MapIdentifierPropertyTypes(string path, IType propertyType)
449449
for (var i = 0; i < componentType.PropertyNames.Length; i++)
450450
{
451451
MapIdentifierPropertyTypes(
452-
!string.IsNullOrEmpty(path) ? $"{path}.{componentType.PropertyNames[i]}" : componentType.PropertyNames[i],
452+
!string.IsNullOrEmpty(path) ? string.Intern($"{path}.{componentType.PropertyNames[i]}") : componentType.PropertyNames[i],
453453
componentType.Subtypes[i]);
454454
}
455455
}

src/NHibernate/Type/PersistentEnumType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public class EnumType<T> : PersistentEnumType
294294
public EnumType() : base(typeof (T))
295295
{
296296
System.Type type = GetType();
297-
typeName = type.FullName + ", " + type.Assembly.GetName().Name;
297+
typeName = string.Intern(type.FullName + ", " + type.Assembly.GetName().Name);
298298
}
299299

300300
public override string Name

src/NHibernate/Util/StringHelper.cs

+10
Original file line numberDiff line numberDiff line change
@@ -871,5 +871,15 @@ public static bool IsAnyNewLine(this string str, int index, out int newLineLengt
871871
newLineLength = 0;
872872
return false;
873873
}
874+
875+
public static string GenerateSuffix(int index)
876+
{
877+
return index switch
878+
{
879+
0 => "0_",
880+
1 => "1_",
881+
_ => string.Intern(index.ToString() + Underscore)
882+
};
883+
}
874884
}
875885
}

0 commit comments

Comments
 (0)