Skip to content

Commit 27e47da

Browse files
Provide cacheable representations for all NHibernate built-in types
1 parent 5fb348c commit 27e47da

File tree

12 files changed

+498
-73
lines changed

12 files changed

+498
-73
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Xml;
4+
using System.Xml.Linq;
5+
using NHibernate.Engine;
6+
using NHibernate.Type;
7+
using NSubstitute;
8+
using NUnit.Framework;
9+
10+
namespace NHibernate.Test.CacheTest
11+
{
12+
[TestFixture]
13+
public class TypeFixture
14+
{
15+
[Test]
16+
public void CultureInfo()
17+
{
18+
DoTestType(NHibernateUtil.CultureInfo, new CultureInfo("en-US"));
19+
}
20+
21+
[Test]
22+
public void Type()
23+
{
24+
DoTestType(TypeFactory.GetTypeType(100), typeof(TypeFixture));
25+
}
26+
27+
[Test]
28+
public void Uri()
29+
{
30+
DoTestType(NHibernateUtil.Uri, new Uri("http://nhibernate.info/", UriKind.RelativeOrAbsolute));
31+
}
32+
33+
[Test]
34+
public void XDoc()
35+
{
36+
DoTestType(NHibernateUtil.XDoc, XDocument.Parse(@"<?xml version=""1.0"" encoding=""utf-8""?>
37+
<hibernate-configuration>
38+
</hibernate-configuration>"));
39+
}
40+
41+
[Test]
42+
public void XmlDoc()
43+
{
44+
var doc = new XmlDocument();
45+
doc.LoadXml(
46+
@"<?xml version=""1.0"" encoding=""utf-8""?>
47+
<hibernate-configuration>
48+
</hibernate-configuration>");
49+
DoTestType(NHibernateUtil.XmlDoc, doc);
50+
}
51+
52+
private void DoTestType(IType type, object value)
53+
{
54+
var session = Substitute.For<ISessionImplementor>();
55+
var cached = type.Disassemble(value, session, null);
56+
// All NHibernate types should yield a cacheable representation that are at least binary serializable
57+
NHAssert.IsSerializable(cached);
58+
var reassembled = type.Assemble(cached, session, null);
59+
Assert.That(type.IsEqual(reassembled, value), Is.True);
60+
}
61+
}
62+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data;
13+
using System.Data.Common;
14+
using System.Globalization;
15+
using NHibernate.Engine;
16+
using NHibernate.SqlTypes;
17+
18+
namespace NHibernate.Type
19+
{
20+
using System.Threading.Tasks;
21+
using System.Threading;
22+
public partial class CultureInfoType : ImmutableType, ILiteralType
23+
{
24+
25+
/// <inheritdoc />
26+
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
27+
{
28+
if (cancellationToken.IsCancellationRequested)
29+
{
30+
return Task.FromCanceled<object>(cancellationToken);
31+
}
32+
try
33+
{
34+
return Task.FromResult<object>(Assemble(cached, session, owner));
35+
}
36+
catch (Exception ex)
37+
{
38+
return Task.FromException<object>(ex);
39+
}
40+
}
41+
42+
/// <inheritdoc />
43+
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
44+
{
45+
if (cancellationToken.IsCancellationRequested)
46+
{
47+
return Task.FromCanceled<object>(cancellationToken);
48+
}
49+
try
50+
{
51+
return Task.FromResult<object>(Disassemble(value, session, owner));
52+
}
53+
catch (Exception ex)
54+
{
55+
return Task.FromException<object>(ex);
56+
}
57+
}
58+
}
59+
}

src/NHibernate/Async/Type/TypeType.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data;
13+
using System.Data.Common;
14+
using NHibernate.Engine;
15+
using NHibernate.SqlTypes;
16+
using NHibernate.Util;
17+
18+
namespace NHibernate.Type
19+
{
20+
using System.Threading.Tasks;
21+
using System.Threading;
22+
public partial class TypeType : ImmutableType
23+
{
24+
25+
/// <inheritdoc />
26+
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
27+
{
28+
if (cancellationToken.IsCancellationRequested)
29+
{
30+
return Task.FromCanceled<object>(cancellationToken);
31+
}
32+
try
33+
{
34+
return Task.FromResult<object>(Assemble(cached, session, owner));
35+
}
36+
catch (Exception ex)
37+
{
38+
return Task.FromException<object>(ex);
39+
}
40+
}
41+
42+
/// <inheritdoc />
43+
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
44+
{
45+
if (cancellationToken.IsCancellationRequested)
46+
{
47+
return Task.FromCanceled<object>(cancellationToken);
48+
}
49+
try
50+
{
51+
return Task.FromResult<object>(Disassemble(value, session, owner));
52+
}
53+
catch (Exception ex)
54+
{
55+
return Task.FromException<object>(ex);
56+
}
57+
}
58+
}
59+
}

src/NHibernate/Async/Type/UriType.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data.Common;
13+
using NHibernate.Engine;
14+
using NHibernate.SqlTypes;
15+
16+
namespace NHibernate.Type
17+
{
18+
using System.Threading.Tasks;
19+
using System.Threading;
20+
public partial class UriType : ImmutableType, IDiscriminatorType
21+
{
22+
23+
/// <inheritdoc />
24+
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
25+
{
26+
if (cancellationToken.IsCancellationRequested)
27+
{
28+
return Task.FromCanceled<object>(cancellationToken);
29+
}
30+
try
31+
{
32+
return Task.FromResult<object>(Assemble(cached, session, owner));
33+
}
34+
catch (Exception ex)
35+
{
36+
return Task.FromException<object>(ex);
37+
}
38+
}
39+
40+
/// <inheritdoc />
41+
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
42+
{
43+
if (cancellationToken.IsCancellationRequested)
44+
{
45+
return Task.FromCanceled<object>(cancellationToken);
46+
}
47+
try
48+
{
49+
return Task.FromResult<object>(Disassemble(value, session, owner));
50+
}
51+
catch (Exception ex)
52+
{
53+
return Task.FromException<object>(ex);
54+
}
55+
}
56+
}
57+
}

src/NHibernate/Async/Type/XDocType.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data.Common;
13+
using System.Xml.Linq;
14+
using NHibernate.Engine;
15+
using NHibernate.SqlTypes;
16+
17+
namespace NHibernate.Type
18+
{
19+
using System.Threading.Tasks;
20+
using System.Threading;
21+
public partial class XDocType : MutableType
22+
{
23+
24+
/// <inheritdoc />
25+
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
26+
{
27+
if (cancellationToken.IsCancellationRequested)
28+
{
29+
return Task.FromCanceled<object>(cancellationToken);
30+
}
31+
try
32+
{
33+
return Task.FromResult<object>(Assemble(cached, session, owner));
34+
}
35+
catch (Exception ex)
36+
{
37+
return Task.FromException<object>(ex);
38+
}
39+
}
40+
41+
/// <inheritdoc />
42+
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
43+
{
44+
if (cancellationToken.IsCancellationRequested)
45+
{
46+
return Task.FromCanceled<object>(cancellationToken);
47+
}
48+
try
49+
{
50+
return Task.FromResult<object>(Disassemble(value, session, owner));
51+
}
52+
catch (Exception ex)
53+
{
54+
return Task.FromException<object>(ex);
55+
}
56+
}
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data.Common;
13+
using System.Xml;
14+
using NHibernate.Engine;
15+
using NHibernate.SqlTypes;
16+
17+
namespace NHibernate.Type
18+
{
19+
using System.Threading.Tasks;
20+
using System.Threading;
21+
public partial class XmlDocType : MutableType
22+
{
23+
24+
/// <inheritdoc />
25+
public override Task<object> AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken)
26+
{
27+
if (cancellationToken.IsCancellationRequested)
28+
{
29+
return Task.FromCanceled<object>(cancellationToken);
30+
}
31+
try
32+
{
33+
return Task.FromResult<object>(Assemble(cached, session, owner));
34+
}
35+
catch (Exception ex)
36+
{
37+
return Task.FromException<object>(ex);
38+
}
39+
}
40+
41+
/// <inheritdoc />
42+
public override Task<object> DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken)
43+
{
44+
if (cancellationToken.IsCancellationRequested)
45+
{
46+
return Task.FromCanceled<object>(cancellationToken);
47+
}
48+
try
49+
{
50+
return Task.FromResult<object>(Disassemble(value, session, owner));
51+
}
52+
catch (Exception ex)
53+
{
54+
return Task.FromException<object>(ex);
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)