6
6
*/
7
7
package org .hibernate .boot .model .relational .internal ;
8
8
9
+ import java .sql .SQLException ;
9
10
import java .util .Map ;
10
11
11
12
import org .hibernate .boot .model .naming .Identifier ;
17
18
import org .hibernate .boot .model .relational .SqlStringGenerationContext ;
18
19
import org .hibernate .cfg .AvailableSettings ;
19
20
import org .hibernate .dialect .Dialect ;
21
+ import org .hibernate .engine .jdbc .env .internal .QualifiedObjectNameFormatterStandardImpl ;
20
22
import org .hibernate .engine .jdbc .env .spi .IdentifierHelper ;
23
+ import org .hibernate .engine .jdbc .env .spi .IdentifierHelperBuilder ;
21
24
import org .hibernate .engine .jdbc .env .spi .JdbcEnvironment ;
22
25
import org .hibernate .engine .jdbc .env .spi .NameQualifierSupport ;
23
26
import org .hibernate .engine .jdbc .env .spi .QualifiedObjectNameFormatter ;
24
27
28
+ import org .jboss .logging .Logger ;
29
+
25
30
public class SqlStringGenerationContextImpl
26
31
implements SqlStringGenerationContext {
32
+ private static final Logger log = Logger .getLogger ( SqlStringGenerationContextImpl .class );
27
33
28
34
/**
29
35
* @param jdbcEnvironment The JDBC environment, to extract the dialect, identifier helper, etc.
@@ -67,6 +73,37 @@ public static SqlStringGenerationContext fromExplicit(JdbcEnvironment jdbcEnviro
67
73
return new SqlStringGenerationContextImpl ( jdbcEnvironment , actualDefaultCatalog , actualDefaultSchema );
68
74
}
69
75
76
+ /**
77
+ * @param dialect The dialect to use.
78
+ * @param defaultCatalog The default catalog to use.
79
+ * @param defaultSchema The default schema to use.
80
+ * @return An {@link SqlStringGenerationContext}.
81
+ * @deprecated Only use for backwards compatibility in deprecated methods.
82
+ * New methods should take the {@link SqlStringGenerationContext} as an argument,
83
+ * and should not need to create their own context.
84
+ */
85
+ @ Deprecated
86
+ public static SqlStringGenerationContext forBackwardsCompatibility (Dialect dialect , String defaultCatalog , String defaultSchema ) {
87
+ NameQualifierSupport nameQualifierSupport = dialect .getNameQualifierSupport ();
88
+ if ( nameQualifierSupport == null ) {
89
+ // assume both catalogs and schemas are supported
90
+ nameQualifierSupport = NameQualifierSupport .BOTH ;
91
+ }
92
+ QualifiedObjectNameFormatter qualifiedObjectNameFormatter =
93
+ new QualifiedObjectNameFormatterStandardImpl ( nameQualifierSupport );
94
+
95
+ Identifier actualDefaultCatalog = null ;
96
+ if ( nameQualifierSupport .supportsCatalogs () ) {
97
+ actualDefaultCatalog = Identifier .toIdentifier ( defaultCatalog );
98
+ }
99
+ Identifier actualDefaultSchema = null ;
100
+ if ( nameQualifierSupport .supportsSchemas () ) {
101
+ actualDefaultSchema = Identifier .toIdentifier ( defaultSchema );
102
+ }
103
+ return new SqlStringGenerationContextImpl ( dialect , null , qualifiedObjectNameFormatter ,
104
+ actualDefaultCatalog , actualDefaultSchema );
105
+ }
106
+
70
107
public static SqlStringGenerationContext forTests (JdbcEnvironment jdbcEnvironment ) {
71
108
return forTests ( jdbcEnvironment , null , null );
72
109
}
@@ -87,9 +124,17 @@ public static SqlStringGenerationContext forTests(JdbcEnvironment jdbcEnvironmen
87
124
@ SuppressWarnings ("deprecation" )
88
125
private SqlStringGenerationContextImpl (JdbcEnvironment jdbcEnvironment ,
89
126
Identifier defaultCatalog , Identifier defaultSchema ) {
90
- this .dialect = jdbcEnvironment .getDialect ();
91
- this .identifierHelper = jdbcEnvironment .getIdentifierHelper ();
92
- this .qualifiedObjectNameFormatter = jdbcEnvironment .getQualifiedObjectNameFormatter ();
127
+ this ( jdbcEnvironment .getDialect (), jdbcEnvironment .getIdentifierHelper (),
128
+ jdbcEnvironment .getQualifiedObjectNameFormatter (),
129
+ defaultCatalog , defaultSchema );
130
+ }
131
+
132
+ private SqlStringGenerationContextImpl (Dialect dialect , IdentifierHelper identifierHelper ,
133
+ QualifiedObjectNameFormatter qualifiedObjectNameFormatter ,
134
+ Identifier defaultCatalog , Identifier defaultSchema ) {
135
+ this .dialect = dialect ;
136
+ this .identifierHelper = identifierHelper ;
137
+ this .qualifiedObjectNameFormatter = qualifiedObjectNameFormatter ;
93
138
this .defaultCatalog = defaultCatalog ;
94
139
this .defaultSchema = defaultSchema ;
95
140
}
0 commit comments