1515import org .hibernate .engine .jdbc .env .spi .JdbcEnvironment ;
1616import org .hibernate .engine .jdbc .env .spi .NameQualifierSupport ;
1717
18- import org .jboss .logging .Logger ;
19-
2018/**
2119* @author Steve Ebersole
2220*/
2321public class NormalizingIdentifierHelperImpl implements IdentifierHelper {
24- private static final Logger log = Logger .getLogger ( NormalizingIdentifierHelperImpl .class );
2522
2623 private final JdbcEnvironment jdbcEnvironment ;
2724
@@ -30,6 +27,7 @@ public class NormalizingIdentifierHelperImpl implements IdentifierHelper {
3027 private final boolean globallyQuoteIdentifiersSkipColumnDefinitions ;
3128 private final boolean autoQuoteKeywords ;
3229 private final boolean autoQuoteInitialUnderscore ;
30+ private final boolean autoQuoteDollar ;
3331 private final TreeSet <String > reservedWords ;
3432 private final IdentifierCaseStrategy unquotedCaseStrategy ;
3533 private final IdentifierCaseStrategy quotedCaseStrategy ;
@@ -41,6 +39,7 @@ public NormalizingIdentifierHelperImpl(
4139 boolean globallyQuoteIdentifiersSkipColumnDefinitions ,
4240 boolean autoQuoteKeywords ,
4341 boolean autoQuoteInitialUnderscore ,
42+ boolean autoQuoteDollar ,
4443 TreeSet <String > reservedWords , //careful, we intentionally omit making a defensive copy to not waste memory
4544 IdentifierCaseStrategy unquotedCaseStrategy ,
4645 IdentifierCaseStrategy quotedCaseStrategy ) {
@@ -50,39 +49,33 @@ public NormalizingIdentifierHelperImpl(
5049 this .globallyQuoteIdentifiersSkipColumnDefinitions = globallyQuoteIdentifiersSkipColumnDefinitions ;
5150 this .autoQuoteKeywords = autoQuoteKeywords ;
5251 this .autoQuoteInitialUnderscore = autoQuoteInitialUnderscore ;
52+ this .autoQuoteDollar = autoQuoteDollar ;
5353 this .reservedWords = reservedWords ;
5454 this .unquotedCaseStrategy = unquotedCaseStrategy == null ? IdentifierCaseStrategy .UPPER : unquotedCaseStrategy ;
5555 this .quotedCaseStrategy = quotedCaseStrategy == null ? IdentifierCaseStrategy .MIXED : quotedCaseStrategy ;
5656 }
5757
5858 @ Override
5959 public Identifier normalizeQuoting (Identifier identifier ) {
60- log .tracef ( "Normalizing identifier quoting [%s]" , identifier );
61-
6260 if ( identifier == null ) {
6361 return null ;
6462 }
65-
66- if ( identifier .isQuoted () ) {
63+ else if ( identifier .isQuoted () ) {
6764 return identifier ;
6865 }
69-
70- if ( globallyQuoteIdentifiers ) {
71- log .tracef ( "Forcing identifier [%s] to quoted for global quoting" , identifier );
66+ else if ( mustQuote ( identifier ) ) {
7267 return Identifier .toIdentifier ( identifier .getText (), true );
7368 }
74-
75- if ( autoQuoteKeywords && isReservedWord ( identifier .getText () ) ) {
76- log .tracef ( "Forcing identifier [%s] to quoted as recognized reserved word" , identifier );
77- return Identifier .toIdentifier ( identifier .getText (), true );
78- }
79-
80- if ( autoQuoteInitialUnderscore && identifier .getText ().startsWith ("_" ) ) {
81- log .tracef ( "Forcing identifier [%s] to quoted due to initial underscore" , identifier );
82- return Identifier .toIdentifier ( identifier .getText (), true );
69+ else {
70+ return identifier ;
8371 }
72+ }
8473
85- return identifier ;
74+ private boolean mustQuote (Identifier identifier ) {
75+ return globallyQuoteIdentifiers
76+ || autoQuoteKeywords && isReservedWord ( identifier .getText () )
77+ || autoQuoteInitialUnderscore && identifier .getText ().startsWith ( "_" )
78+ || autoQuoteDollar && identifier .getText ().contains ( "$" );
8679 }
8780
8881 @ Override
@@ -110,10 +103,7 @@ public boolean isReservedWord(String word) {
110103
111104 @ Override
112105 public String toMetaDataCatalogName (Identifier identifier ) {
113- log .tracef ( "Normalizing identifier quoting for catalog name [%s]" , identifier );
114-
115106 if ( !nameQualifierSupport .supportsCatalogs () ) {
116- log .trace ( "Environment does not support catalogs; returning null" );
117107 // null is used to tell DatabaseMetaData to not limit results based on catalog.
118108 return null ;
119109 }
@@ -133,53 +123,30 @@ private String toMetaDataText(Identifier identifier) {
133123 throw new IllegalArgumentException ( "Identifier cannot be null; bad usage" );
134124 }
135125
126+ final String text = identifier .getText ();
136127 if ( identifier instanceof DatabaseIdentifier ) {
137- return identifier . getText () ;
128+ return text ;
138129 }
139-
140- if ( identifier .isQuoted () ) {
141- switch ( quotedCaseStrategy ) {
142- case UPPER : {
143- log .tracef ( "Rendering quoted identifier [%s] in upper case for use in DatabaseMetaData" , identifier );
144- return identifier .getText ().toUpperCase ( Locale .ROOT );
145- }
146- case LOWER : {
147- log .tracef ( "Rendering quoted identifier [%s] in lower case for use in DatabaseMetaData" , identifier );
148- return identifier .getText ().toLowerCase ( Locale .ROOT );
149- }
150- default : {
151- // default is mixed case
152- log .tracef ( "Rendering quoted identifier [%s] in mixed case for use in DatabaseMetaData" , identifier );
153- return identifier .getText ();
154- }
155- }
130+ else if ( identifier .isQuoted () ) {
131+ return switch ( quotedCaseStrategy ) {
132+ case UPPER -> text .toUpperCase ( Locale .ROOT );
133+ case LOWER -> text .toLowerCase ( Locale .ROOT );
134+ case MIXED -> text ; // default
135+ };
156136 }
157137 else {
158- switch ( unquotedCaseStrategy ) {
159- case MIXED : {
160- log .tracef ( "Rendering unquoted identifier [%s] in mixed case for use in DatabaseMetaData" , identifier );
161- return identifier .getText ();
162- }
163- case LOWER : {
164- log .tracef ( "Rendering unquoted identifier [%s] in lower case for use in DatabaseMetaData" , identifier );
165- return identifier .getText ().toLowerCase ( Locale .ROOT );
166- }
167- default : {
168- // default is upper case
169- log .tracef ( "Rendering unquoted identifier [%s] in upper case for use in DatabaseMetaData" , identifier );
170- return identifier .getText ().toUpperCase ( Locale .ROOT );
171- }
172- }
138+ return switch ( unquotedCaseStrategy ) {
139+ case MIXED -> text ;
140+ case LOWER -> text .toLowerCase ( Locale .ROOT );
141+ case UPPER -> text .toUpperCase ( Locale .ROOT ); // default
142+ };
173143 }
174144 }
175145
176146 @ Override
177147 public String toMetaDataSchemaName (Identifier identifier ) {
178- log .tracef ( "Normalizing identifier quoting for schema name [%s]" , identifier );
179-
180148 if ( !nameQualifierSupport .supportsSchemas () ) {
181149 // null is used to tell DatabaseMetaData to not limit results based on schema.
182- log .trace ( "Environment does not support catalogs; returning null" );
183150 return null ;
184151 }
185152
@@ -195,8 +162,6 @@ public String toMetaDataSchemaName(Identifier identifier) {
195162
196163 @ Override
197164 public String toMetaDataObjectName (Identifier identifier ) {
198- log .tracef ( "Normalizing identifier quoting for object name [%s]" , identifier );
199-
200165 if ( identifier == null ) {
201166 // if this method was called, the value is needed
202167 throw new IllegalArgumentException ( "null was passed as an object name" );
0 commit comments