@@ -98,7 +98,6 @@ public Configuration(SerializationInfo info, StreamingContext context)
9898 FilterDefinitions = GetSerialedObject < IDictionary < string , FilterDefinition > > ( info , "filterDefinitions" ) ;
9999 Imports = GetSerialedObject < IDictionary < string , string > > ( info , "imports" ) ;
100100 interceptor = GetSerialedObject < IInterceptor > ( info , "interceptor" ) ;
101- mapping = GetSerialedObject < IMapping > ( info , "mapping" ) ;
102101 NamedQueries = GetSerialedObject < IDictionary < string , NamedQueryDefinition > > ( info , "namedQueries" ) ;
103102 NamedSQLQueries = GetSerialedObject < IDictionary < string , NamedSQLQueryDefinition > > ( info , "namedSqlQueries" ) ;
104103 namingStrategy = GetSerialedObject < INamingStrategy > ( info , "namingStrategy" ) ;
@@ -124,7 +123,6 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
124123 {
125124 ConfigureProxyFactoryFactory ( ) ;
126125 SecondPassCompile ( ) ;
127- Validate ( ) ;
128126
129127 info . AddValue ( "entityNotFoundDelegate" , EntityNotFoundDelegate ) ;
130128
@@ -139,7 +137,6 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
139137 info . AddValue ( "filterDefinitions" , FilterDefinitions ) ;
140138 info . AddValue ( "imports" , Imports ) ;
141139 info . AddValue ( "interceptor" , interceptor ) ;
142- info . AddValue ( "mapping" , mapping ) ;
143140 info . AddValue ( "namedQueries" , NamedQueries ) ;
144141 info . AddValue ( "namedSqlQueries" , NamedSQLQueries ) ;
145142 info . AddValue ( "namingStrategy" , namingStrategy ) ;
@@ -246,10 +243,6 @@ private class StaticDialectMappingWrapper : IMapping
246243 {
247244 private readonly IMapping _mapping ;
248245
249- public StaticDialectMappingWrapper ( IMapping mapping ) : this ( mapping , mapping . Dialect )
250- {
251- }
252-
253246 public StaticDialectMappingWrapper ( IMapping mapping , Dialect . Dialect dialect )
254247 {
255248 _mapping = mapping ;
@@ -279,23 +272,25 @@ public bool HasNonIdentifierPropertyNamedId(string className)
279272 public Dialect . Dialect Dialect { get ; }
280273 }
281274
282- private IMapping mapping ;
283-
284275 protected Configuration ( SettingsFactory settingsFactory )
285276 {
286- InitBlock ( ) ;
287277 this . settingsFactory = settingsFactory ;
288278 Reset ( ) ;
289279 }
290280
291- private void InitBlock ( )
281+ // Since v5.5
282+ [ Obsolete ( "Use BuildMapping(Dialect.Dialect) instead." ) ]
283+ public virtual IMapping BuildMapping ( )
292284 {
293- mapping = BuildMapping ( ) ;
285+ return new Mapping ( this ) ;
294286 }
295287
296- public virtual IMapping BuildMapping ( )
288+ public virtual IMapping BuildMapping ( Dialect . Dialect dialect )
297289 {
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 ) ;
299294 }
300295
301296 /// <summary>
@@ -552,9 +547,8 @@ private void AddValidatedDocument(NamedXmlDocument doc)
552547 public void AddDeserializedMapping ( HbmMapping mappingDocument , string documentFileName )
553548 {
554549 if ( mappingDocument == null )
555- {
556- throw new ArgumentNullException ( "mappingDocument" ) ;
557- }
550+ throw new ArgumentNullException ( nameof ( mappingDocument ) ) ;
551+
558552 try
559553 {
560554 var dialect = new Lazy < Dialect . Dialect > ( ( ) => Dialect . Dialect . GetDialect ( properties ) ) ;
@@ -749,9 +743,8 @@ public Configuration AddResource(string path, Assembly assembly)
749743 public Configuration AddResources ( IEnumerable < string > paths , Assembly assembly )
750744 {
751745 if ( paths == null )
752- {
753- throw new ArgumentNullException ( "paths" ) ;
754- }
746+ throw new ArgumentNullException ( nameof ( paths ) ) ;
747+
755748 foreach ( var path in paths )
756749 {
757750 AddResource ( path , assembly ) ;
@@ -938,19 +931,19 @@ public static bool IncludeAction(SchemaAction actionsSource, SchemaAction includ
938931 /// <param name="dialect"></param>
939932 public string [ ] GenerateSchemaCreationScript ( Dialect . Dialect dialect )
940933 {
934+ var mapping = BuildMapping ( dialect ) ;
941935 SecondPassCompile ( ) ;
942936
943937 var defaultCatalog = GetQuotedDefaultCatalog ( dialect ) ;
944938 var defaultSchema = GetQuotedDefaultSchema ( dialect ) ;
945939
946940 var script = new List < string > ( ) ;
947941
948- var staticDialectMapping = new StaticDialectMappingWrapper ( mapping , dialect ) ;
949942 foreach ( var table in TableMappings )
950943 {
951944 if ( table . IsPhysicalTable && IncludeAction ( table . SchemaActions , SchemaAction . Export ) )
952945 {
953- script . Add ( table . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
946+ script . Add ( table . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
954947 script . AddRange ( table . SqlCommentStrings ( dialect , defaultCatalog , defaultSchema ) ) ;
955948 }
956949 }
@@ -963,7 +956,7 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
963956 {
964957 foreach ( var uk in table . UniqueKeyIterator )
965958 {
966- string constraintString = uk . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ;
959+ string constraintString = uk . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ;
967960 if ( constraintString != null )
968961 {
969962 script . Add ( constraintString ) ;
@@ -973,7 +966,7 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
973966
974967 foreach ( var index in table . IndexIterator )
975968 {
976- script . Add ( index . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
969+ script . Add ( index . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
977970 }
978971
979972 if ( dialect . SupportsForeignKeyConstraintInAlterTable )
@@ -982,7 +975,7 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
982975 {
983976 if ( fk . IsGenerated ( dialect ) && IncludeAction ( fk . ReferencedTable . SchemaActions , SchemaAction . Export ) )
984977 {
985- script . Add ( fk . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
978+ script . Add ( fk . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
986979 }
987980 }
988981 }
@@ -999,18 +992,18 @@ public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
999992 {
1000993 if ( auxDbObj . AppliesToDialect ( dialect ) )
1001994 {
1002- script . Add ( auxDbObj . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
995+ script . Add ( auxDbObj . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
1003996 }
1004997 }
1005998
1006999 return script . ToArray ( ) ;
10071000 }
10081001
1009- private void Validate ( )
1002+ private void Validate ( IMapping mapping )
10101003 {
1011- ValidateEntities ( ) ;
1004+ ValidateEntities ( mapping ) ;
10121005
1013- ValidateCollections ( ) ;
1006+ ValidateCollections ( mapping ) ;
10141007
10151008 ValidateFilterDefs ( ) ;
10161009 }
@@ -1064,15 +1057,15 @@ private void ValidateFilterDefs()
10641057 }
10651058 }
10661059
1067- private void ValidateCollections ( )
1060+ private void ValidateCollections ( IMapping mapping )
10681061 {
10691062 foreach ( var col in collections . Values )
10701063 {
10711064 col . Validate ( mapping ) ;
10721065 }
10731066 }
10741067
1075- private void ValidateEntities ( )
1068+ private void ValidateEntities ( IMapping mapping )
10761069 {
10771070 bool validateProxy = PropertiesHelper . GetBoolean ( Environment . UseProxyValidator , properties , true ) ;
10781071 HashSet < string > allProxyErrors = null ;
@@ -1286,8 +1279,7 @@ protected virtual void ConfigureProxyFactoryFactory()
12861279 //http://nhibernate.jira.com/browse/NH-975
12871280
12881281 var ipff = Environment . BytecodeProvider as IInjectableProxyFactoryFactory ;
1289- string pffClassName ;
1290- properties . TryGetValue ( Environment . ProxyFactoryFactoryClass , out pffClassName ) ;
1282+ properties . TryGetValue ( Environment . ProxyFactoryFactoryClass , out var pffClassName ) ;
12911283 if ( ipff != null && ! string . IsNullOrEmpty ( pffClassName ) )
12921284 {
12931285 ipff . SetProxyFactoryFactory ( pffClassName ) ;
@@ -1304,33 +1296,21 @@ protected virtual void ConfigureProxyFactoryFactory()
13041296 /// <returns>An <see cref="ISessionFactory" /> instance.</returns>
13051297 public ISessionFactory BuildSessionFactory ( )
13061298 {
1307- var dynamicDialectMapping = mapping ;
13081299 // Use a mapping which does store the dialect instead of instantiating a new one
13091300 // at each access. The dialect does not change while building a session factory.
13101301 // It furthermore allows some hack on NHibernate.Spatial side to go on working,
13111302 // 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 ) ;
13201309
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 ;
13231312
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 ( ) ) ;
13341314 }
13351315
13361316 /// <summary>
@@ -2363,13 +2343,13 @@ private static T[] AppendListeners<T>(T[] existing, T[] listenersToAdd)
23632343 /// <seealso cref="NHibernate.Tool.hbm2ddl.SchemaUpdate"/>
23642344 public string [ ] GenerateSchemaUpdateScript ( Dialect . Dialect dialect , IDatabaseMetadata databaseMetadata )
23652345 {
2346+ var mapping = BuildMapping ( dialect ) ;
23662347 SecondPassCompile ( ) ;
23672348
23682349 var defaultCatalog = GetQuotedDefaultCatalog ( dialect ) ;
23692350 var defaultSchema = GetQuotedDefaultSchema ( dialect ) ;
23702351
23712352 var script = new List < string > ( 50 ) ;
2372- var staticDialectMapping = new StaticDialectMappingWrapper ( mapping , dialect ) ;
23732353 foreach ( var table in TableMappings )
23742354 {
23752355 if ( table . IsPhysicalTable && IncludeAction ( table . SchemaActions , SchemaAction . Update ) )
@@ -2378,11 +2358,11 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
23782358 table . Catalog ?? defaultCatalog , table . IsQuoted ) ;
23792359 if ( tableInfo == null )
23802360 {
2381- script . Add ( table . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
2361+ script . Add ( table . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
23822362 }
23832363 else
23842364 {
2385- string [ ] alterDDL = table . SqlAlterStrings ( dialect , staticDialectMapping , tableInfo , defaultCatalog , defaultSchema ) ;
2365+ string [ ] alterDDL = table . SqlAlterStrings ( dialect , mapping , tableInfo , defaultCatalog , defaultSchema ) ;
23862366 script . AddRange ( alterDDL ) ;
23872367 }
23882368
@@ -2410,7 +2390,7 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
24102390 && ( ! ( dialect is MySQLDialect ) || tableInfo . GetIndexMetadata ( fk . Name ) == null ) ) ;
24112391 if ( create )
24122392 {
2413- script . Add ( fk . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
2393+ script . Add ( fk . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
24142394 }
24152395 }
24162396 }
@@ -2420,7 +2400,7 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
24202400 {
24212401 if ( tableInfo == null || tableInfo . GetIndexMetadata ( index . Name ) == null )
24222402 {
2423- script . Add ( index . SqlCreateString ( dialect , staticDialectMapping , defaultCatalog , defaultSchema ) ) ;
2403+ script . Add ( index . SqlCreateString ( dialect , mapping , defaultCatalog , defaultSchema ) ) ;
24242404 }
24252405 }
24262406 }
@@ -2444,9 +2424,9 @@ public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, IDatabaseMet
24442424
24452425 public void ValidateSchema ( Dialect . Dialect dialect , IDatabaseMetadata databaseMetadata )
24462426 {
2427+ var mapping = BuildMapping ( dialect ) ;
24472428 SecondPassCompile ( ) ;
24482429
2449- var staticDialectMapping = new StaticDialectMappingWrapper ( mapping , dialect ) ;
24502430 var defaultCatalog = GetQuotedDefaultCatalog ( dialect ) ;
24512431 var defaultSchema = GetQuotedDefaultSchema ( dialect ) ;
24522432
@@ -2473,7 +2453,7 @@ public void ValidateSchema(Dialect.Dialect dialect, IDatabaseMetadata databaseMe
24732453 }
24742454 else
24752455 {
2476- validationErrors . AddRange ( table . ValidateColumns ( dialect , staticDialectMapping , tableInfo ) ) ;
2456+ validationErrors . AddRange ( table . ValidateColumns ( dialect , mapping , tableInfo ) ) ;
24772457 }
24782458 }
24792459 }
0 commit comments