Skip to content

Provide cacheable representations for all NHibernate built-in types #1765

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 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
62 changes: 62 additions & 0 deletions src/NHibernate.Test/CacheTest/TypeFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Globalization;
using System.Xml;
using System.Xml.Linq;
using NHibernate.Engine;
using NHibernate.Type;
using NSubstitute;
using NUnit.Framework;

namespace NHibernate.Test.CacheTest
{
[TestFixture]
public class TypeFixture
{
[Test]
public void CultureInfo()
{
DoTestType(NHibernateUtil.CultureInfo, new CultureInfo("en-US"));
}

[Test]
public void Type()
{
DoTestType(TypeFactory.GetTypeType(100), typeof(TypeFixture));
}

[Test]
public void Uri()
{
DoTestType(NHibernateUtil.Uri, new Uri("http://nhibernate.info/", UriKind.RelativeOrAbsolute));
}

[Test]
public void XDoc()
{
DoTestType(NHibernateUtil.XDoc, XDocument.Parse(@"<?xml version=""1.0"" encoding=""utf-8""?>
<hibernate-configuration>
</hibernate-configuration>"));
}

[Test]
public void XmlDoc()
{
var doc = new XmlDocument();
doc.LoadXml(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<hibernate-configuration>
</hibernate-configuration>");
DoTestType(NHibernateUtil.XmlDoc, doc);
}

private void DoTestType(IType type, object value)
{
var session = Substitute.For<ISessionImplementor>();
var cached = type.Disassemble(value, session, null);
// All NHibernate types should yield a cacheable representation that are at least binary serializable
NHAssert.IsSerializable(cached);
var reassembled = type.Assemble(cached, session, null);
Assert.That(type.IsEqual(reassembled, value), Is.True);
}
}
}
59 changes: 59 additions & 0 deletions src/NHibernate/Async/Type/CultureInfoType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Data;
using System.Data.Common;
using System.Globalization;
using NHibernate.Engine;
using NHibernate.SqlTypes;

namespace NHibernate.Type
{
using System.Threading.Tasks;
using System.Threading;
public partial class CultureInfoType : ImmutableType, ILiteralType
{

/// <inheritdoc />
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Assemble(cached, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}

/// <inheritdoc />
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Disassemble(value, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
}
59 changes: 59 additions & 0 deletions src/NHibernate/Async/Type/TypeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Data;
using System.Data.Common;
using NHibernate.Engine;
using NHibernate.SqlTypes;
using NHibernate.Util;

namespace NHibernate.Type
{
using System.Threading.Tasks;
using System.Threading;
public partial class TypeType : ImmutableType
{

/// <inheritdoc />
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Assemble(cached, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}

/// <inheritdoc />
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Disassemble(value, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
}
57 changes: 57 additions & 0 deletions src/NHibernate/Async/Type/UriType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Data.Common;
using NHibernate.Engine;
using NHibernate.SqlTypes;

namespace NHibernate.Type
{
using System.Threading.Tasks;
using System.Threading;
public partial class UriType : ImmutableType, IDiscriminatorType
{

/// <inheritdoc />
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Assemble(cached, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}

/// <inheritdoc />
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Disassemble(value, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
}
58 changes: 58 additions & 0 deletions src/NHibernate/Async/Type/XDocType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Data.Common;
using System.Xml.Linq;
using NHibernate.Engine;
using NHibernate.SqlTypes;

namespace NHibernate.Type
{
using System.Threading.Tasks;
using System.Threading;
public partial class XDocType : MutableType
{

/// <inheritdoc />
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Assemble(cached, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}

/// <inheritdoc />
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Disassemble(value, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
}
58 changes: 58 additions & 0 deletions src/NHibernate/Async/Type/XmlDocType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Data.Common;
using System.Xml;
using NHibernate.Engine;
using NHibernate.SqlTypes;

namespace NHibernate.Type
{
using System.Threading.Tasks;
using System.Threading;
public partial class XmlDocType : MutableType
{

/// <inheritdoc />
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Assemble(cached, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}

/// <inheritdoc />
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return Task.FromResult<object>(Disassemble(value, session, owner));
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
}
Loading