Skip to content

Commit 0e5fc02

Browse files
authored
Merge branch '5.4.x' into gh3288
2 parents c73a6e5 + 19d4549 commit 0e5fc02

File tree

14 files changed

+253
-22
lines changed

14 files changed

+253
-22
lines changed

.github/renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
],
1616
"packageRules": [
1717
{
18-
"matchPackagePrefixes": [
19-
"NUnit"
20-
],
18+
"matchSourceUrls": ["https://github.com/nunit/nunit"],
2119
"groupName": "NUnit"
2220
},
2321
{

src/NHibernate.Test.VisualBasic/NHibernate.Test.VisualBasic.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
2929
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
3030
<PackageReference Include="NUnit" Version="3.13.2" />
31-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
31+
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
3232
</ItemGroup>
3333
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
3434
<PackageReference Include="NUnitLite" Version="3.13.2" />
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.Linq;
13+
using NHibernate.Criterion;
14+
using NUnit.Framework;
15+
using NHibernate.Linq;
16+
17+
namespace NHibernate.Test.NHSpecificTest.GH3291
18+
{
19+
using System.Threading.Tasks;
20+
[TestFixture]
21+
public class FixtureAsync : BugTestCase
22+
{
23+
protected override void OnSetUp()
24+
{
25+
using var session = OpenSession();
26+
using var transaction = session.BeginTransaction();
27+
28+
var e1 = new Person { Name = "Bob", DateOfBirth = new DateTime(2009, 12, 23) };
29+
session.Save(e1);
30+
31+
var e2 = new Person { Name = "Sally", DateOfBirth = new DateTime(2018, 9, 30) };
32+
session.Save(e2);
33+
34+
transaction.Commit();
35+
}
36+
37+
protected override void OnTearDown()
38+
{
39+
using var session = OpenSession();
40+
using var transaction = session.BeginTransaction();
41+
42+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
43+
44+
transaction.Commit();
45+
}
46+
47+
[Test]
48+
public async Task LinqAsync()
49+
{
50+
using var session = OpenSession();
51+
using var _ = session.BeginTransaction();
52+
53+
DateTime? dateOfSearch = null;
54+
55+
var result = await ((
56+
from person in session.Query<Person>()
57+
where dateOfSearch == null || person.DateOfBirth > dateOfSearch
58+
select person).ToListAsync());
59+
60+
Assert.That(result, Has.Count.EqualTo(2));
61+
}
62+
63+
[Test]
64+
public async Task HqlAsync()
65+
{
66+
using var session = OpenSession();
67+
using var _ = session.BeginTransaction();
68+
69+
DateTime? dateOfSearch = null;
70+
71+
var result =
72+
await (session.CreateQuery("from Person where :DateOfSearch is null OR DateOfBirth > :DateOfSearch")
73+
.SetParameter("DateOfSearch", dateOfSearch, NHibernateUtil.DateTime)
74+
.ListAsync<Person>());
75+
76+
Assert.That(result, Has.Count.EqualTo(2));
77+
}
78+
}
79+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Linq;
3+
using NHibernate.Criterion;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.NHSpecificTest.GH3291
7+
{
8+
[TestFixture]
9+
public class Fixture : BugTestCase
10+
{
11+
protected override void OnSetUp()
12+
{
13+
using var session = OpenSession();
14+
using var transaction = session.BeginTransaction();
15+
16+
var e1 = new Person { Name = "Bob", DateOfBirth = new DateTime(2009, 12, 23) };
17+
session.Save(e1);
18+
19+
var e2 = new Person { Name = "Sally", DateOfBirth = new DateTime(2018, 9, 30) };
20+
session.Save(e2);
21+
22+
transaction.Commit();
23+
}
24+
25+
protected override void OnTearDown()
26+
{
27+
using var session = OpenSession();
28+
using var transaction = session.BeginTransaction();
29+
30+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
31+
32+
transaction.Commit();
33+
}
34+
35+
[Test]
36+
public void Linq()
37+
{
38+
using var session = OpenSession();
39+
using var _ = session.BeginTransaction();
40+
41+
DateTime? dateOfSearch = null;
42+
43+
var result = (
44+
from person in session.Query<Person>()
45+
where dateOfSearch == null || person.DateOfBirth > dateOfSearch
46+
select person).ToList();
47+
48+
Assert.That(result, Has.Count.EqualTo(2));
49+
}
50+
51+
[Test]
52+
public void Hql()
53+
{
54+
using var session = OpenSession();
55+
using var _ = session.BeginTransaction();
56+
57+
DateTime? dateOfSearch = null;
58+
59+
var result =
60+
session.CreateQuery("from Person where :DateOfSearch is null OR DateOfBirth > :DateOfSearch")
61+
.SetParameter("DateOfSearch", dateOfSearch, NHibernateUtil.DateTime)
62+
.List<Person>();
63+
64+
Assert.That(result, Has.Count.EqualTo(2));
65+
}
66+
}
67+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH3291">
4+
5+
<class name="Person">
6+
<id name="Id" generator="guid.comb"/>
7+
<property name="Name"/>
8+
<property name="DateOfBirth" />
9+
</class>
10+
11+
</hibernate-mapping>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH3291
4+
{
5+
class Person
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
public virtual DateTime? DateOfBirth { get; set; }
10+
}
11+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.12" />
6464
<PackageReference Include="NSubstitute" Version="4.4.0" />
6565
<PackageReference Include="NUnit" Version="3.13.2" />
66-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
66+
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
6767
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
6868
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="8.5.2" />
6969
<PackageReference Include="Npgsql" Version="6.0.6" />

src/NHibernate.Test/StaticProxyTest/StaticProxyFactoryFixture.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,50 @@ private static BinaryFormatter GetFormatter()
816816
#endif
817817
}
818818

819+
#if NETCOREAPP3_1_OR_GREATER
820+
public interface IWithStaticMethods
821+
{
822+
// C# 8
823+
static void StaticMethod()
824+
{
825+
}
826+
827+
#if NET7_0_OR_GREATER
828+
// C# 11
829+
static abstract void StaticAbstractMethod();
830+
831+
// C# 11
832+
static virtual void StaticVirtualMethod()
833+
{
834+
}
835+
#endif
836+
}
837+
838+
public class ClassWithStaticInterfaceMethods : IWithStaticMethods
839+
{
840+
public static void StaticAbstractMethod()
841+
{
842+
}
843+
}
844+
845+
[Test(Description = "GH3295")]
846+
public void VerifyProxyForClassWithStaticInterfaceMethod()
847+
{
848+
var factory = new StaticProxyFactory();
849+
factory.PostInstantiate(
850+
typeof(ClassWithStaticInterfaceMethods).FullName,
851+
typeof(ClassWithStaticInterfaceMethods),
852+
new HashSet<System.Type> { typeof(INHibernateProxy) },
853+
null, null, null, true);
854+
855+
var proxy = factory.GetProxy(1, null);
856+
Assert.That(proxy, Is.Not.Null);
857+
Assert.That(proxy, Is.InstanceOf<ClassWithStaticInterfaceMethods>());
858+
859+
Assert.That(factory.GetFieldInterceptionProxy(), Is.InstanceOf<ClassWithStaticInterfaceMethods>());
860+
}
861+
#endif
862+
819863
#if NETFX
820864
private static void VerifyGeneratedAssembly(System.Action assemblyGenerator)
821865
{

src/NHibernate.TestDatabaseSetup/NHibernate.TestDatabaseSetup.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</ItemGroup>
1717
<ItemGroup>
1818
<PackageReference Include="NUnit" Version="3.13.2" />
19-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
19+
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
2020
</ItemGroup>
2121
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
2222
<PackageReference Include="NUnitLite" Version="3.13.2" />

src/NHibernate.TestDatabaseSetup/TestDatabaseSetup.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ private static void SetupNpgsql(Cfg.Configuration cfg)
182182

183183
using (var cmd = conn.CreateCommand())
184184
{
185-
cmd.CommandText =
186-
@"CREATE OR REPLACE FUNCTION uuid_generate_v4()
187-
RETURNS uuid
188-
AS '$libdir/uuid-ossp', 'uuid_generate_v4'
189-
VOLATILE STRICT LANGUAGE C;";
185+
cmd.CommandText = "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";";
190186

191187
cmd.ExecuteNonQuery();
192188
}

src/NHibernate/Async/Event/Default/AbstractFlushingEventListener.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ protected virtual async Task PrepareEntityFlushesAsync(IEventSource session, Can
191191
cancellationToken.ThrowIfCancellationRequested();
192192
log.Debug("processing flush-time cascades");
193193

194+
var anything = Anything;
194195
ICollection list = IdentityMap.ConcurrentEntries(session.PersistenceContext.EntityEntries);
195196
//safe from concurrent modification because of how entryList() is implemented on IdentityMap
196197
foreach (DictionaryEntry me in list)
@@ -199,7 +200,7 @@ protected virtual async Task PrepareEntityFlushesAsync(IEventSource session, Can
199200
Status status = entry.Status;
200201
if (status == Status.Loaded || status == Status.Saving || status == Status.ReadOnly)
201202
{
202-
await (CascadeOnFlushAsync(session, entry.Persister, me.Key, Anything, cancellationToken)).ConfigureAwait(false);
203+
await (CascadeOnFlushAsync(session, entry.Persister, me.Key, anything, cancellationToken)).ConfigureAwait(false);
203204
}
204205
}
205206
}

src/NHibernate/Driver/NpgsqlDriver.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Data;
23
using System.Data.Common;
34
using NHibernate.AdoNet;
@@ -74,14 +75,37 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
7475
// Since the .NET currency type has 4 decimal places, we use a decimal type in PostgreSQL instead of its native 2 decimal currency type.
7576
dbParam.DbType = DbType.Decimal;
7677
}
77-
else if (DriverVersionMajor < 6 || sqlType.DbType != DbType.DateTime)
78+
else
7879
{
7980
dbParam.DbType = sqlType.DbType;
8081
}
81-
else
82+
}
83+
84+
public override void AdjustCommand(DbCommand command)
85+
{
86+
if (DriverVersionMajor >= 6)
8287
{
83-
// Let Npgsql 6 driver to decide parameter type
88+
for (var i = 0; i < command.Parameters.Count; i++)
89+
{
90+
var parameter = command.Parameters[i];
91+
if (parameter.DbType == DbType.DateTime &&
92+
parameter.Value is DateTime dateTime &&
93+
dateTime.Kind != DateTimeKind.Utc)
94+
{
95+
// There are breaking changes in Npgsql 6 as following:
96+
// UTC DateTime is now strictly mapped to timestamptz,
97+
// while Local/Unspecified DateTime is now strictly mapped to timestamp.
98+
//
99+
// DbType.DateTime now maps to timestamptz, not timestamp.
100+
// DbType.DateTime2 continues to map to timestamp
101+
//
102+
// See more details here: https://www.npgsql.org/doc/release-notes/6.0.html#detailed-notes
103+
parameter.DbType = DbType.DateTime2;
104+
}
105+
}
84106
}
107+
108+
base.AdjustCommand(command);
85109
}
86110

87111
// Prior to v3, Npgsql was expecting DateTime for time.

src/NHibernate/Event/Default/AbstractFlushingEventListener.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ protected virtual void PrepareEntityFlushes(IEventSource session)
188188
{
189189
log.Debug("processing flush-time cascades");
190190

191+
var anything = Anything;
191192
ICollection list = IdentityMap.ConcurrentEntries(session.PersistenceContext.EntityEntries);
192193
//safe from concurrent modification because of how entryList() is implemented on IdentityMap
193194
foreach (DictionaryEntry me in list)
@@ -196,7 +197,7 @@ protected virtual void PrepareEntityFlushes(IEventSource session)
196197
Status status = entry.Status;
197198
if (status == Status.Loaded || status == Status.Saving || status == Status.ReadOnly)
198199
{
199-
CascadeOnFlush(session, entry.Persister, me.Key, Anything);
200+
CascadeOnFlush(session, entry.Persister, me.Key, anything);
200201
}
201202
}
202203
}

src/NHibernate/Proxy/ProxyBuilderHelper.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace NHibernate.Proxy
2121
{
2222
internal static class ProxyBuilderHelper
2323
{
24+
private const BindingFlags ProxiableMethodsBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
25+
2426
private static readonly ConstructorInfo ObjectConstructor = typeof(object).GetConstructor(System.Type.EmptyTypes);
2527
private static readonly ConstructorInfo SecurityCriticalAttributeConstructor = typeof(SecurityCriticalAttribute).GetConstructor(System.Type.EmptyTypes);
2628
private static readonly ConstructorInfo IgnoresAccessChecksToAttributeConstructor = typeof(IgnoresAccessChecksToAttribute).GetConstructor(new[] {typeof(string)});
@@ -94,23 +96,20 @@ internal static void CallDefaultBaseConstructor(ILGenerator il, System.Type pare
9496

9597
internal static IEnumerable<MethodInfo> GetProxiableMethods(System.Type type)
9698
{
97-
const BindingFlags candidateMethodsBindingFlags =
98-
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
99-
100-
return type.GetMethods(candidateMethodsBindingFlags).Where(m => m.IsProxiable());
99+
return type.GetMethods(ProxiableMethodsBindingFlags).Where(m => m.IsProxiable());
101100
}
102101

103102
internal static IEnumerable<MethodInfo> GetProxiableMethods(System.Type type, IEnumerable<System.Type> interfaces)
104103
{
105104
if (type.IsInterface || type == typeof(object) || type.GetInterfaces().Length == 0)
106105
{
107106
return GetProxiableMethods(type)
108-
.Concat(interfaces.SelectMany(i => i.GetMethods()))
107+
.Concat(interfaces.SelectMany(i => i.GetMethods(ProxiableMethodsBindingFlags)))
109108
.Distinct();
110109
}
111110

112111
var proxiableMethods = new HashSet<MethodInfo>(GetProxiableMethods(type), new MethodInfoComparer(type));
113-
foreach (var interfaceMethod in interfaces.SelectMany(i => i.GetMethods()))
112+
foreach (var interfaceMethod in interfaces.SelectMany(i => i.GetMethods(ProxiableMethodsBindingFlags)))
114113
{
115114
proxiableMethods.Add(interfaceMethod);
116115
}

0 commit comments

Comments
 (0)