@@ -98,7 +98,6 @@ public Configuration(SerializationInfo info, StreamingContext context)
98
98
FilterDefinitions = GetSerialedObject < IDictionary < string , FilterDefinition > > ( info , "filterDefinitions" ) ;
99
99
Imports = GetSerialedObject < IDictionary < string , string > > ( info , "imports" ) ;
100
100
interceptor = GetSerialedObject < IInterceptor > ( info , "interceptor" ) ;
101
- mapping = GetSerialedObject < IMapping > ( info , "mapping" ) ;
102
101
NamedQueries = GetSerialedObject < IDictionary < string , NamedQueryDefinition > > ( info , "namedQueries" ) ;
103
102
NamedSQLQueries = GetSerialedObject < IDictionary < string , NamedSQLQueryDefinition > > ( info , "namedSqlQueries" ) ;
104
103
namingStrategy = GetSerialedObject < INamingStrategy > ( info , "namingStrategy" ) ;
@@ -124,7 +123,6 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
124
123
{
125
124
ConfigureProxyFactoryFactory ( ) ;
126
125
SecondPassCompile ( ) ;
127
- Validate ( ) ;
128
126
129
127
info . AddValue ( "entityNotFoundDelegate" , EntityNotFoundDelegate ) ;
130
128
@@ -139,7 +137,6 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
139
137
info . AddValue ( "filterDefinitions" , FilterDefinitions ) ;
140
138
info . AddValue ( "imports" , Imports ) ;
141
139
info . AddValue ( "interceptor" , interceptor ) ;
142
- info . AddValue ( "mapping" , mapping ) ;
143
140
info . AddValue ( "namedQueries" , NamedQueries ) ;
144
141
info . AddValue ( "namedSqlQueries" , NamedSQLQueries ) ;
145
142
info . AddValue ( "namingStrategy" , namingStrategy ) ;
@@ -246,10 +243,6 @@ private class StaticDialectMappingWrapper : IMapping
246
243
{
247
244
private readonly IMapping _mapping ;
248
245
249
- public StaticDialectMappingWrapper ( IMapping mapping ) : this ( mapping , mapping . Dialect )
250
- {
251
- }
252
-
253
246
public StaticDialectMappingWrapper ( IMapping mapping , Dialect . Dialect dialect )
254
247
{
255
248
_mapping = mapping ;
@@ -279,23 +272,25 @@ public bool HasNonIdentifierPropertyNamedId(string className)
279
272
public Dialect . Dialect Dialect { get ; }
280
273
}
281
274
282
- private IMapping mapping ;
283
-
284
275
protected Configuration ( SettingsFactory settingsFactory )
285
276
{
286
- InitBlock ( ) ;
287
277
this . settingsFactory = settingsFactory ;
288
278
Reset ( ) ;
289
279
}
290
280
291
- private void InitBlock ( )
281
+ // Since v5.5
282
+ [ Obsolete ( "Use BuildMapping(Dialect.Dialect) instead." ) ]
283
+ public virtual IMapping BuildMapping ( )
292
284
{
293
- mapping = BuildMapping ( ) ;
285
+ return new Mapping ( this ) ;
294
286
}
295
287
296
- public virtual IMapping BuildMapping ( )
288
+ public virtual IMapping BuildMapping ( Dialect . Dialect dialect )
297
289
{
298
- return new Mapping ( this ) ;
290
+ #pragma warning disable CS0618
291
+ var mapping = BuildMapping ( ) ;
292
+ #pragma warning restore CS0618
293
+ return new StaticDialectMappingWrapper ( mapping , dialect ) ;
299
294
}
300
295
301
296
/// <summary>
@@ -552,9 +547,8 @@ private void AddValidatedDocument(NamedXmlDocument doc)
552
547
public void AddDeserializedMapping ( HbmMapping mappingDocument , string documentFileName )
553
548
{
554
549
if ( mappingDocument == null )
555
- {
556
- throw new ArgumentNullException ( "mappingDocument" ) ;
557
- }
550
+ throw new ArgumentNullException ( nameof ( mappingDocument ) ) ;
551
+
558
552
try
559
553
{
560
554
var dialect = new Lazy < Dialect . Dialect > ( ( ) => Dialect . Dialect . GetDialect ( properties ) ) ;
@@ -749,9 +743,8 @@ public Configuration AddResource(string path, Assembly assembly)
749
743
public Configuration AddResources ( IEnumerable < string > paths , Assembly assembly )
750
744
{
751
745
if ( paths == null )
752
- {
753
- throw new ArgumentNullException ( "paths" ) ;
754
- }
746
+ throw new ArgumentNullException ( nameof ( paths ) ) ;
747
+
755
748
foreach ( var path in paths )
756
749
{
757
750
AddResource ( path , assembly ) ;
@@ -938,19 +931,19 @@ public static bool IncludeAction(SchemaAction actionsSource, SchemaAction includ
938
931
/// <param name="dialect"></param>
939
932
public string [ ] GenerateSchemaCreationScript ( Dialect . Dialect dialect )
940
933
{
934
+ var mapping = BuildMapping ( dialect ) ;
941
935
SecondPassCompile ( ) ;
942
936
943
937
var defaultCatalog = GetQuotedDefaultCatalog ( dialect ) ;
944
938
var defaultSchema = GetQuotedDefaultSchema ( dialect ) ;
945
939
946
940
var script = new List < string > ( ) ;
947
941
948
- var staticDialectMapping = new StaticDialectMappingWrapper ( mapping , dialect ) ;
949
942
foreach ( var table in TableMappings )
950
943
{
951
944
if ( table . IsPhysicalTable && IncludeAction ( table . SchemaActions , SchemaAction . Export ) )
952
945
{
953
- script . Add ( table . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
946
+ script . Add ( table . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
954
947
script . AddRange ( table . SqlCommentStrings ( dialect , defaultCatalog , defaultSchema ) ) ;
955
948
}
956
949
}
@@ -963,7 +956,7 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
963
956
{
964
957
foreach ( var uk in table . UniqueKeyIterator )
965
958
{
966
- string constraintString = uk . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ;
959
+ string constraintString = uk . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ;
967
960
if ( constraintString != null )
968
961
{
969
962
script . Add ( constraintString ) ;
@@ -973,7 +966,7 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
973
966
974
967
foreach ( var index in table . IndexIterator )
975
968
{
976
- script . Add ( index . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
969
+ script . Add ( index . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
977
970
}
978
971
979
972
if ( dialect . SupportsForeignKeyConstraintInAlterTable )
@@ -982,7 +975,7 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
982
975
{
983
976
if ( fk . IsGenerated ( dialect ) && IncludeAction ( fk . ReferencedTable . SchemaActions , SchemaAction . Export ) )
984
977
{
985
- script . Add ( fk . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
978
+ script . Add ( fk . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
986
979
}
987
980
}
988
981
}
@@ -999,18 +992,18 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
999
992
{
1000
993
if ( auxDbObj . AppliesToDialect ( dialect ) )
1001
994
{
1002
- script . Add ( auxDbObj . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
995
+ script . Add ( auxDbObj . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
1003
996
}
1004
997
}
1005
998
1006
999
return script . ToArray ( ) ;
1007
1000
}
1008
1001
1009
- private void Validate ( )
1002
+ private void Validate ( IMapping mapping )
1010
1003
{
1011
- ValidateEntities ( ) ;
1004
+ ValidateEntities ( mapping ) ;
1012
1005
1013
- ValidateCollections ( ) ;
1006
+ ValidateCollections ( mapping ) ;
1014
1007
1015
1008
ValidateFilterDefs ( ) ;
1016
1009
}
@@ -1064,15 +1057,15 @@ private void ValidateFilterDefs()
1064
1057
}
1065
1058
}
1066
1059
1067
- private void ValidateCollections ( )
1060
+ private void ValidateCollections ( IMapping mapping )
1068
1061
{
1069
1062
foreach ( var col in collections . Values )
1070
1063
{
1071
1064
col . Validate ( mapping ) ;
1072
1065
}
1073
1066
}
1074
1067
1075
- private void ValidateEntities ( )
1068
+ private void ValidateEntities ( IMapping mapping )
1076
1069
{
1077
1070
bool validateProxy = PropertiesHelper . GetBoolean ( Environment . UseProxyValidator , properties , true ) ;
1078
1071
HashSet < string > allProxyErrors = null ;
@@ -1286,8 +1279,7 @@ protected virtual void ConfigureProxyFactoryFactory()
1286
1279
//http://nhibernate.jira.com/browse/NH-975
1287
1280
1288
1281
var ipff = Environment . BytecodeProvider as IInjectableProxyFactoryFactory ;
1289
- string pffClassName ;
1290
- properties . TryGetValue ( Environment . ProxyFactoryFactoryClass , out pffClassName ) ;
1282
+ properties . TryGetValue ( Environment . ProxyFactoryFactoryClass , out var pffClassName ) ;
1291
1283
if ( ipff != null && ! string . IsNullOrEmpty ( pffClassName ) )
1292
1284
{
1293
1285
ipff . SetProxyFactoryFactory ( pffClassName ) ;
@@ -1304,33 +1296,21 @@ protected virtual void ConfigureProxyFactoryFactory()
1304
1296
/// <returns>An <see cref="ISessionFactory" /> instance.</returns>
1305
1297
public ISessionFactory BuildSessionFactory ( )
1306
1298
{
1307
- var dynamicDialectMapping = mapping ;
1308
1299
// Use a mapping which does store the dialect instead of instantiating a new one
1309
1300
// at each access. The dialect does not change while building a session factory.
1310
1301
// It furthermore allows some hack on NHibernate.Spatial side to go on working,
1311
1302
// See nhibernate/NHibernate.Spatial#104
1312
- mapping = new StaticDialectMappingWrapper ( mapping ) ;
1313
- try
1314
- {
1315
- ConfigureProxyFactoryFactory ( ) ;
1316
- SecondPassCompile ( ) ;
1317
- Validate ( ) ;
1318
- Environment . VerifyProperties ( properties ) ;
1319
- Settings settings = BuildSettings ( ) ;
1303
+ var settings = BuildSettings ( ) ;
1304
+ var mapping = BuildMapping ( settings . Dialect ) ;
1305
+ ConfigureProxyFactoryFactory ( ) ;
1306
+ SecondPassCompile ( ) ;
1307
+ Validate ( mapping ) ;
1308
+ Environment . VerifyProperties ( properties ) ;
1320
1309
1321
- // Ok, don't need schemas anymore, so free them
1322
- Schemas = null ;
1310
+ // Ok, don't need schemas anymore, so free them
1311
+ Schemas = null ;
1323
1312
1324
- return new SessionFactoryImpl (
1325
- this ,
1326
- mapping ,
1327
- settings ,
1328
- GetInitializedEventListeners ( ) ) ;
1329
- }
1330
- finally
1331
- {
1332
- mapping = dynamicDialectMapping ;
1333
- }
1313
+ return new SessionFactoryImpl ( this , mapping , settings , GetInitializedEventListeners ( ) ) ;
1334
1314
}
1335
1315
1336
1316
/// <summary>
@@ -2363,13 +2343,13 @@ private static T[] AppendListeners<T>(T[] existing, T[] listenersToAdd)
2363
2343
/// <seealso cref="NHibernate.Tool.hbm2ddl.SchemaUpdate"/>
2364
2344
public string [ ] GenerateSchemaUpdateScript ( Dialect . Dialect dialect , IDatabaseMetadata databaseMetadata )
2365
2345
{
2346
+ var mapping = BuildMapping ( dialect ) ;
2366
2347
SecondPassCompile ( ) ;
2367
2348
2368
2349
var defaultCatalog = GetQuotedDefaultCatalog ( dialect ) ;
2369
2350
var defaultSchema = GetQuotedDefaultSchema ( dialect ) ;
2370
2351
2371
2352
var script = new List < string > ( 50 ) ;
2372
- var staticDialectMapping = new StaticDialectMappingWrapper ( mapping , dialect ) ;
2373
2353
foreach ( var table in TableMappings )
2374
2354
{
2375
2355
if ( table . IsPhysicalTable && IncludeAction ( table . SchemaActions , SchemaAction . Update ) )
@@ -2378,11 +2358,11 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
2378
2358
table . Catalog ?? defaultCatalog , table . IsQuoted ) ;
2379
2359
if ( tableInfo == null )
2380
2360
{
2381
- script . Add ( table . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
2361
+ script . Add ( table . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
2382
2362
}
2383
2363
else
2384
2364
{
2385
- string [ ] alterDDL = table . SqlAlterStrings ( dialect , staticDialectMapping , tableInfo , defaultCatalog , defaultSchema ) ;
2365
+ string [ ] alterDDL = table . SqlAlterStrings ( dialect , mapping , tableInfo , defaultCatalog , defaultSchema ) ;
2386
2366
script . AddRange ( alterDDL ) ;
2387
2367
}
2388
2368
@@ -2410,7 +2390,7 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
2410
2390
&& ( ! ( dialect is MySQLDialect ) || tableInfo . GetIndexMetadata ( fk . Name ) == null ) ) ;
2411
2391
if ( create )
2412
2392
{
2413
- script . Add ( fk . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
2393
+ script . Add ( fk . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
2414
2394
}
2415
2395
}
2416
2396
}
@@ -2420,7 +2400,7 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
2420
2400
{
2421
2401
if ( tableInfo == null || tableInfo . GetIndexMetadata ( index . Name ) == null )
2422
2402
{
2423
- script . Add ( index . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
2403
+ script . Add ( index . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
2424
2404
}
2425
2405
}
2426
2406
}
@@ -2444,9 +2424,9 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
2444
2424
2445
2425
public void ValidateSchema ( Dialect . Dialect dialect , IDatabaseMetadata databaseMetadata )
2446
2426
{
2427
+ var mapping = BuildMapping ( dialect ) ;
2447
2428
SecondPassCompile ( ) ;
2448
2429
2449
- var staticDialectMapping = new StaticDialectMappingWrapper ( mapping , dialect ) ;
2450
2430
var defaultCatalog = GetQuotedDefaultCatalog ( dialect ) ;
2451
2431
var defaultSchema = GetQuotedDefaultSchema ( dialect ) ;
2452
2432
@@ -2473,7 +2453,7 @@ public void ValidateSchema(Dialect.Dialect dialect, IDatabaseMetadata databaseMe
2473
2453
}
2474
2454
else
2475
2455
{
2476
- validationErrors . AddRange ( table . ValidateColumns ( dialect , staticDialectMapping , tableInfo ) ) ;
2456
+ validationErrors . AddRange ( table . ValidateColumns ( dialect , mapping , tableInfo ) ) ;
2477
2457
}
2478
2458
}
2479
2459
}
0 commit comments