Skip to content

Commit 63991c1

Browse files
fredericDelaportehazzik
authored andcommitted
NH-4023 - Add the session parameter to IUserType
1 parent 110c611 commit 63991c1

File tree

19 files changed

+133
-120
lines changed

19 files changed

+133
-120
lines changed

src/NHibernate.DomainModel/NHSpecific/NullInt32UserType.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Data.Common;
3-
3+
using NHibernate.Engine;
44
using NHibernate.SqlTypes;
55
using NHibernate.Type;
66
using NHibernate.UserTypes;
@@ -46,15 +46,15 @@ public object DeepCopy(object value)
4646
return value;
4747
}
4848

49-
public void NullSafeSet(DbCommand cmd, object value, int index)
49+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
5050
{
5151
if (value.Equals(0))
5252
{
5353
cmd.Parameters[index].Value = DBNull.Value;
5454
}
5555
else
5656
{
57-
_int32Type.Set(cmd, value, index, null);
57+
_int32Type.Set(cmd, value, index, session);
5858
}
5959
}
6060

@@ -63,9 +63,9 @@ public System.Type ReturnedType
6363
get { return typeof(Int32); }
6464
}
6565

66-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
66+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
6767
{
68-
return _int32Type.NullSafeGet(rs, names, null);
68+
return _int32Type.NullSafeGet(rs, names, session);
6969
}
7070

7171
public bool IsMutable

src/NHibernate.Test/DateTimeOffsetUserType.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public SqlType[] SqlTypes
3030
get { return new[] { new SqlType(DbType.DateTime) }; }
3131
}
3232

33-
public object NullSafeGet(DbDataReader dr, string[] names, object owner)
33+
public object NullSafeGet(DbDataReader dr, string[] names, ISessionImplementor session, object owner)
3434
{
3535
var name = names[0];
3636
int index = dr.GetOrdinal(name);
@@ -40,7 +40,7 @@ public object NullSafeGet(DbDataReader dr, string[] names, object owner)
4040
return null;
4141
}
4242
try
43-
{
43+
{
4444
DateTime storedTime;
4545
try
4646
{
@@ -63,11 +63,11 @@ public object NullSafeGet(DbDataReader dr, string[] names, object owner)
6363
}
6464
}
6565

66-
public void NullSafeSet(DbCommand cmd, object value, int index)
66+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
6767
{
6868
if (value == null)
6969
{
70-
NHibernateUtil.DateTime.NullSafeSet(cmd, null, index, null);
70+
NHibernateUtil.DateTime.NullSafeSet(cmd, null, index, session);
7171
}
7272
else
7373
{

src/NHibernate.Test/MappingByCode/MappersTests/PropertyMapperTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,12 @@ public int GetHashCode(object x)
334334
throw new NotImplementedException();
335335
}
336336

337-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
337+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
338338
{
339339
throw new NotImplementedException();
340340
}
341341

342-
public void NullSafeSet(DbCommand cmd, object value, int index)
342+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
343343
{
344344
throw new NotImplementedException();
345345
}

src/NHibernate.Test/NHSpecificTest/DataReaderWrapperTest/TheUserType.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Data;
33
using System.Data.Common;
4+
using NHibernate.Engine;
45
using NHibernate.SqlTypes;
56
using NHibernate.UserTypes;
67

@@ -28,14 +29,14 @@ public int GetHashCode(object x)
2829
return x.GetHashCode();
2930
}
3031

31-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
32+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
3233
{
3334
return rs.GetValue(rs.GetOrdinal(names[0]));
3435
}
3536

36-
public void NullSafeSet(DbCommand cmd, object value, int index)
37+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
3738
{
38-
NHibernateUtil.String.NullSafeSet(cmd, value, index, null);
39+
NHibernateUtil.String.NullSafeSet(cmd, value, index, session);
3940
}
4041

4142
public object DeepCopy(object value)

src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/DoubleStringUserType.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Data;
33
using System.Data.Common;
4+
using NHibernate.Engine;
45
using NHibernate.SqlTypes;
56
using NHibernate.UserTypes;
67

@@ -32,17 +33,17 @@ public int GetHashCode(object x)
3233
return x.GetHashCode();
3334
}
3435

35-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
36+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
3637
{
37-
object obj = NHibernateUtil.String.NullSafeGet(rs, names[0], null);
38+
object obj = NHibernateUtil.String.NullSafeGet(rs, names[0], session);
3839
if (obj == null)
3940
{
4041
return null;
4142
}
4243
return Convert.ToDouble((string)obj);
4344
}
4445

45-
public void NullSafeSet(DbCommand cmd, object value, int index)
46+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
4647
{
4748
if (value == null)
4849
{

src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/ExampleUserType.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Data;
33
using System.Data.Common;
4+
using NHibernate.Engine;
45
using NHibernate.SqlTypes;
56
using NHibernate.UserTypes;
67

@@ -58,7 +59,7 @@ public object Disassemble(object value)
5859
public System.Type ReturnedType { get { return typeof(IExample); } }
5960
public bool IsMutable { get { return true; } }
6061

61-
public void NullSafeSet(DbCommand cmd, object value, int index)
62+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
6263
{
6364
var dataParameter = cmd.Parameters[index];
6465
var example = (IExample)value;
@@ -73,7 +74,7 @@ public void NullSafeSet(DbCommand cmd, object value, int index)
7374
}
7475
}
7576

76-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
77+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
7778
{
7879
var index = rs.GetOrdinal(names[0]);
7980
if (rs.IsDBNull(index))

src/NHibernate.Test/NHSpecificTest/NH1355/UserTypeTimestamp.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public bool IsMutable
4949
get { return false; }
5050
}
5151

52-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
52+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
5353
{
5454
return rs.GetValue(rs.GetOrdinal(names[0]));
5555
}
5656

57-
public void NullSafeSet(DbCommand cmd, object value, int index)
57+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
5858
{
59-
NHibernateUtil.Binary.NullSafeSet(cmd, value, index, null);
59+
NHibernateUtil.Binary.NullSafeSet(cmd, value, index, session);
6060
}
6161

6262
public object Replace(object original, object target, object owner)

src/NHibernate.Test/NHSpecificTest/NH1907/MyType.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Data.Common;
3+
using NHibernate.Engine;
34
using NHibernate.SqlTypes;
45
using NHibernate.UserTypes;
56

@@ -61,7 +62,7 @@ public object DeepCopy(object value)
6162
return value;
6263
}
6364

64-
public void NullSafeSet(DbCommand cmd, object value, int index)
65+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
6566
{
6667
if (value == null)
6768
{
@@ -78,7 +79,7 @@ public System.Type ReturnedType
7879
get { return typeof(Int32); }
7980
}
8081

81-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
82+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
8283
{
8384
int index0 = rs.GetOrdinal(names[0]);
8485
if (rs.IsDBNull(index0))

src/NHibernate.Test/NHSpecificTest/NH2234/MyType.cs

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,65 @@
11
using System.Collections.Generic;
22
using System.Data.Common;
3+
using NHibernate.Engine;
34
using NHibernate.SqlTypes;
45
using NHibernate.UserTypes;
56

67
namespace NHibernate.Test.NHSpecificTest.NH2234
78
{
8-
public class MyUsertype
9-
{
10-
public MyUsertype(int id, string value)
11-
{
12-
Id = id;
13-
Value = value;
14-
}
15-
16-
public int Id { get; set; }
17-
public string Value { get; set; }
18-
19-
public override int GetHashCode()
20-
{
21-
return Id.GetHashCode();
22-
}
23-
24-
public override bool Equals(object obj)
25-
{
26-
var mut = obj as MyUsertype;
27-
return mut != null && mut.Id == Id;
28-
}
29-
30-
public static bool operator ==(MyUsertype left, MyUsertype right)
31-
{
32-
return Equals(left, right);
33-
}
34-
35-
public static bool operator !=(MyUsertype left, MyUsertype right)
36-
{
37-
return !Equals(left, right);
38-
}
39-
}
40-
41-
public static class MyUserTypes
42-
{
43-
public static readonly List<MyUsertype> _values = new List<MyUsertype>()
44-
{new MyUsertype(1, "Value 1"), new MyUsertype(2, "Value 2")};
45-
46-
47-
public static MyUsertype Value1
48-
{
49-
get { return _values[0]; }
50-
}
51-
52-
public static MyUsertype Value2
53-
{
54-
get { return _values[1]; }
55-
}
56-
57-
public static MyUsertype Find(int id)
58-
{
59-
return _values.Find(item => item.Id == id);
60-
}
61-
}
9+
public class MyUsertype
10+
{
11+
public MyUsertype(int id, string value)
12+
{
13+
Id = id;
14+
Value = value;
15+
}
16+
17+
public int Id { get; set; }
18+
public string Value { get; set; }
19+
20+
public override int GetHashCode()
21+
{
22+
return Id.GetHashCode();
23+
}
24+
25+
public override bool Equals(object obj)
26+
{
27+
var mut = obj as MyUsertype;
28+
return mut != null && mut.Id == Id;
29+
}
30+
31+
public static bool operator ==(MyUsertype left, MyUsertype right)
32+
{
33+
return Equals(left, right);
34+
}
35+
36+
public static bool operator !=(MyUsertype left, MyUsertype right)
37+
{
38+
return !Equals(left, right);
39+
}
40+
}
41+
42+
public static class MyUserTypes
43+
{
44+
public static readonly List<MyUsertype> _values =
45+
new List<MyUsertype> { new MyUsertype(1, "Value 1"), new MyUsertype(2, "Value 2") };
46+
47+
48+
public static MyUsertype Value1
49+
{
50+
get { return _values[0]; }
51+
}
52+
53+
public static MyUsertype Value2
54+
{
55+
get { return _values[1]; }
56+
}
57+
58+
public static MyUsertype Find(int id)
59+
{
60+
return _values.Find(item => item.Id == id);
61+
}
62+
}
6263

6364
public class SimpleCustomType : IUserType
6465
{
@@ -87,23 +88,23 @@ public object DeepCopy(object value)
8788
return value;
8889
}
8990

90-
public void NullSafeSet(DbCommand cmd, object value, int index)
91+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
9192
{
9293
if (value == null)
93-
NHibernateUtil.Int32.NullSafeSet(cmd, null, index, null);
94+
NHibernateUtil.Int32.NullSafeSet(cmd, null, index, session);
9495
else
95-
NHibernateUtil.Int32.NullSafeSet(cmd, ((MyUsertype)value).Id, index, null);
96+
NHibernateUtil.Int32.NullSafeSet(cmd, ((MyUsertype)value).Id, index, session);
9697
}
9798

9899
public System.Type ReturnedType
99100
{
100101
get { return typeof(MyUsertype); }
101102
}
102103

103-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
104+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
104105
{
105-
int value = (int)NHibernateUtil.Int32.NullSafeGet(rs, names[0], null, owner);
106-
return MyUserTypes.Find(value);
106+
int value = (int)NHibernateUtil.Int32.NullSafeGet(rs, names[0], session, owner);
107+
return MyUserTypes.Find(value);
107108
}
108109

109110
public bool IsMutable

src/NHibernate.Test/NHSpecificTest/NH2839/FixtureByCode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Data.Common;
33
using System.Linq;
44
using NHibernate.Cfg.MappingSchema;
5+
using NHibernate.Engine;
56
using NHibernate.Linq;
67
using NHibernate.Mapping.ByCode;
78
using NHibernate.SqlTypes;
@@ -43,15 +44,15 @@ public int GetHashCode(object x)
4344
return x.GetHashCode();
4445
}
4546

46-
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
47+
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
4748
{
4849
var ordinal = rs.GetOrdinal(names[0]);
4950
if (rs.IsDBNull(ordinal))
5051
return false;
5152
return rs.GetInt32(ordinal) == 1;
5253
}
5354

54-
public void NullSafeSet(DbCommand cmd, object value, int index)
55+
public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
5556
{
5657
cmd.Parameters[index].Value = ((bool) value) ? 1 : -1;
5758
}

0 commit comments

Comments
 (0)