Skip to content

Commit 6d97fa9

Browse files
committed
Reintroduced PersistenceConfiguration methods (but marked them as obsolete) to maintain backwards compatibility
1 parent 448bba9 commit 6d97fa9

File tree

3 files changed

+193
-55
lines changed

3 files changed

+193
-55
lines changed

src/FluentNHibernate.Testing/Cfg/Db/PersistenceConfigurationTester.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,50 @@ public void Use_Reflection_Optimizer_should_set_value_to_const_true()
7676

7777
}
7878

79+
#pragma warning disable 612,618
80+
81+
[Test]
82+
public void Provider_Class_should_set_property_value()
83+
{
84+
_config.Cache(c => c
85+
.ProviderClass("foo"));
86+
ValueOf("cache.provider_class").ShouldEqual("foo");
87+
88+
}
89+
90+
[Test]
91+
public void Use_Minimal_Puts_should_set_value_to_const_true()
92+
{
93+
_config.Cache(c => c
94+
.UseMinimalPuts());
95+
ValueOf("cache.use_minimal_puts").ShouldEqual("true");
96+
}
97+
98+
[Test]
99+
public void Use_Query_Cache_should_set_value_to_const_true()
100+
{
101+
_config.Cache(c => c
102+
.UseQueryCache());
103+
ValueOf("cache.use_query_cache").ShouldEqual("true");
104+
}
105+
106+
[Test]
107+
public void Query_Cache_Factory_should_set_property_value()
108+
{
109+
_config.Cache(c => c
110+
.QueryCacheFactory("foo"));
111+
ValueOf("cache.query_cache_factory").ShouldEqual("foo");
112+
}
113+
114+
[Test]
115+
public void Region_Prefix_should_set_property_value()
116+
{
117+
_config.Cache(c => c
118+
.RegionPrefix("foo"));
119+
ValueOf("cache.region_prefix").ShouldEqual("foo");
120+
}
121+
#pragma warning restore 612,618
122+
79123
[Test]
80124
public void Query_Substitutions_should_set_property_value()
81125
{

src/FluentNHibernate.Testing/Cfg/FluentConfigurationTests.cs

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,35 @@ public void ShouldGetAConfigurationIfEverythingIsOK()
126126
configuration.ShouldNotBeNull();
127127
}
128128

129-
[Test]
130-
public void ShouldSetCurrentSessionContext()
129+
[Test]
130+
public void ShouldSetCurrentSessionContext() { var configuration = Fluently.Configure() .CurrentSessionContext("thread_static") .BuildConfiguration();
131+
configuration.Properties["current_session_context_class"].ShouldEqual("thread_static"); }
132+
133+
[Test]
134+
public void ShouldSetCurrentSessionContextUsingGeneric() { var configuration = Fluently.Configure() .CurrentSessionContext<NHibernate.Context.ThreadStaticSessionContext>() .BuildConfiguration();
135+
configuration.Properties["current_session_context_class"].ShouldEqual(typeof(NHibernate.Context.ThreadStaticSessionContext).AssemblyQualifiedName); }
136+
137+
#pragma warning disable 612,618
138+
[Test]
139+
public void ShouldSetCurrentSessionContext_Obsolete()
131140
{
132141
var configuration = Fluently.Configure()
133-
.CurrentSessionContext("thread_static")
142+
.Database(SQLiteConfiguration.Standard.CurrentSessionContext("thread_static").InMemory)
134143
.BuildConfiguration();
135144

136145
configuration.Properties["current_session_context_class"].ShouldEqual("thread_static");
137146
}
138147

139148
[Test]
140-
public void ShouldSetCurrentSessionContextUsingGeneric()
149+
public void ShouldSetCurrentSessionContextUsingGeneric_Obsolete()
141150
{
142151
var configuration = Fluently.Configure()
143-
.CurrentSessionContext<NHibernate.Context.ThreadStaticSessionContext>()
152+
.Database(SQLiteConfiguration.Standard.CurrentSessionContext<NHibernate.Context.ThreadStaticSessionContext>())
144153
.BuildConfiguration();
145154

146155
configuration.Properties["current_session_context_class"].ShouldEqual(typeof(NHibernate.Context.ThreadStaticSessionContext).AssemblyQualifiedName);
147156
}
157+
#pragma warning restore 612,618
148158

149159
[Test]
150160
public void ShouldSetConnectionIsolationLevel()
@@ -156,55 +166,7 @@ public void ShouldSetConnectionIsolationLevel()
156166
configuration.Properties["connection.isolation"].ShouldEqual("ReadUncommitted");
157167
}
158168

159-
[Test]
160-
public void Use_Minimal_Puts_should_set_value_to_const_true()
161-
{
162-
var configuration = Fluently.Configure()
163-
.Cache(x => x.UseMinimalPuts())
164-
.BuildConfiguration();
165-
166-
configuration.Properties.ShouldContain("cache.use_minimal_puts", "true");
167-
}
168-
169-
[Test]
170-
public void Use_Query_Cache_should_set_value_to_const_true()
171-
{
172-
var configuration = Fluently.Configure()
173-
.Cache(x => x.UseQueryCache())
174-
.BuildConfiguration();
175-
176-
configuration.Properties.ShouldContain("cache.use_query_cache", "true");
177-
}
178-
179-
[Test]
180-
public void Query_Cache_Factory_should_set_property_value()
181-
{
182-
var configuration = Fluently.Configure()
183-
.Cache(x => x.QueryCacheFactory("foo"))
184-
.BuildConfiguration();
185-
186-
configuration.Properties.ShouldContain("cache.query_cache_factory", "foo");
187-
}
188-
189-
[Test]
190-
public void Region_Prefix_should_set_property_value()
191-
{
192-
var configuration = Fluently.Configure()
193-
.Cache(x => x.RegionPrefix("foo"))
194-
.BuildConfiguration();
195-
196-
configuration.Properties.ShouldContain("cache.region_prefix", "foo");
197-
}
198-
199-
[Test]
200-
public void Provider_Class_should_set_property_value()
201-
{
202-
var configuration = Fluently.Configure()
203-
.Cache(x => x.ProviderClass("foo"))
204-
.BuildConfiguration();
205-
206-
}
207-
}
169+
[Test] public void Use_Minimal_Puts_should_set_value_to_const_true() { var configuration = Fluently.Configure() .Cache(x => x.UseMinimalPuts()) .BuildConfiguration(); configuration.Properties.ShouldContain("cache.use_minimal_puts", "true"); } [Test] public void Use_Query_Cache_should_set_value_to_const_true() { var configuration = Fluently.Configure() .Cache(x => x.UseQueryCache()) .BuildConfiguration(); configuration.Properties.ShouldContain("cache.use_query_cache", "true"); } [Test] public void Query_Cache_Factory_should_set_property_value() { var configuration = Fluently.Configure() .Cache(x => x.QueryCacheFactory("foo")) .BuildConfiguration(); configuration.Properties.ShouldContain("cache.query_cache_factory", "foo"); } [Test] public void Region_Prefix_should_set_property_value() { var configuration = Fluently.Configure() .Cache(x => x.RegionPrefix("foo")) .BuildConfiguration(); configuration.Properties.ShouldContain("cache.region_prefix", "foo"); } [Test] public void Provider_Class_should_set_property_value() { var configuration = Fluently.Configure() .Cache(x => x.ProviderClass("foo")) .BuildConfiguration(); } }
208170

209171
[TestFixture]
210172
public class InvalidFluentConfigurationTests

src/FluentNHibernate/Cfg/Db/PersistenceConfiguration.cs

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,27 @@ public abstract class PersistenceConfiguration<TThisConfiguration, TConnectionSt
2828
protected const string ShowSqlKey = NHibEnvironment.ShowSql;
2929
protected const string FormatSqlKey = NHibEnvironment.FormatSql;
3030

31+
protected const string CollectionTypeFactoryClassKey = NHibernate.Cfg.Environment.CollectionTypeFactoryClass;
3132
protected const string ConnectionProviderKey = NHibEnvironment.ConnectionProvider;
3233
protected const string DefaultConnectionProviderClassName = "NHibernate.Connection.DriverConnectionProvider";
3334
protected const string DriverClassKey = NHibEnvironment.ConnectionDriver;
3435
protected const string ConnectionStringKey = NHibEnvironment.ConnectionString;
3536
protected const string IsolationLevelKey = NHibEnvironment.Isolation;
37+
protected const string ProxyFactoryFactoryClassKey = "proxyfactory.factory_class";
38+
protected const string DefaultProxyFactoryFactoryClassName = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";
3639
protected const string AdoNetBatchSizeKey = NHibEnvironment.BatchSize;
40+
protected const string CurrentSessionContextClassKey = "current_session_context_class";
3741

3842
private readonly Dictionary<string, string> values = new Dictionary<string, string>();
3943

4044
private bool nextBoolSettingValue = true;
4145
private readonly TConnectionString connectionString;
46+
private readonly CacheSettingsBuilder cache = new CacheSettingsBuilder();
4247

4348
protected PersistenceConfiguration()
4449
{
4550
values[ConnectionProviderKey] = DefaultConnectionProviderClassName;
51+
values[ProxyFactoryFactoryClassKey] = DefaultProxyFactoryFactoryClassName;
4652
connectionString = new TConnectionString();
4753
}
4854

@@ -51,14 +57,22 @@ protected virtual IDictionary<string, string> CreateProperties()
5157
if (connectionString.IsDirty)
5258
Raw(ConnectionStringKey, connectionString.Create());
5359

60+
if (cache.IsDirty)
61+
{
62+
foreach (var pair in cache.Create())
63+
{
64+
Raw(pair.Key, pair.Value);
65+
}
66+
}
67+
5468
return values;
5569
}
5670

5771
public NHibConfiguration ConfigureProperties(NHibConfiguration nhibernateConfig)
5872
{
5973
var settings = CreateProperties();
6074

61-
nhibernateConfig.AddProperties(settings);
75+
nhibernateConfig.SetProperties(settings);
6276

6377
return nhibernateConfig;
6478
}
@@ -263,6 +277,25 @@ public TThisConfiguration ConnectionString(string value)
263277
return (TThisConfiguration)this;
264278
}
265279

280+
/// <summary>
281+
/// Configure caching.
282+
/// </summary>
283+
/// <example>
284+
/// Cache(x =>
285+
/// {
286+
/// x.UseQueryCache();
287+
/// x.UseMinimalPuts();
288+
/// });
289+
/// </example>
290+
/// <param name="cacheExpression">Closure for configuring caching</param>
291+
/// <returns>Configuration builder</returns>
292+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().Cache(...))")]
293+
public TThisConfiguration Cache(Action<CacheSettingsBuilder> cacheExpression)
294+
{
295+
cacheExpression(cache);
296+
return (TThisConfiguration)this;
297+
}
298+
266299
/// <summary>
267300
/// Sets a raw property on the NHibernate configuration. Use this method
268301
/// if there isn't a specific option available in the API.
@@ -276,6 +309,82 @@ public TThisConfiguration Raw(string key, string value)
276309
return (TThisConfiguration) this;
277310
}
278311

312+
/// <summary>
313+
/// Sets the collectiontype.factory_class property.
314+
/// NOTE: NHibernate 2.1 only
315+
/// </summary>
316+
/// <param name="collectionTypeFactoryClass">factory class</param>
317+
/// <returns>Configuration</returns>
318+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().CollectionTypeFactory(...))")]
319+
public TThisConfiguration CollectionTypeFactory(string collectionTypeFactoryClass)
320+
{
321+
values[CollectionTypeFactoryClassKey] = collectionTypeFactoryClass;
322+
return (TThisConfiguration)this;
323+
}
324+
325+
/// <summary>
326+
/// Sets the collectiontype.factory_class property.
327+
/// NOTE: NHibernate 2.1 only
328+
/// </summary>
329+
/// <param name="collectionTypeFactoryClass">factory class</param>
330+
/// <returns>Configuration</returns>
331+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().CollectionTypeFactory(...))")]
332+
public TThisConfiguration CollectionTypeFactory(Type collectionTypeFactoryClass)
333+
{
334+
values[CollectionTypeFactoryClassKey] = collectionTypeFactoryClass.AssemblyQualifiedName;
335+
return (TThisConfiguration)this;
336+
}
337+
338+
/// <summary>
339+
/// Sets the collectiontype.factory_class property.
340+
/// NOTE: NHibernate 2.1 only
341+
/// </summary>
342+
/// <typeparam name="TCollectionTypeFactory">factory class</typeparam>
343+
/// <returns>Configuration</returns>
344+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().CollectionTypeFactory(...))")]
345+
public TThisConfiguration CollectionTypeFactory<TCollectionTypeFactory>() where TCollectionTypeFactory : ICollectionTypeFactory
346+
{
347+
return CollectionTypeFactory(typeof(TCollectionTypeFactory));
348+
}
349+
350+
/// <summary>
351+
/// Sets the proxyfactory.factory_class property.
352+
/// NOTE: NHibernate 2.1 only
353+
/// </summary>
354+
/// <param name="proxyFactoryFactoryClass">factory class</param>
355+
/// <returns>Configuration</returns>
356+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().ProxyFactoryFactory(...))")]
357+
public TThisConfiguration ProxyFactoryFactory(string proxyFactoryFactoryClass)
358+
{
359+
values[ProxyFactoryFactoryClassKey] = proxyFactoryFactoryClass;
360+
return (TThisConfiguration)this;
361+
}
362+
363+
/// <summary>
364+
/// Sets the proxyfactory.factory_class property.
365+
/// NOTE: NHibernate 2.1 only
366+
/// </summary>
367+
/// <param name="proxyFactoryFactory">factory class</param>
368+
/// <returns>Configuration</returns>
369+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().ProxyFactoryFactory(...))")]
370+
public TThisConfiguration ProxyFactoryFactory(Type proxyFactoryFactory)
371+
{
372+
values[ProxyFactoryFactoryClassKey] = proxyFactoryFactory.AssemblyQualifiedName;
373+
return (TThisConfiguration)this;
374+
}
375+
376+
/// <summary>
377+
/// Sets the proxyfactory.factory_class property.
378+
/// NOTE: NHibernate 2.1 only
379+
/// </summary>
380+
/// <typeparam name="TProxyFactoryFactory">factory class</typeparam>
381+
/// <returns>Configuration</returns>
382+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().ProxyFactoryFactory(...))")]
383+
public TThisConfiguration ProxyFactoryFactory<TProxyFactoryFactory>() where TProxyFactoryFactory : IProxyFactoryFactory
384+
{
385+
return ProxyFactoryFactory(typeof(TProxyFactoryFactory));
386+
}
387+
279388
/// <summary>
280389
/// Sets the adonet.batch_size property.
281390
/// </summary>
@@ -287,6 +396,29 @@ public TThisConfiguration AdoNetBatchSize(int size)
287396
return (TThisConfiguration)this;
288397
}
289398

399+
/// <summary>
400+
/// Sets the current_session_context_class property.
401+
/// </summary>
402+
/// <param name="currentSessionContextClass">current session context class</param>
403+
/// <returns>Configuration</returns>
404+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().CurrentSessionContext(...))")]
405+
public TThisConfiguration CurrentSessionContext(string currentSessionContextClass)
406+
{
407+
values[CurrentSessionContextClassKey] = currentSessionContextClass;
408+
return (TThisConfiguration)this;
409+
}
410+
411+
/// <summary>
412+
/// Sets the current_session_context_class property.
413+
/// </summary>
414+
/// <typeparam name="TSessionContext">Implementation of ICurrentSessionContext to use</typeparam>
415+
/// <returns>Configuration</returns>
416+
[Obsolete("Moved to FluentConfiguration (Fluently.Configure().CurrentSessionContext(...))")]
417+
public TThisConfiguration CurrentSessionContext<TSessionContext>() where TSessionContext : NHibernate.Context.ICurrentSessionContext
418+
{
419+
return CurrentSessionContext(typeof(TSessionContext).AssemblyQualifiedName);
420+
}
421+
290422
/// <summary>
291423
/// Sets the connection isolation level. NHibernate setting: connection.isolation
292424
/// </summary>

0 commit comments

Comments
 (0)