HHH-16430 Avoid AnsiSqlKeywords to retain all keywords as static constants

This commit is contained in:
Sanne Grinovero 2023-04-03 17:02:23 +01:00 committed by Sanne Grinovero
parent ca3e69a4f6
commit 845e9770d5
4 changed files with 8 additions and 11 deletions

View File

@ -609,7 +609,8 @@ public abstract class Dialect implements ConversionContext, TypeContributor, Fun
* @see AnsiSqlKeywords
*/
protected void registerDefaultKeywords() {
for ( String keyword : AnsiSqlKeywords.INSTANCE.sql2003() ) {
AnsiSqlKeywords keywords = new AnsiSqlKeywords();
for ( String keyword : keywords.sql2003() ) {
registerKeyword( keyword );
}
}

View File

@ -15,14 +15,9 @@ import java.util.Set;
*/
public final class AnsiSqlKeywords {
/**
* Singleton access
*/
public static final AnsiSqlKeywords INSTANCE = new AnsiSqlKeywords();
private final Set<String> keywordsSql2003;
private AnsiSqlKeywords() {
public AnsiSqlKeywords() {
this.keywordsSql2003 = Set.of(
"add",
"all",

View File

@ -11,6 +11,7 @@ import org.hibernate.internal.util.StringHelper;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
@ -21,10 +22,10 @@ import java.util.StringTokenizer;
*/
public final class HighlightingFormatter implements Formatter {
private static final Set<String> KEYWORDS = new HashSet<>( AnsiSqlKeywords.INSTANCE.sql2003() );
private static final Set<String> KEYWORDS_LOWERCASED = new HashSet<>( new AnsiSqlKeywords().sql2003() );
static {
// additional keywords not reserved by ANSI SQL 2003
KEYWORDS.addAll( Arrays.asList( "KEY", "SEQUENCE", "CASCADE", "INCREMENT" ) );
KEYWORDS_LOWERCASED.addAll( Arrays.asList( "key", "sequence", "cascade", "increment" ) );
}
public static final Formatter INSTANCE =
@ -92,7 +93,7 @@ public final class HighlightingFormatter implements Formatter {
}
break;
default:
if ( KEYWORDS.contains( token.toUpperCase() ) ) {
if ( KEYWORDS_LOWERCASED.contains( token.toLowerCase( Locale.ROOT ) ) ) {
result.append( keywordEscape ).append( token ).append( normalEscape );
}
else {

View File

@ -37,7 +37,7 @@ public class JdbcMocks {
private boolean supportsBatchUpdates = true;
private boolean dataDefinitionIgnoredInTransactions = false;
private boolean dataDefinitionCausesTransactionCommit = false;
private String sqlKeywords = String.join( ",", AnsiSqlKeywords.INSTANCE.sql2003() );
private String sqlKeywords = String.join( ",", new AnsiSqlKeywords().sql2003() );
private int sqlStateType = DatabaseMetaData.sqlStateXOpen;
private boolean locatorsUpdateCopy = false;
private boolean storesLowerCaseIdentifiers = true;