3
3
using NHibernate . Engine ;
4
4
using NHibernate . Mapping ;
5
5
using System . Collections . Generic ;
6
- using NHibernate . Connection ;
7
6
8
7
namespace NHibernate . Tool . hbm2ddl
9
8
{
@@ -12,95 +11,71 @@ public static class SchemaMetadataUpdater
12
11
{
13
12
public static void Update ( ISessionFactoryImplementor sessionFactory )
14
13
{
15
- var reservedWords = GetReservedWords ( sessionFactory . ConnectionProvider , sessionFactory . Dialect ) ;
16
- sessionFactory . Dialect . Keywords . UnionWith ( reservedWords ) ;
14
+ UpdateDialectKeywords (
15
+ sessionFactory . Dialect ,
16
+ new SuppliedConnectionProviderConnectionHelper ( sessionFactory . ConnectionProvider ) ) ;
17
17
}
18
18
19
19
public static void Update ( Configuration configuration , Dialect . Dialect dialect )
20
20
{
21
- dialect . Keywords . UnionWith ( GetReservedWords ( configuration , dialect ) ) ;
21
+ UpdateDialectKeywords (
22
+ dialect ,
23
+ new ManagedProviderConnectionHelper ( configuration . GetDerivedProperties ( ) ) ) ;
22
24
}
23
25
24
- [ Obsolete ( "Use the overload that passes dialect so keywords will be updated and persisted before auto-quoting" ) ]
25
- public static void QuoteTableAndColumns ( Configuration configuration )
26
- {
27
- // Instantiates a new instance of the dialect so doesn't benefit from the Update call.
28
- var dialect = Dialect . Dialect . GetDialect ( configuration . GetDerivedProperties ( ) ) ;
29
- Update ( configuration , dialect ) ;
30
- QuoteTableAndColumns ( configuration , dialect ) ;
31
- }
32
-
33
- public static void QuoteTableAndColumns ( Configuration configuration , Dialect . Dialect dialect )
26
+ static void UpdateDialectKeywords ( Dialect . Dialect dialect , IConnectionHelper connectionHelper )
34
27
{
35
- ISet < string > reservedDb = dialect . Keywords ;
36
-
37
- foreach ( var cm in configuration . ClassMappings )
38
- {
39
- QuoteTable ( cm . Table , reservedDb ) ;
40
- }
41
- foreach ( var cm in configuration . CollectionMappings )
42
- {
43
- QuoteTable ( cm . Table , reservedDb ) ;
44
- }
28
+ dialect . RegisterKeywords ( GetReservedWords ( dialect , connectionHelper ) ) ;
45
29
}
46
30
47
- private static ISet < string > GetReservedWords ( Configuration configuration , Dialect . Dialect dialect )
31
+ static IEnumerable < string > GetReservedWords ( Dialect . Dialect dialect , IConnectionHelper connectionHelper )
48
32
{
49
- IConnectionHelper connectionHelper = new ManagedProviderConnectionHelper ( configuration . GetDerivedProperties ( ) ) ;
50
33
connectionHelper . Prepare ( ) ;
51
34
try
52
35
{
53
- return GetReservedWords ( dialect , connectionHelper ) ;
36
+ var metaData = dialect . GetDataBaseSchema ( connectionHelper . Connection ) ;
37
+ return metaData . GetReservedWords ( ) ;
54
38
}
55
39
finally
56
40
{
57
41
connectionHelper . Release ( ) ;
58
42
}
59
43
}
60
44
61
- private static ISet < string > GetReservedWords ( IConnectionProvider connectionProvider , Dialect . Dialect dialect )
45
+ [ Obsolete ( "Use the overload that passes dialect so keywords will be updated and persisted before auto-quoting" ) ]
46
+ public static void QuoteTableAndColumns ( Configuration configuration )
62
47
{
63
- IConnectionHelper connectionHelper = new SuppliedConnectionProviderConnectionHelper ( connectionProvider ) ;
64
- connectionHelper . Prepare ( ) ;
65
- try
66
- {
67
- return GetReservedWords ( dialect , connectionHelper ) ;
68
- }
69
- finally
70
- {
71
- connectionHelper . Release ( ) ;
72
- }
48
+ // Instantiates a new instance of the dialect so doesn't benefit from the Update call.
49
+ var dialect = Dialect . Dialect . GetDialect ( configuration . GetDerivedProperties ( ) ) ;
50
+ Update ( configuration , dialect ) ;
51
+ QuoteTableAndColumns ( configuration , dialect ) ;
73
52
}
74
53
75
- private static ISet < string > GetReservedWords ( Dialect . Dialect dialect , IConnectionHelper connectionHelper )
54
+ public static void QuoteTableAndColumns ( Configuration configuration , Dialect . Dialect dialect )
76
55
{
77
- ISet < string > reservedWords = new HashSet < string > ( dialect . Keywords , StringComparer . OrdinalIgnoreCase ) ;
78
- var metaData = dialect . GetDataBaseSchema ( connectionHelper . Connection ) ;
79
- foreach ( var rw in metaData . GetReservedWords ( ) )
56
+ foreach ( var cm in configuration . ClassMappings )
80
57
{
81
- reservedWords . Add ( rw ) ;
58
+ QuoteTable ( cm . Table , dialect ) ;
59
+ }
60
+ foreach ( var cm in configuration . CollectionMappings )
61
+ {
62
+ QuoteTable ( cm . Table , dialect ) ;
82
63
}
83
- return reservedWords ;
84
64
}
85
65
86
- private static void QuoteTable ( Table table , ICollection < string > reservedDb )
66
+ private static void QuoteTable ( Table table , Dialect . Dialect dialect )
87
67
{
88
- if ( ! table . IsQuoted && reservedDb . Contains ( table . Name ) )
68
+ if ( ! table . IsQuoted && dialect . IsKeyword ( table . Name ) )
89
69
{
90
- table . Name = GetNhQuoted ( table . Name ) ;
70
+ table . IsQuoted = true ;
91
71
}
92
72
foreach ( var column in table . ColumnIterator )
93
73
{
94
- if ( ! column . IsQuoted && reservedDb . Contains ( column . Name ) )
74
+ if ( ! column . IsQuoted && dialect . IsKeyword ( column . Name ) )
95
75
{
96
- column . Name = GetNhQuoted ( column . Name ) ;
76
+ column . IsQuoted = true ;
97
77
}
98
78
}
99
79
}
100
-
101
- private static string GetNhQuoted ( string name )
102
- {
103
- return "`" + name + "`" ;
104
- }
105
80
}
106
- }
81
+ }
0 commit comments