Skip to content

Commit 57e9e2a

Browse files
Merge branch 'master' into NH-2285-v2
2 parents b2490ff + fa978cf commit 57e9e2a

File tree

16 files changed

+76
-32
lines changed

16 files changed

+76
-32
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
5757
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
5858
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="6.3.0" />
59-
<PackageReference Include="Npgsql" Version="3.2.4.1" />
59+
<PackageReference Include="Npgsql" Version="4.0.3" />
6060
</ItemGroup>
6161
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
6262
<Reference Include="System.Configuration" />

src/NHibernate.Test/TestDialects/PostgreSQL83TestDialect.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
{
33
public class PostgreSQL83TestDialect : TestDialect
44
{
5-
public PostgreSQL83TestDialect(Dialect.Dialect dialect)
6-
: base(dialect)
7-
{
8-
}
5+
public PostgreSQL83TestDialect(Dialect.Dialect dialect)
6+
: base(dialect)
7+
{
8+
}
99

10-
public override bool SupportsSelectForUpdateOnOuterJoin
11-
{
12-
get { return false; }
13-
}
10+
public override bool SupportsSelectForUpdateOnOuterJoin => false;
1411

15-
public override bool SupportsNullCharactersInUtfStrings
16-
{
17-
get { return false; }
18-
}
12+
public override bool SupportsNullCharactersInUtfStrings => false;
13+
14+
/// <summary>
15+
/// Npgsql since its 3.2.5 version fails some tests requiring this feature. The trouble was not occuring with
16+
/// Npgsql 3.2.4.1.
17+
/// </summary>
18+
public override bool SupportsUsingConnectionOnSystemTransactionPrepare => false;
1919
}
2020
}

src/NHibernate/Async/Transaction/AdoTransaction.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Generic;
1313
using System.Data;
1414
using System.Data.Common;
15+
using NHibernate.Driver;
1516
using NHibernate.Engine;
1617
using NHibernate.Impl;
1718

src/NHibernate/Dialect/PostgreSQLDialect.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ public override string CurrentTimestampSelectString
329329

330330
public override string QuerySequencesString => "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'";
331331

332+
/// <summary>
333+
/// Does this dialect supports distributed transaction? <c>false</c>.
334+
/// </summary>
335+
/// <remarks>
336+
/// Npgsql since its version 3.2.5 version has race conditions: it fails handling the threading involved with
337+
/// distributed transactions. This causes a bunch of distributed tests to be flaky with Npgsql. Individually,
338+
/// they usually succeed, but run together, some of them fail. The trouble was not occuring with Npgsql 3.2.4.1.
339+
/// </remarks>
340+
public override bool SupportsDistributedTransactions => false;
341+
332342
#endregion
333343

334344
[Serializable]

src/NHibernate/Driver/DriverBase.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ protected bool IsPrepareSqlEnabled
4646
public abstract DbConnection CreateConnection();
4747
public abstract DbCommand CreateCommand();
4848

49+
/// <summary>
50+
/// Begin an ADO <see cref="DbTransaction" />.
51+
/// </summary>
52+
/// <param name="isolationLevel">The isolation level requested for the transaction.</param>
53+
/// <param name="connection">The connection on which to start the transaction.</param>
54+
/// <returns>The started <see cref="DbTransaction" />.</returns>
55+
public virtual DbTransaction BeginTransaction(IsolationLevel isolationLevel, DbConnection connection)
56+
{
57+
if (isolationLevel == IsolationLevel.Unspecified)
58+
{
59+
return connection.BeginTransaction();
60+
}
61+
return connection.BeginTransaction(isolationLevel);
62+
}
63+
4964
/// <summary>
5065
/// Does this Driver require the use of a Named Prefix in the SQL statement.
5166
/// </summary>
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
1+
using System.Data;
12
using System.Data.Common;
23
using NHibernate.AdoNet;
34
using NHibernate.SqlTypes;
4-
using NHibernate.Type;
55

66
namespace NHibernate.Driver
77
{
8-
internal static class DriverExtensions
8+
public static class DriverExtensions
99
{
1010
internal static void AdjustParameterForValue(this IDriver driver, DbParameter parameter, SqlType sqlType, object value)
1111
{
1212
var adjustingDriver = driver as IParameterAdjuster;
1313
adjustingDriver?.AdjustParameterForValue(parameter, sqlType, value);
1414
}
15+
16+
// 6.0 TODO: merge into IDriver
17+
/// <summary>
18+
/// Begin an ADO <see cref="DbTransaction" />.
19+
/// </summary>
20+
/// <param name="driver">The driver.</param>
21+
/// <param name="isolationLevel">The isolation level requested for the transaction.</param>
22+
/// <param name="connection">The connection on which to start the transaction.</param>
23+
/// <returns>The started <see cref="DbTransaction" />.</returns>
24+
public static DbTransaction BeginTransaction(this IDriver driver, IsolationLevel isolationLevel, DbConnection connection)
25+
{
26+
if (driver is DriverBase driverBase)
27+
{
28+
return driverBase.BeginTransaction(isolationLevel, connection);
29+
}
30+
31+
// So long for custom drivers not deriving from DriverBase, they will have to wait for 6.0 if they
32+
// need the feature.
33+
if (isolationLevel == IsolationLevel.Unspecified)
34+
{
35+
return connection.BeginTransaction();
36+
}
37+
return connection.BeginTransaction(isolationLevel);
38+
}
1539
}
1640
}

src/NHibernate/Transaction/AdoTransaction.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.Data.Common;
5+
using NHibernate.Driver;
56
using NHibernate.Engine;
67
using NHibernate.Impl;
78

@@ -146,14 +147,7 @@ public void Begin(IsolationLevel isolationLevel)
146147

147148
try
148149
{
149-
if (isolationLevel == IsolationLevel.Unspecified)
150-
{
151-
trans = session.Connection.BeginTransaction();
152-
}
153-
else
154-
{
155-
trans = session.Connection.BeginTransaction(isolationLevel);
156-
}
150+
trans = session.Factory.ConnectionProvider.Driver.BeginTransaction(isolationLevel, session.Connection);
157151
}
158152
catch (HibernateException)
159153
{

src/NHibernate/Type/DecimalType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override System.Type ReturnedClass
3939

4040
public override void Set(DbCommand st, object value, int index, ISessionImplementor session)
4141
{
42-
st.Parameters[index].Value = value;
42+
st.Parameters[index].Value = Convert.ToDecimal(value);
4343
}
4444

4545
public override string Name

src/NHibernate/Type/DoubleType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override System.Type ReturnedClass
3838

3939
public override void Set(DbCommand st, object value, int index, ISessionImplementor session)
4040
{
41-
st.Parameters[index].Value = value;
41+
st.Parameters[index].Value = Convert.ToDouble(value);
4242
}
4343

4444
/// <summary></summary>

src/NHibernate/Type/Int16Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToInt16(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/Int32Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToInt32(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/Int64Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToInt64(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/SByteType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToSByte(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/UInt16Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToUInt16(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/UInt32Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override System.Type ReturnedClass
5858

5959
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
6060
{
61-
rs.Parameters[index].Value = value;
61+
rs.Parameters[index].Value = Convert.ToUInt32(value);
6262
}
6363

6464
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

src/NHibernate/Type/UInt64Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override System.Type ReturnedClass
5757

5858
public override void Set(DbCommand rs, object value, int index, ISessionImplementor session)
5959
{
60-
rs.Parameters[index].Value = value;
60+
rs.Parameters[index].Value = Convert.ToUInt64(value);
6161
}
6262

6363
// 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml

0 commit comments

Comments
 (0)