Skip to content

Commit 51a1ab0

Browse files
committed
Merge remote-tracking branch 'nhibernate/master'
2 parents 8de813c + 13bdb94 commit 51a1ab0

File tree

7 files changed

+139
-10
lines changed

7 files changed

+139
-10
lines changed

src/NHibernate.Test/Linq/ExpressionSessionLeakTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace NHibernate.Test.Linq
88
{
99
public class ExpressionSessionLeakTest : LinqTestCase
1010
{
11-
[Test, KnownBug("NH-3579")]
11+
[Test]
1212
public void SessionGetsCollected()
1313
{
1414
var reference = DoLinqInSeparateSession();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Test.NHSpecificTest.NH3590
5+
{
6+
public class Entity
7+
{
8+
public Entity()
9+
{
10+
Dates = new HashSet<DateTime>();
11+
}
12+
13+
public virtual Guid Id { get; protected set; }
14+
public virtual ISet<DateTime> Dates { get; protected set; }
15+
16+
public override bool Equals(object obj)
17+
{
18+
var that = obj as Entity;
19+
return that != null && that.Id == Id;
20+
}
21+
22+
public override int GetHashCode()
23+
{
24+
return Id.GetHashCode();
25+
}
26+
}
27+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using NUnit.Framework;
3+
using SharpTestsEx;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH3590
6+
{
7+
[TestFixture]
8+
public class Fixture : BugTestCase
9+
{
10+
private Entity entity;
11+
12+
protected override void OnSetUp()
13+
{
14+
entity = new Entity();
15+
using (var s = OpenSession())
16+
{
17+
using (var tx = s.BeginTransaction())
18+
{
19+
s.Save(entity);
20+
tx.Commit();
21+
}
22+
}
23+
}
24+
25+
[Test, KnownBug("3590")]
26+
public void ShouldUpdate()
27+
{
28+
entity.Dates.Add(DateTime.Now);
29+
using (var s = OpenSession())
30+
{
31+
using (var tx = s.BeginTransaction())
32+
{
33+
s.Update(entity);
34+
tx.Commit();
35+
}
36+
}
37+
38+
using (var s = OpenSession())
39+
{
40+
using (s.BeginTransaction())
41+
{
42+
s.Get<Entity>(entity.Id).Dates.Count
43+
.Should().Be.EqualTo(1);
44+
}
45+
}
46+
}
47+
48+
[Test, KnownBug("3590")]
49+
public void ShouldMerge()
50+
{
51+
entity.Dates.Add(DateTime.Now);
52+
using (var s = OpenSession())
53+
{
54+
using (var tx = s.BeginTransaction())
55+
{
56+
s.Merge(entity);
57+
tx.Commit();
58+
}
59+
}
60+
61+
using (var s = OpenSession())
62+
{
63+
using (s.BeginTransaction())
64+
{
65+
s.Get<Entity>(entity.Id).Dates.Count
66+
.Should().Be.EqualTo(1);
67+
}
68+
}
69+
}
70+
71+
protected override void OnTearDown()
72+
{
73+
using (var s = OpenSession())
74+
{
75+
using (var tx = s.BeginTransaction())
76+
{
77+
s.Delete(s.Get<Entity>(entity.Id));
78+
tx.Commit();
79+
}
80+
}
81+
}
82+
}
83+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
namespace="NHibernate.Test.NHSpecificTest.NH3590"
4+
assembly="NHibernate.Test">
5+
6+
<class name="Entity">
7+
<id name="Id"
8+
type="guid">
9+
<generator class="guid.comb" />
10+
</id>
11+
<set name="Dates">
12+
<key column="entity_id" />
13+
<element column="Date" type="DateTime"/>
14+
</set>
15+
</class>
16+
</hibernate-mapping>

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,8 @@
11551155
<Compile Include="NHSpecificTest\ProxyValidator\ShouldBeProxiableTests.cs" />
11561156
<Compile Include="NHSpecificTest\NH2898\ItemWithLazyProperty.cs" />
11571157
<Compile Include="NHSpecificTest\NH2898\Fixture.cs" />
1158+
<Compile Include="NHSpecificTest\NH3590\Entity.cs" />
1159+
<Compile Include="NHSpecificTest\NH3590\Fixture.cs" />
11581160
<Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\Fixture.cs" />
11591161
<Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\Model.cs" />
11601162
<Compile Include="NHSpecificTest\SqlConverterAndMultiQuery\SqlConverter.cs" />
@@ -3009,6 +3011,7 @@
30093011
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
30103012
</ItemGroup>
30113013
<ItemGroup>
3014+
<EmbeddedResource Include="NHSpecificTest\NH3590\Mappings.hbm.xml" />
30123015
<EmbeddedResource Include="NHSpecificTest\NH3377\Mappings.hbm.xml" />
30133016
<EmbeddedResource Include="NHSpecificTest\NH2865\Mappings.hbm.xml" />
30143017
<EmbeddedResource Include="NHSpecificTest\NH2756\Mappings.hbm.xml" />

src/NHibernate/ISession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace NHibernate
1818
/// transaction. (Long transactions might span several database transactions.)
1919
/// </para>
2020
/// <para>
21-
/// The main function of the <c>ISession</c> is to offer create, find and delete operations
21+
/// The main function of the <c>ISession</c> is to offer create, find, update, and delete operations
2222
/// for instances of mapped entity classes. Instances may exist in one of two states:
2323
/// <list type="bullet">
2424
/// <item>transient: not associated with any <c>ISession</c></item>

src/NHibernate/Linq/DefaultQueryProvider.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ public class DefaultQueryProvider : INhQueryProvider
2020
{
2121
private static readonly MethodInfo CreateQueryMethodDefinition = ReflectionHelper.GetMethodDefinition((DefaultQueryProvider p) => p.CreateQuery<object>(null));
2222

23+
private readonly WeakReference _session;
24+
2325
public DefaultQueryProvider(ISessionImplementor session)
2426
{
25-
Session = session;
27+
_session = new WeakReference(session, true);
2628
}
2729

28-
protected virtual ISessionImplementor Session { get; private set; }
29-
30-
#region IQueryProvider Members
30+
protected virtual ISessionImplementor Session
31+
{
32+
get { return _session.Target as ISessionImplementor; }
33+
}
3134

3235
public virtual object Execute(Expression expression)
3336
{
@@ -47,16 +50,14 @@ public virtual IQueryable CreateQuery(Expression expression)
4750
{
4851
MethodInfo m = CreateQueryMethodDefinition.MakeGenericMethod(expression.Type.GetGenericArguments()[0]);
4952

50-
return (IQueryable) m.Invoke(this, new[] {expression});
53+
return (IQueryable) m.Invoke(this, new object[] {expression});
5154
}
5255

5356
public virtual IQueryable<T> CreateQuery<T>(Expression expression)
5457
{
5558
return new NhQueryable<T>(this, expression);
5659
}
5760

58-
#endregion
59-
6061
public virtual object ExecuteFuture(Expression expression)
6162
{
6263
IQuery query;
@@ -92,7 +93,6 @@ protected virtual object ExecuteFutureQuery(NhLinqExpression nhLinqExpression, I
9293

9394
object result = method.Invoke(query, new object[0]);
9495

95-
9696
if (nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer != null)
9797
{
9898
((IDelayedValue) result).ExecuteOnEval = nhQuery.ExpressionToHqlTranslationResults.PostExecuteTransformer;

0 commit comments

Comments
 (0)