diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index 48c67cff185e..e9d51597dfab 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -1568,8 +1568,7 @@ private void bindSynchronize() { if ( synchronize != null ) { final JdbcEnvironment jdbcEnvironment = getMetadataCollector().getDatabase().getJdbcEnvironment(); final boolean logical = synchronize.logical(); - final String[] tableNames = synchronize.value(); - for ( String tableName : tableNames ) { + for ( String tableName : synchronize.value() ) { final String physicalName = logical ? toPhysicalName( jdbcEnvironment, tableName ) : tableName; persistentClass.addSynchronizedTable( physicalName ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Template.java b/hibernate-core/src/main/java/org/hibernate/sql/Template.java index 7d242bb8d187..990e82a586e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Template.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Template.java @@ -207,8 +207,8 @@ else if ( quotedIdentifier && dialect.closeQuote()==token.charAt(0) ) { isOpenQuote = false; } if ( isOpenQuote - && !inFromClause // don't want to append alias to tokens inside the from clause - && notEndsWithDot( previousToken ) ) { + && !inFromClause // don't want to append alias to tokens inside the FROM clause + && !endsWithDot( previousToken ) ) { result.append( alias ).append( '.' ); } } @@ -237,7 +237,7 @@ else if ( FUNCTION_WITH_FROM_KEYWORDS.contains(lcToken) && "(".equals( nextToken result.append(token); inExtractOrTrim = true; } - else if ( !inFromClause // don't want to append alias to tokens inside the from clause + else if ( !inFromClause // don't want to append alias to tokens inside the FROM clause && isIdentifier( token ) && !isFunctionOrKeyword( lcToken, nextToken, dialect, typeConfiguration ) && !isLiteral( lcToken, nextToken, sql, symbols, tokens ) ) { @@ -274,31 +274,29 @@ else if ( inFromClause && ",".equals(lcToken) ) { return result.toString(); } - private static boolean notEndsWithDot(String token) { - return token == null || !token.endsWith( "." ); + private static boolean endsWithDot(String token) { + return token != null && token.endsWith( "." ); } private static boolean isLiteral( String lcToken, String next, String sqlWhereString, String symbols, StringTokenizer tokens) { - if ( LITERAL_PREFIXES.contains( lcToken ) && next != null ) { - // easy cases first - if ( "'".equals(next) ) { - return true; - } - else if ( !next.isBlank() ) { - return false; - } - else { + if ( next == null ) { + return false; + } + else if ( LITERAL_PREFIXES.contains( lcToken ) ) { + if ( next.isBlank() ) { // we need to look ahead in the token stream // to find the first non-blank token return lookPastBlankTokens( sqlWhereString, symbols, tokens, 1, - (String nextToken) - -> "'".equals(nextToken) + (nextToken) -> "'".equals(nextToken) || lcToken.equals("time") && "with".equals(nextToken) || lcToken.equals("timestamp") && "with".equals(nextToken) || lcToken.equals("time") && "zone".equals(nextToken) ); } + else { + return "'".equals(next); + } } else { return false; @@ -351,7 +349,7 @@ public static List collectColumnNames(String template) { int begin = 0; int match; while ( ( match = template.indexOf(TEMPLATE, begin) ) >= 0 ) { - int start = match + TEMPLATE.length() + 1; + final int start = match + TEMPLATE.length() + 1; for ( int loc = start;; loc++ ) { if ( loc == template.length() - 1 ) { names.add( template.substring( start ) ); @@ -359,7 +357,7 @@ public static List collectColumnNames(String template) { break; } else { - char ch = template.charAt( loc ); + final char ch = template.charAt( loc ); if ( PUNCTUATION.indexOf(ch) >= 0 || WHITESPACE.indexOf(ch) >= 0 ) { names.add( template.substring( start, loc ) ); begin = loc; @@ -401,17 +399,16 @@ private static boolean isType(String lcToken, TypeConfiguration typeConfiguratio } private static boolean isIdentifier(String token) { - if ( isBoolean( token ) ) { - return false; - } - return token.charAt( 0 ) == '`' - || ( //allow any identifier quoted with backtick - isLetter( token.charAt( 0 ) ) && //only recognizes identifiers beginning with a letter - token.indexOf( '.' ) < 0 - ); + return token.charAt( 0 ) == '`' // allow any identifier quoted with backtick + || isLetter( token.charAt( 0 ) ) // only recognizes identifiers beginning with a letter + && token.indexOf( '.' ) < 0 + && !isBoolean( token ); } private static boolean isBoolean(String token) { - return "true".equals( token ) || "false".equals( token ); + return switch ( token.toLowerCase( Locale.ROOT ) ) { + case "true", "false" -> true; + default -> false; + }; } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/DateTimeUtils.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/DateTimeUtils.java index 498a56771eb9..663be8fca938 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/DateTimeUtils.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/DateTimeUtils.java @@ -20,6 +20,7 @@ import java.util.Locale; import java.util.TimeZone; +import org.hibernate.Internal; import org.hibernate.dialect.Dialect; import org.hibernate.sql.ast.spi.SqlAppender; @@ -32,6 +33,7 @@ * @author Steve Ebersole * @author Gavin King */ +@Internal public final class DateTimeUtils { private DateTimeUtils() { } @@ -435,8 +437,8 @@ public static T adjustToDefaultPrecision(T temporal, Dialec return adjustToPrecision( temporal, d.getDefaultTimestampPrecision(), d ); } - public static T adjustToPrecision(T temporal, int precision, Dialect d) { - return d.doesRoundTemporalOnOverflow() + public static T adjustToPrecision(T temporal, int precision, Dialect dialect) { + return dialect.doesRoundTemporalOnOverflow() ? roundToSecondPrecision( temporal, precision ) : truncateToPrecision( temporal, precision ); } @@ -484,6 +486,7 @@ public static T roundToSecondPrecision(T temporal, int prec } final long nanos = roundToPrecision( temporal.get( ChronoField.NANO_OF_SECOND ), precision ); if ( nanos == 1000000000L ) { + //noinspection unchecked return (T) temporal.plus( 1L, ChronoUnit.SECONDS ).with( ChronoField.NANO_OF_SECOND, 0L ); } //noinspection unchecked @@ -501,27 +504,17 @@ public static long roundToPrecision(int nano, int precision) { } private static int pow10(int exponent) { - switch ( exponent ) { - case 0: - return 1; - case 1: - return 10; - case 2: - return 100; - case 3: - return 1_000; - case 4: - return 10_000; - case 5: - return 100_000; - case 6: - return 1_000_000; - case 7: - return 10_000_000; - case 8: - return 100_000_000; - default: - return (int) Math.pow( 10, exponent ); - } + return switch ( exponent ) { + case 0 -> 1; + case 1 -> 10; + case 2 -> 100; + case 3 -> 1_000; + case 4 -> 10_000; + case 5 -> 100_000; + case 6 -> 1_000_000; + case 7 -> 10_000_000; + case 8 -> 100_000_000; + default -> (int) Math.pow( 10, exponent ); + }; } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java index c0f448a9cdb9..dd943ac5ae5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java @@ -267,7 +267,6 @@ public boolean isTypeNameRegistered(final String typeName) { return true; } } - return false; } }