Skip to content

Support an arbitrary length for CultureInfoType #3481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/NHibernate.DomainModel/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public CultureInfo Locale
set { _locale = value; }
}

public CultureInfo ExtendedLocale { get; set; }

#region System.Object Members

public override bool Equals(object obj)
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate.DomainModel/Location.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/>
</composite-id>
<property name="Locale" />
<property name="ExtendedLocale" length="11" />
<property name="Description" />
</class>
</hibernate-mapping>
</hibernate-mapping>
2 changes: 2 additions & 0 deletions src/NHibernate.Test/Async/Legacy/FooBarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5162,6 +5162,7 @@ public async Task EmbeddedCompositeIDAsync()
l.CountryCode = "AU";
l.Description = "foo bar";
l.Locale = CultureInfo.CreateSpecificCulture("en-AU");
l.ExtendedLocale = CultureInfo.CreateSpecificCulture("en-US-POSIX");
l.StreetName = "Brunswick Rd";
l.StreetNumber = 300;
l.City = "Melbourne";
Expand All @@ -5177,6 +5178,7 @@ public async Task EmbeddedCompositeIDAsync()
Assert.AreEqual("AU", l.CountryCode);
Assert.AreEqual("Melbourne", l.City);
Assert.AreEqual(CultureInfo.CreateSpecificCulture("en-AU"), l.Locale);
Assert.That(l.ExtendedLocale, Is.EqualTo(CultureInfo.CreateSpecificCulture("en-US-POSIX")));
s.Close();

s = OpenSession();
Expand Down
2 changes: 2 additions & 0 deletions src/NHibernate.Test/Legacy/FooBarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5150,6 +5150,7 @@ public void EmbeddedCompositeID()
l.CountryCode = "AU";
l.Description = "foo bar";
l.Locale = CultureInfo.CreateSpecificCulture("en-AU");
l.ExtendedLocale = CultureInfo.CreateSpecificCulture("en-US-POSIX");
l.StreetName = "Brunswick Rd";
l.StreetNumber = 300;
l.City = "Melbourne";
Expand All @@ -5165,6 +5166,7 @@ public void EmbeddedCompositeID()
Assert.AreEqual("AU", l.CountryCode);
Assert.AreEqual("Melbourne", l.City);
Assert.AreEqual(CultureInfo.CreateSpecificCulture("en-AU"), l.Locale);
Assert.That(l.ExtendedLocale, Is.EqualTo(CultureInfo.CreateSpecificCulture("en-US-POSIX")));
s.Close();

s = OpenSession();
Expand Down
8 changes: 6 additions & 2 deletions src/NHibernate/Type/CultureInfoType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
namespace NHibernate.Type
{
/// <summary>
/// Maps a <see cref="System.Globalization.CultureInfo"/> Property
/// Maps a <see cref="CultureInfo"/> Property
/// to a <see cref="DbType.String"/> column.
/// </summary>
/// <remarks>
/// CultureInfoType stores the culture name (not the Culture ID) of the
/// <see cref="System.Globalization.CultureInfo"/> in the DB.
/// <see cref="CultureInfo"/> in the DB.
/// </remarks>
[Serializable]
public partial class CultureInfoType : ImmutableType, ILiteralType
Expand All @@ -22,6 +22,10 @@ internal CultureInfoType() : base(new StringSqlType(5))
{
}

internal CultureInfoType(StringSqlType sqlType) : base(sqlType)
{
}

/// <inheritdoc />
public override object Get(DbDataReader rs, int index, ISessionImplementor session)
{
Expand Down
9 changes: 5 additions & 4 deletions src/NHibernate/Type/TypeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ private static void RegisterDefaultNetTypes()
RegisterType(typeof (Boolean), NHibernateUtil.Boolean, new[] { "boolean", "bool" });
RegisterType(typeof (Byte), NHibernateUtil.Byte, new[]{ "byte"});
RegisterType(typeof (Char), NHibernateUtil.Character, new[] {"character", "char"});
RegisterType(typeof (CultureInfo), NHibernateUtil.CultureInfo, new[]{ "locale"});
RegisterType(typeof (CultureInfo), NHibernateUtil.CultureInfo, new[] { "locale" },
l => GetType(NHibernateUtil.CultureInfo, l, len => new CultureInfoType(SqlTypeFactory.GetString(len))),
false);
RegisterType(typeof (DateTime), NHibernateUtil.DateTime, new[] { "datetime" },
s => GetType(NHibernateUtil.DateTime, s, scale => new DateTimeType(SqlTypeFactory.GetDateTime((byte)scale))),
false);
Expand Down Expand Up @@ -344,11 +346,10 @@ private static void RegisterDefaultNetTypes()
}

/// <summary>
/// Register other NO Default .NET type
/// Register types which are not a default for a .NET type.
/// </summary>
/// <remarks>
/// These type will be used only when the "type" attribute was is specified in the mapping.
/// These are in here because needed to NO override default CLR types and be available in mappings
/// These types will be used only when the "type" attribute is specified in the mapping.
/// </remarks>
private static void RegisterBuiltInTypes()
{
Expand Down