Skip to content

Commit 5e24f5c

Browse files
NH-4003 - renaming then converting to properties some methods, to be squashed or dropped.
1 parent 4343cef commit 5e24f5c

File tree

7 files changed

+51
-53
lines changed

7 files changed

+51
-53
lines changed

src/NHibernate.Test/SessionBuilder/Fixture.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void CanSetAutoClose()
3737
private void CanSetAutoClose<T>(T sb) where T : ISessionBuilder<T>
3838
{
3939
var options = (ISessionCreationOptions)sb;
40-
CanSet(sb, sb.AutoClose, options.ShouldAutoClose,
40+
CanSet(sb, sb.AutoClose, () => options.ShouldAutoClose,
4141
sb is ISharedSessionBuilder ssb ? ssb.AutoClose : default(Func<ISharedSessionBuilder>),
4242
// initial values
4343
false,
@@ -63,34 +63,34 @@ private void CanSetConnection<T>(T sb) where T : ISessionBuilder<T>
6363
try
6464
{
6565
var options = (ISessionCreationOptions)sb;
66-
Assert.IsNull(options.GetConnection(), $"{sbType}: Initial value");
66+
Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: Initial value");
6767
var fsb = sb.Connection(conn);
68-
Assert.AreEqual(conn, options.GetConnection(), $"{sbType}: After call with a connection");
68+
Assert.AreEqual(conn, options.UserSuppliedConnection, $"{sbType}: After call with a connection");
6969
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with a connection");
7070

7171
if (sb is ISharedSessionBuilder ssb)
7272
{
7373
var sharedOptions = (ISharedSessionCreationOptions)options;
74-
Assert.IsFalse(sharedOptions.IsTransactionCoordinatorShared(), $"{sbType}: Transaction coordinator shared before sharing");
75-
Assert.IsNull(sharedOptions.GetConnectionManager(), $"{sbType}: Connection manager shared before sharing");
74+
Assert.IsFalse(sharedOptions.IsTransactionCoordinatorShared, $"{sbType}: Transaction coordinator shared before sharing");
75+
Assert.IsNull(sharedOptions.ConnectionManager, $"{sbType}: Connection manager shared before sharing");
7676

7777
var fssb = ssb.Connection();
7878
// Sharing connection shares the connection manager, not the connection.
79-
Assert.IsNull(options.GetConnection(), $"{sbType}: After call with previous session connection");
80-
Assert.IsTrue(sharedOptions.IsTransactionCoordinatorShared(), $"{sbType}: Transaction coordinator not shared after sharing");
81-
Assert.IsNotNull(sharedOptions.GetConnectionManager(), $"{sbType}: Connection manager not shared after sharing");
79+
Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with previous session connection");
80+
Assert.IsTrue(sharedOptions.IsTransactionCoordinatorShared, $"{sbType}: Transaction coordinator not shared after sharing");
81+
Assert.IsNotNull(sharedOptions.ConnectionManager, $"{sbType}: Connection manager not shared after sharing");
8282
Assert.AreEqual(sb, fssb, $"{sbType}: Unexpected fluent return on shared");
8383

8484
fsb = sb.Connection(null);
85-
Assert.IsNull(options.GetConnection(), $"{sbType}: After call with null");
86-
Assert.IsFalse(sharedOptions.IsTransactionCoordinatorShared(), $"{sbType}: Transaction coordinator shared after un-sharing");
87-
Assert.IsNull(sharedOptions.GetConnectionManager(), $"{sbType}: Connection manager shared after un-sharing");
85+
Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with null");
86+
Assert.IsFalse(sharedOptions.IsTransactionCoordinatorShared, $"{sbType}: Transaction coordinator shared after un-sharing");
87+
Assert.IsNull(sharedOptions.ConnectionManager, $"{sbType}: Connection manager shared after un-sharing");
8888
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after un-sharing");
8989
}
9090
else
9191
{
9292
fsb = sb.Connection(null);
93-
Assert.IsNull(options.GetConnection(), $"{sbType}: After call with null");
93+
Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with null");
9494
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with null");
9595
}
9696
}
@@ -109,13 +109,13 @@ public void CanSetConnectionOnStateless()
109109
try
110110
{
111111
var options = (ISessionCreationOptions)sb;
112-
Assert.IsNull(options.GetConnection(), $"{sbType}: Initial value");
112+
Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: Initial value");
113113
var fsb = sb.Connection(conn);
114-
Assert.AreEqual(conn, options.GetConnection(), $"{sbType}: After call with a connection");
114+
Assert.AreEqual(conn, options.UserSuppliedConnection, $"{sbType}: After call with a connection");
115115
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with a connection");
116116

117117
fsb = sb.Connection(null);
118-
Assert.IsNull(options.GetConnection(), $"{sbType}: After call with null");
118+
Assert.IsNull(options.UserSuppliedConnection, $"{sbType}: After call with null");
119119
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with null");
120120
}
121121
finally
@@ -138,7 +138,7 @@ public void CanSetConnectionReleaseMode()
138138
private void CanSetConnectionReleaseMode<T>(T sb) where T : ISessionBuilder<T>
139139
{
140140
var options = (ISessionCreationOptions)sb;
141-
CanSet(sb, sb.ConnectionReleaseMode, options.GetConnectionReleaseMode,
141+
CanSet(sb, sb.ConnectionReleaseMode, () => options.SessionConnectionReleaseMode,
142142
sb is ISharedSessionBuilder ssb ? ssb.ConnectionReleaseMode : default(Func<ISharedSessionBuilder>),
143143
// initial values
144144
sessions.Settings.ConnectionReleaseMode,
@@ -160,7 +160,7 @@ public void CanSetFlushMode()
160160
private void CanSetFlushMode<T>(T sb) where T : ISessionBuilder<T>
161161
{
162162
var options = (ISessionCreationOptions)sb;
163-
CanSet(sb, sb.FlushMode, options.GetInitialSessionFlushMode,
163+
CanSet(sb, sb.FlushMode, () => options.InitialSessionFlushMode,
164164
sb is ISharedSessionBuilder ssb ? ssb.FlushMode : default(Func<ISharedSessionBuilder>),
165165
// initial values
166166
sessions.Settings.DefaultFlushMode,
@@ -186,22 +186,22 @@ private void CanSetInterceptor<T>(T sb) where T : ISessionBuilder<T>
186186
var interceptor = new EmptyInterceptor();
187187
var options = (ISessionCreationOptions)sb;
188188

189-
Assert.AreEqual(sessions.Interceptor, options.GetInterceptor(), $"{sbType}: Initial value");
189+
Assert.AreEqual(sessions.Interceptor, options.SessionInterceptor, $"{sbType}: Initial value");
190190
var fsb = sb.Interceptor(interceptor);
191-
Assert.AreEqual(interceptor, options.GetInterceptor(), $"{sbType}: After call with an interceptor");
191+
Assert.AreEqual(interceptor, options.SessionInterceptor, $"{sbType}: After call with an interceptor");
192192
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after call with an interceptor");
193193

194194
if (sb is ISharedSessionBuilder ssb)
195195
{
196196
var fssb = ssb.Interceptor();
197-
Assert.AreEqual(EmptyInterceptor.Instance, options.GetInterceptor(), $"{sbType}: After call with shared interceptor");
197+
Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After call with shared interceptor");
198198
Assert.AreEqual(sb, fssb, $"{sbType}: Unexpected fluent return on shared");
199199
}
200200

201201
Assert.Throws<ArgumentNullException>(() => sb.Interceptor(null), $"{sbType}: After call with null");
202202

203203
fsb = sb.NoInterceptor();
204-
Assert.AreEqual(EmptyInterceptor.Instance, options.GetInterceptor(), $"{sbType}: After no call");
204+
Assert.AreEqual(EmptyInterceptor.Instance, options.SessionInterceptor, $"{sbType}: After no call");
205205
Assert.AreEqual(sb, fsb, $"{sbType}: Unexpected fluent return after no call");
206206
}
207207

src/NHibernate/Impl/AbstractSessionImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ protected internal AbstractSessionImpl(ISessionFactoryImplementor factory, ISess
4646
{
4747
_factory = factory;
4848
Timestamp = factory.Settings.CacheProvider.NextTimestamp();
49-
_flushMode = options.GetInitialSessionFlushMode();
50-
Interceptor = options.GetInterceptor() ?? EmptyInterceptor.Instance;
49+
_flushMode = options.InitialSessionFlushMode;
50+
Interceptor = options.SessionInterceptor ?? EmptyInterceptor.Instance;
5151
}
5252

5353
#region ISessionImplementor Members

src/NHibernate/Impl/ISessionCreationOptions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ namespace NHibernate.Impl
88
/// <seealso cref="ISessionBuilder"/>
99
public interface ISessionCreationOptions
1010
{
11-
// NH note: it is tempting to convert them to properties, but then their names conflict
12-
// with ISessionBuilder, which is implemented along this interface.
13-
FlushMode GetInitialSessionFlushMode();
11+
// NH note: naming "adjusted" for converting Java methods to properties while avoiding conflicts with
12+
// ISessionBuilder.
13+
FlushMode InitialSessionFlushMode { get; }
1414

15-
bool ShouldAutoClose();
15+
bool ShouldAutoClose { get; }
1616

17-
DbConnection GetConnection();
17+
DbConnection UserSuppliedConnection { get; }
1818

19-
IInterceptor GetInterceptor();
19+
IInterceptor SessionInterceptor { get; }
2020

2121
// Todo: port PhysicalConnectionHandlingMode
22-
ConnectionReleaseMode GetConnectionReleaseMode();
22+
ConnectionReleaseMode SessionConnectionReleaseMode { get; }
2323
}
2424
}

src/NHibernate/Impl/ISharedSessionCreationOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace NHibernate.Impl
1010
public interface ISharedSessionCreationOptions : ISessionCreationOptions
1111
{
1212
// NH note: not converting them to properties for staying in sync with ISessionCreationOptions.
13-
bool IsTransactionCoordinatorShared();
13+
bool IsTransactionCoordinatorShared { get; }
1414
// NH different implementation: need to port Hibernate transaction management.
15-
ConnectionManager GetConnectionManager();
15+
ConnectionManager ConnectionManager { get; }
1616
}
1717
}

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,20 +1309,18 @@ protected void SetSelf(T self)
13091309

13101310
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13111311
// SessionCreationOptions
1312-
// NH note: it is tempting to convert them to properties, but then their names conflict
1313-
// with SessionBuilder interface.
13141312

1315-
public virtual FlushMode GetInitialSessionFlushMode() => _flushMode;
1313+
public virtual FlushMode InitialSessionFlushMode => _flushMode;
13161314

1317-
public virtual bool ShouldAutoClose() => _autoClose;
1315+
public virtual bool ShouldAutoClose => _autoClose;
13181316

1319-
public DbConnection GetConnection() => _connection;
1317+
public DbConnection UserSuppliedConnection => _connection;
13201318

13211319
// NH different implementation: Hibernate here ignore EmptyInterceptor.Instance too, resulting
13221320
// in the "NoInterceptor" being unable to override a session factory interceptor.
1323-
public virtual IInterceptor GetInterceptor() => _interceptor ?? _sessionFactory.Interceptor;
1321+
public virtual IInterceptor SessionInterceptor => _interceptor ?? _sessionFactory.Interceptor;
13241322

1325-
public virtual ConnectionReleaseMode GetConnectionReleaseMode() => _connectionReleaseMode;
1323+
public virtual ConnectionReleaseMode SessionConnectionReleaseMode => _connectionReleaseMode;
13261324

13271325
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13281326
// SessionBuilder
@@ -1400,15 +1398,15 @@ public IStatelessSessionBuilder Connection(DbConnection connection)
14001398
return this;
14011399
}
14021400

1403-
public FlushMode GetInitialSessionFlushMode() => FlushMode.Always;
1401+
public FlushMode InitialSessionFlushMode => FlushMode.Always;
14041402

1405-
public bool ShouldAutoClose() => false;
1403+
public bool ShouldAutoClose => false;
14061404

1407-
public DbConnection GetConnection() => _connection;
1405+
public DbConnection UserSuppliedConnection => _connection;
14081406

1409-
public IInterceptor GetInterceptor() => EmptyInterceptor.Instance;
1407+
public IInterceptor SessionInterceptor => EmptyInterceptor.Instance;
14101408

1411-
public ConnectionReleaseMode GetConnectionReleaseMode() => ConnectionReleaseMode.AfterTransaction;
1409+
public ConnectionReleaseMode SessionConnectionReleaseMode => ConnectionReleaseMode.AfterTransaction;
14121410
}
14131411
}
14141412
}

src/NHibernate/Impl/SessionImpl.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,22 @@ internal SessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options
189189
actionQueue = new ActionQueue(this);
190190
persistenceContext = new StatefulPersistenceContext(this);
191191

192-
autoCloseSessionEnabled = options.ShouldAutoClose();
192+
autoCloseSessionEnabled = options.ShouldAutoClose;
193193

194194
listeners = factory.EventListeners;
195-
connectionReleaseMode = options.GetConnectionReleaseMode();
195+
connectionReleaseMode = options.SessionConnectionReleaseMode;
196196

197-
if (options is ISharedSessionCreationOptions sharedOptions && sharedOptions.IsTransactionCoordinatorShared())
197+
if (options is ISharedSessionCreationOptions sharedOptions && sharedOptions.IsTransactionCoordinatorShared)
198198
{
199199
// NH specific implementation: need to port Hibernate transaction management.
200200
_transactionCoordinatorShared = true;
201-
if (options.GetConnection() != null)
201+
if (options.UserSuppliedConnection != null)
202202
throw new SessionException("Cannot simultaneously share transaction context and specify connection");
203-
connectionManager = sharedOptions.GetConnectionManager();
203+
connectionManager = sharedOptions.ConnectionManager;
204204
}
205205
else
206206
{
207-
connectionManager = new ConnectionManager(this, options.GetConnection(), connectionReleaseMode, Interceptor);
207+
connectionManager = new ConnectionManager(this, options.UserSuppliedConnection, connectionReleaseMode, Interceptor);
208208
}
209209

210210
if (factory.Statistics.IsStatisticsEnabled)
@@ -2556,10 +2556,10 @@ public override ISharedSessionBuilder Connection(DbConnection connection)
25562556
// SharedSessionCreationOptions
25572557

25582558
// NH note: not converting them to properties for staying in sync with ISessionCreationOptions.
2559-
public virtual bool IsTransactionCoordinatorShared() => _shareTransactionContext;
2559+
public virtual bool IsTransactionCoordinatorShared => _shareTransactionContext;
25602560

25612561
// NH different implementation: need to port Hibernate transaction management.
2562-
public ConnectionManager GetConnectionManager() => _shareTransactionContext ? _session.ConnectionManager : null;
2562+
public ConnectionManager ConnectionManager => _shareTransactionContext ? _session.ConnectionManager : null;
25632563
}
25642564
}
25652565
}

src/NHibernate/Impl/StatelessSessionImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal StatelessSessionImpl(SessionFactoryImpl factory, ISessionCreationOption
3838
using (new SessionIdLoggingContext(SessionId))
3939
{
4040
temporaryPersistenceContext = new StatefulPersistenceContext(this);
41-
connectionManager = new ConnectionManager(this, options.GetConnection(), ConnectionReleaseMode.AfterTransaction,
41+
connectionManager = new ConnectionManager(this, options.UserSuppliedConnection, ConnectionReleaseMode.AfterTransaction,
4242
EmptyInterceptor.Instance);
4343

4444
if (log.IsDebugEnabled)

0 commit comments

Comments
 (0)