Skip to content

Commit 38afb8a

Browse files
bahusoidfredericDelaporte
authored andcommitted
Remove AbstractLazyInitializer unused field
1 parent e11ec16 commit 38afb8a

File tree

2 files changed

+21
-40
lines changed

2 files changed

+21
-40
lines changed

src/NHibernate/Async/Proxy/AbstractLazyInitializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
using System;
1212
using NHibernate.Engine;
13-
using NHibernate.Persister.Entity;
1413

1514
namespace NHibernate.Proxy
1615
{

src/NHibernate/Proxy/AbstractLazyInitializer.cs

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using NHibernate.Engine;
3-
using NHibernate.Persister.Entity;
43

54
namespace NHibernate.Proxy
65
{
@@ -30,7 +29,6 @@ public abstract partial class AbstractLazyInitializer : ILazyInitializer
3029
private bool unwrap;
3130
private readonly string _entityName;
3231
private bool readOnly;
33-
private bool? readOnlyBeforeAttachedToSession;
3432

3533
/// <summary>
3634
/// Create a LazyInitializer to handle all of the Methods/Properties that are called
@@ -43,54 +41,40 @@ protected internal AbstractLazyInitializer(string entityName, object id, ISessio
4341
{
4442
_id = id;
4543
_entityName = entityName;
46-
47-
if (session == null)
48-
UnsetSession();
49-
else
50-
SetSession(session);
44+
45+
SetSession(session);
5146
}
5247

5348
/// <inheritdoc />
5449
public void SetSession(ISessionImplementor s)
5550
{
56-
if (s != _session)
51+
if (s == _session)
52+
return;
53+
54+
// check for s == null first, since it is least expensive
55+
if (s == null)
5756
{
58-
// check for s == null first, since it is least expensive
59-
if (s == null)
60-
{
61-
UnsetSession();
62-
}
63-
else if (IsConnectedToSession)
64-
{
65-
//TODO: perhaps this should be some other RuntimeException...
66-
throw new HibernateException("illegally attempted to associate a proxy with two open Sessions");
67-
}
68-
else
69-
{
70-
// s != null
71-
_session = s;
72-
if (readOnlyBeforeAttachedToSession == null)
73-
{
74-
// use the default read-only/modifiable setting
75-
IEntityPersister persister = s.Factory.GetEntityPersister(_entityName);
76-
SetReadOnly(s.PersistenceContext.DefaultReadOnly || !persister.IsMutable);
77-
}
78-
else
79-
{
80-
// use the read-only/modifiable setting indicated during deserialization
81-
SetReadOnly(readOnlyBeforeAttachedToSession.Value);
82-
readOnlyBeforeAttachedToSession = null;
83-
}
84-
}
57+
UnsetSession();
58+
return;
8559
}
60+
61+
if (IsConnectedToSession)
62+
{
63+
//TODO: perhaps this should be some other RuntimeException...
64+
throw new HibernateException("illegally attempted to associate a proxy with two open Sessions");
65+
}
66+
67+
_session = s;
68+
69+
// use the default read-only/modifiable setting
70+
SetReadOnly(s.PersistenceContext.DefaultReadOnly || !s.Factory.GetEntityPersister(_entityName).IsMutable);
8671
}
8772

8873
/// <inheritdoc />
8974
public void UnsetSession()
9075
{
9176
_session = null;
9277
readOnly = false;
93-
readOnlyBeforeAttachedToSession = null;
9478
}
9579

9680
protected internal bool IsConnectedToSession
@@ -275,9 +259,7 @@ private object GetProxyOrNull()
275259

276260
private void SetReadOnly(bool readOnly)
277261
{
278-
IEntityPersister persister = _session.Factory.GetEntityPersister(_entityName);
279-
280-
if (!persister.IsMutable && !readOnly)
262+
if (!readOnly && !_session.Factory.GetEntityPersister(_entityName).IsMutable)
281263
{
282264
throw new InvalidOperationException("cannot make proxies for immutable entities modifiable");
283265
}

0 commit comments

Comments
 (0)