66 */
77package org .hibernate .boot .model .relational .internal ;
88
9+ import java .sql .SQLException ;
910import java .util .Map ;
1011
1112import org .hibernate .boot .model .naming .Identifier ;
1718import org .hibernate .boot .model .relational .SqlStringGenerationContext ;
1819import org .hibernate .cfg .AvailableSettings ;
1920import org .hibernate .dialect .Dialect ;
21+ import org .hibernate .engine .jdbc .env .internal .QualifiedObjectNameFormatterStandardImpl ;
2022import org .hibernate .engine .jdbc .env .spi .IdentifierHelper ;
23+ import org .hibernate .engine .jdbc .env .spi .IdentifierHelperBuilder ;
2124import org .hibernate .engine .jdbc .env .spi .JdbcEnvironment ;
2225import org .hibernate .engine .jdbc .env .spi .NameQualifierSupport ;
2326import org .hibernate .engine .jdbc .env .spi .QualifiedObjectNameFormatter ;
2427
28+ import org .jboss .logging .Logger ;
29+
2530public class SqlStringGenerationContextImpl
2631 implements SqlStringGenerationContext {
32+ private static final Logger log = Logger .getLogger ( SqlStringGenerationContextImpl .class );
2733
2834 /**
2935 * @param jdbcEnvironment The JDBC environment, to extract the dialect, identifier helper, etc.
@@ -67,6 +73,37 @@ public static SqlStringGenerationContext fromExplicit(JdbcEnvironment jdbcEnviro
6773 return new SqlStringGenerationContextImpl ( jdbcEnvironment , actualDefaultCatalog , actualDefaultSchema );
6874 }
6975
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+
70107 public static SqlStringGenerationContext forTests (JdbcEnvironment jdbcEnvironment ) {
71108 return forTests ( jdbcEnvironment , null , null );
72109 }
@@ -87,9 +124,17 @@ public static SqlStringGenerationContext forTests(JdbcEnvironment jdbcEnvironmen
87124 @ SuppressWarnings ("deprecation" )
88125 private SqlStringGenerationContextImpl (JdbcEnvironment jdbcEnvironment ,
89126 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 ;
93138 this .defaultCatalog = defaultCatalog ;
94139 this .defaultSchema = defaultSchema ;
95140 }
0 commit comments