Skip to content

Commit ca28ec1

Browse files
committed
Merge branch 'master' of https://github.com/nhibernate/nhibernate-core into obsolete-ivalue-settypeusing-reflection
# Conflicts: # src/NHibernate/Cfg/XmlHbmBinding/ClassIdBinder.cs # src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs
2 parents 02fbe34 + bea3a31 commit ca28ec1

File tree

14 files changed

+204
-62
lines changed

14 files changed

+204
-62
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 NUnit.Framework;
12+
13+
namespace NHibernate.Test.NHSpecificTest.NH1284
14+
{
15+
using System.Threading.Tasks;
16+
[TestFixture]
17+
public class FixtureAsync : BugTestCase
18+
{
19+
protected override void OnTearDown()
20+
{
21+
using var s = OpenSession();
22+
using var tx = s.BeginTransaction();
23+
s.Delete("from Person");
24+
tx.Commit();
25+
}
26+
27+
[Test]
28+
public async Task EmptyValueTypeComponentAsync()
29+
{
30+
Person jimmy;
31+
using (var s = OpenSession())
32+
using (var tx = s.BeginTransaction())
33+
{
34+
var p = new Person("Jimmy Hendrix");
35+
await (s.SaveAsync(p));
36+
await (tx.CommitAsync());
37+
}
38+
39+
using (var s = OpenSession())
40+
using (var tx = s.BeginTransaction())
41+
{
42+
jimmy = await (s.GetAsync<Person>("Jimmy Hendrix"));
43+
await (tx.CommitAsync());
44+
}
45+
46+
Assert.That(jimmy.Address, Is.Null);
47+
}
48+
}
49+
}

Diff for: src/NHibernate.Test/NHSpecificTest/NH1284/Fixture.cs

+17-15
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22

33
namespace NHibernate.Test.NHSpecificTest.NH1284
44
{
5-
[TestFixture, Ignore("Not supported yet.")]
5+
[TestFixture]
66
public class Fixture : BugTestCase
77
{
8+
protected override void OnTearDown()
9+
{
10+
using var s = OpenSession();
11+
using var tx = s.BeginTransaction();
12+
s.Delete("from Person");
13+
tx.Commit();
14+
}
15+
816
[Test]
917
public void EmptyValueTypeComponent()
1018
{
1119
Person jimmy;
12-
using (ISession s = OpenSession())
13-
using (ITransaction tx = s.BeginTransaction())
20+
using (var s = OpenSession())
21+
using (var tx = s.BeginTransaction())
1422
{
15-
Person p = new Person("Jimmy Hendrix");
23+
var p = new Person("Jimmy Hendrix");
1624
s.Save(p);
1725
tx.Commit();
1826
}
1927

20-
using (ISession s = OpenSession())
21-
using (ITransaction tx = s.BeginTransaction())
28+
using (var s = OpenSession())
29+
using (var tx = s.BeginTransaction())
2230
{
23-
jimmy = (Person)s.Get(typeof(Person), "Jimmy Hendrix");
31+
jimmy = s.Get<Person>("Jimmy Hendrix");
2432
tx.Commit();
2533
}
26-
Assert.IsFalse(jimmy.Address.HasValue);
2734

28-
using (ISession s = OpenSession())
29-
using (ITransaction tx = s.BeginTransaction())
30-
{
31-
s.Delete("from Person");
32-
tx.Commit();
33-
}
35+
Assert.That(jimmy.Address, Is.Null);
3436
}
3537
}
36-
}
38+
}

Diff for: src/NHibernate.Test/NHSpecificTest/NH1284/Mappings.hbm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
<property name="GmtOffset"/>
1616
</component>
1717
</class>
18-
</hibernate-mapping>
18+
</hibernate-mapping>

Diff for: src/NHibernate.Test/TestDialect.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ public bool SupportsSqlType(SqlType sqlType)
123123
/// </summary>
124124
public virtual bool SupportsModuloOnDecimal => true;
125125

126+
/// <summary>
127+
/// Supports sub-selects in order by clause
128+
/// </summary>
129+
public virtual bool SupportsSubSelectsInOrderBy => _dialect.SupportsScalarSubSelects;
130+
126131
/// <summary>
127132
/// Supports aggregating sub-selects in order by clause
128133
/// </summary>
129-
public virtual bool SupportsAggregatingScalarSubSelectsInOrderBy => _dialect.SupportsScalarSubSelects;
134+
public virtual bool SupportsAggregatingScalarSubSelectsInOrderBy => SupportsSubSelectsInOrderBy;
130135

131136
/// <summary>
132137
/// Supports order by and limits/top in correlated sub-queries

Diff for: src/NHibernate.Test/TestDialects/DB2TestDialect.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NHibernate.Test.TestDialects
2+
{
3+
public class DB2TestDialect: TestDialect
4+
{
5+
public DB2TestDialect(Dialect.Dialect dialect) : base(dialect)
6+
{
7+
}
8+
9+
public override bool HasBrokenTypeInferenceOnSelectedParameters => true;
10+
public override bool SupportsCancelQuery => false;
11+
public override bool SupportsComplexExpressionInGroupBy => false;
12+
public override bool SupportsNonDataBoundCondition => false;
13+
public override bool SupportsSelectForUpdateWithPaging => false;
14+
public override bool SupportsSubSelectsInOrderBy => false;
15+
}
16+
}

Diff for: src/NHibernate.TestDatabaseSetup/TestDatabaseSetup.cs

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class DatabaseSetup
3232
{"NHibernate.Driver.OracleManagedDataClientDriver", SetupOracle},
3333
{"NHibernate.Driver.OdbcDriver", SetupSqlServerOdbc},
3434
{"NHibernate.Driver.SQLite20Driver", SetupSQLite},
35+
{"NHibernate.Driver.DB2Driver", SetupDB2},
36+
{"NHibernate.Driver.DB2CoreDriver", SetupDB2},
37+
{"NHibernate.Driver.DB2NetDriver", SetupDB2},
3538
#if NETFX
3639
{"NHibernate.Driver.SqlServerCeDriver", SetupSqlServerCe},
3740
{"NHibernate.Driver.SapSQLAnywhere17Driver", SetupSqlAnywhere}
@@ -207,6 +210,10 @@ private static void SetupSQLite(Cfg.Configuration cfg)
207210
}
208211
}
209212

213+
private static void SetupDB2(Cfg.Configuration cfg)
214+
{
215+
}
216+
210217
private static void SetupOracle(Cfg.Configuration cfg)
211218
{
212219
// disabled until system password is set on TeamCity

Diff for: src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs

+12-23
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,14 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
8383

8484
string propertyName = entityPropertyMapping.Name;
8585

86-
ICollectionPropertiesMapping collectionMapping;
87-
HbmManyToOne manyToOneMapping;
88-
HbmAny anyMapping;
89-
HbmOneToOne oneToOneMapping;
90-
HbmProperty propertyMapping;
91-
HbmComponent componentMapping;
92-
HbmDynamicComponent dynamicComponentMapping;
93-
HbmNestedCompositeElement nestedCompositeElementMapping;
94-
HbmKeyProperty keyPropertyMapping;
95-
HbmKeyManyToOne keyManyToOneMapping;
96-
HbmProperties propertiesMapping;
97-
98-
if ((propertyMapping = entityPropertyMapping as HbmProperty) != null)
86+
if (entityPropertyMapping is HbmProperty propertyMapping)
9987
{
10088
var value = new SimpleValue(table);
10189
new ValuePropertyBinder(value, Mappings).BindSimpleValue(propertyMapping, propertyName, true);
10290
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
10391
BindValueProperty(propertyMapping, property);
10492
}
105-
else if ((collectionMapping = entityPropertyMapping as ICollectionPropertiesMapping) != null)
93+
else if (entityPropertyMapping is ICollectionPropertiesMapping collectionMapping)
10694
{
10795
var collectionBinder = new CollectionBinder(Mappings);
10896
string propertyPath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);
@@ -115,22 +103,22 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
115103
property = CreateProperty(collectionMapping, mappedClass, collection, inheritedMetas);
116104
BindCollectionProperty(collectionMapping, property);
117105
}
118-
else if ((propertiesMapping = entityPropertyMapping as HbmProperties) != null)
106+
else if (entityPropertyMapping is HbmProperties propertiesMapping)
119107
{
120108
var subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);
121109
var value = CreateNewComponent(table);
122110
BindComponent(propertiesMapping, value, null, entityName, subpath, componetDefaultNullable, inheritedMetas);
123111
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
124112
BindComponentProperty(propertiesMapping, property, value);
125113
}
126-
else if ((manyToOneMapping = entityPropertyMapping as HbmManyToOne) != null)
114+
else if (entityPropertyMapping is HbmManyToOne manyToOneMapping)
127115
{
128116
var value = new ManyToOne(table);
129117
BindManyToOne(manyToOneMapping, value, propertyName, true);
130118
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
131119
BindManyToOneProperty(manyToOneMapping, property);
132120
}
133-
else if ((componentMapping = entityPropertyMapping as HbmComponent) != null)
121+
else if (entityPropertyMapping is HbmComponent componentMapping)
134122
{
135123
string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);
136124
var value = CreateNewComponent(table);
@@ -140,14 +128,14 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
140128
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
141129
BindComponentProperty(componentMapping, property, value);
142130
}
143-
else if ((oneToOneMapping = entityPropertyMapping as HbmOneToOne) != null)
131+
else if (entityPropertyMapping is HbmOneToOne oneToOneMapping)
144132
{
145133
var value = new OneToOne(table, persistentClass);
146134
BindOneToOne(oneToOneMapping, value);
147135
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
148136
BindOneToOneProperty(oneToOneMapping, property);
149137
}
150-
else if ((dynamicComponentMapping = entityPropertyMapping as HbmDynamicComponent) != null)
138+
else if (entityPropertyMapping is HbmDynamicComponent dynamicComponentMapping)
151139
{
152140
string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);
153141
var value = CreateNewComponent(table);
@@ -157,14 +145,14 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
157145
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
158146
BindComponentProperty(dynamicComponentMapping, property, value);
159147
}
160-
else if ((anyMapping = entityPropertyMapping as HbmAny) != null)
148+
else if (entityPropertyMapping is HbmAny anyMapping)
161149
{
162150
var value = new Any(table);
163151
BindAny(anyMapping, value, true);
164152
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
165153
BindAnyProperty(anyMapping, property);
166154
}
167-
else if ((nestedCompositeElementMapping = entityPropertyMapping as HbmNestedCompositeElement) != null)
155+
else if (entityPropertyMapping is HbmNestedCompositeElement nestedCompositeElementMapping)
168156
{
169157
if (component == null)
170158
{
@@ -177,13 +165,13 @@ public void Bind(IEnumerable<IEntityPropertyMapping> properties, Table table, ID
177165
BindComponent(nestedCompositeElementMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas);
178166
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
179167
}
180-
else if ((keyPropertyMapping = entityPropertyMapping as HbmKeyProperty) != null)
168+
else if (entityPropertyMapping is HbmKeyProperty keyPropertyMapping)
181169
{
182170
var value = new SimpleValue(table);
183171
new ValuePropertyBinder(value, Mappings).BindSimpleValue(keyPropertyMapping, propertyName, componetDefaultNullable);
184172
property = CreateProperty(entityPropertyMapping, mappedClass, value, inheritedMetas);
185173
}
186-
else if ((keyManyToOneMapping = entityPropertyMapping as HbmKeyManyToOne) != null)
174+
else if (entityPropertyMapping is HbmKeyManyToOne keyManyToOneMapping)
187175
{
188176
var value = new ManyToOne(table);
189177
BindKeyManyToOne(keyManyToOneMapping, value, propertyName, componetDefaultNullable);
@@ -400,6 +388,7 @@ private void BindCollectionProperty(ICollectionPropertiesMapping collectionMappi
400388

401389
private Property CreateProperty(IEntityPropertyMapping propertyMapping, System.Type propertyOwnerType, SimpleValue value, IDictionary<string, MetaAttribute> inheritedMetas)
402390
{
391+
var type = propertyOwnerType?.UnwrapIfNullable();
403392
if (string.IsNullOrEmpty(propertyMapping.Name))
404393
throw new MappingException("A property mapping must define the name attribute [" + propertyOwnerType + "]");
405394

Diff for: src/NHibernate/Dialect/DB2Dialect.cs

+5
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ public override bool SupportsSequences
214214
get { return true; }
215215
}
216216

217+
public override string QuerySequencesString => "select seqname from syscat.sequences";
218+
217219
/// <summary></summary>
218220
public override bool SupportsLimit
219221
{
@@ -311,6 +313,9 @@ public override string ForUpdateString
311313

312314
public override bool SupportsExistsInSelect => false;
313315

316+
/// <inheritdoc/>
317+
public override bool SupportsHavingOnGroupedByComputation => false;
318+
314319
public override bool DoesReadCommittedCauseWritersToBlockReaders => true;
315320

316321
#endregion

Diff for: src/NHibernate/Driver/DB2CoreDriver.cs

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
1-
using System.Data.Common;
2-
using NHibernate.SqlTypes;
1+
using System;
32

43
namespace NHibernate.Driver
54
{
65
/// <summary>
76
/// A NHibernate Driver for using the IBM.Data.DB2.Core DataProvider.
87
/// </summary>
9-
public class DB2CoreDriver : DB2DriverBase
10-
{
11-
public DB2CoreDriver() : base("IBM.Data.DB2.Core")
12-
{
13-
}
8+
// Since v5.6
9+
[Obsolete("Please use DB2NetDriver")]
10+
public class DB2CoreDriver : DB2NetDriver
11+
{
12+
private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(DB2CoreDriver));
1413

15-
public override bool UseNamedPrefixInSql => true;
16-
17-
public override bool UseNamedPrefixInParameter => true;
18-
19-
public override string NamedPrefix => "@";
20-
21-
protected override void InitializeParameter(DbParameter dbParam, string name, SqlType sqlType)
14+
public DB2CoreDriver() : base("IBM.Data.DB2.Core")
2215
{
23-
dbParam.ParameterName = FormatNameForParameter(name);
24-
base.InitializeParameter(dbParam, name, sqlType);
16+
Log.Warn("DB2CoreDriver is obsolete, please use DB2NetDriver instead.");
2517
}
2618
}
2719
}

Diff for: src/NHibernate/Driver/DB2NetDriver.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Data.Common;
2+
using NHibernate.SqlTypes;
3+
4+
namespace NHibernate.Driver
5+
{
6+
/// <summary>
7+
/// A NHibernate Driver for using the Net5.IBM.Data.Db2/Net.IBM.Data.Db2 DataProvider.
8+
/// </summary>
9+
public class DB2NetDriver : DB2DriverBase
10+
{
11+
private protected DB2NetDriver(string assemblyName) : base(assemblyName)
12+
{
13+
}
14+
15+
public DB2NetDriver() : base("IBM.Data.Db2")
16+
{
17+
}
18+
19+
public override bool UseNamedPrefixInSql => true;
20+
public override bool UseNamedPrefixInParameter => true;
21+
public override string NamedPrefix => "@";
22+
23+
protected override void InitializeParameter(DbParameter dbParam, string name, SqlType sqlType)
24+
{
25+
dbParam.ParameterName = FormatNameForParameter(name);
26+
base.InitializeParameter(dbParam, name, sqlType);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)