Skip to content

Commit d0f3b67

Browse files
committed
misc minor code changes
1 parent fe9aec8 commit d0f3b67

File tree

4 files changed

+42
-54
lines changed

4 files changed

+42
-54
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,8 +1568,7 @@ private void bindSynchronize() {
15681568
if ( synchronize != null ) {
15691569
final JdbcEnvironment jdbcEnvironment = getMetadataCollector().getDatabase().getJdbcEnvironment();
15701570
final boolean logical = synchronize.logical();
1571-
final String[] tableNames = synchronize.value();
1572-
for ( String tableName : tableNames ) {
1571+
for ( String tableName : synchronize.value() ) {
15731572
final String physicalName = logical ? toPhysicalName( jdbcEnvironment, tableName ) : tableName;
15741573
persistentClass.addSynchronizedTable( physicalName );
15751574
}

hibernate-core/src/main/java/org/hibernate/sql/Template.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ else if ( quotedIdentifier && dialect.closeQuote()==token.charAt(0) ) {
207207
isOpenQuote = false;
208208
}
209209
if ( isOpenQuote
210-
&& !inFromClause // don't want to append alias to tokens inside the from clause
211-
&& notEndsWithDot( previousToken ) ) {
210+
&& !inFromClause // don't want to append alias to tokens inside the FROM clause
211+
&& !endsWithDot( previousToken ) ) {
212212
result.append( alias ).append( '.' );
213213
}
214214
}
@@ -237,7 +237,7 @@ else if ( FUNCTION_WITH_FROM_KEYWORDS.contains(lcToken) && "(".equals( nextToken
237237
result.append(token);
238238
inExtractOrTrim = true;
239239
}
240-
else if ( !inFromClause // don't want to append alias to tokens inside the from clause
240+
else if ( !inFromClause // don't want to append alias to tokens inside the FROM clause
241241
&& isIdentifier( token )
242242
&& !isFunctionOrKeyword( lcToken, nextToken, dialect, typeConfiguration )
243243
&& !isLiteral( lcToken, nextToken, sql, symbols, tokens ) ) {
@@ -274,31 +274,29 @@ else if ( inFromClause && ",".equals(lcToken) ) {
274274
return result.toString();
275275
}
276276

277-
private static boolean notEndsWithDot(String token) {
278-
return token == null || !token.endsWith( "." );
277+
private static boolean endsWithDot(String token) {
278+
return token != null && token.endsWith( "." );
279279
}
280280

281281
private static boolean isLiteral(
282282
String lcToken, String next,
283283
String sqlWhereString, String symbols, StringTokenizer tokens) {
284-
if ( LITERAL_PREFIXES.contains( lcToken ) && next != null ) {
285-
// easy cases first
286-
if ( "'".equals(next) ) {
287-
return true;
288-
}
289-
else if ( !next.isBlank() ) {
290-
return false;
291-
}
292-
else {
284+
if ( next == null ) {
285+
return false;
286+
}
287+
else if ( LITERAL_PREFIXES.contains( lcToken ) ) {
288+
if ( next.isBlank() ) {
293289
// we need to look ahead in the token stream
294290
// to find the first non-blank token
295291
return lookPastBlankTokens( sqlWhereString, symbols, tokens, 1,
296-
(String nextToken)
297-
-> "'".equals(nextToken)
292+
(nextToken) -> "'".equals(nextToken)
298293
|| lcToken.equals("time") && "with".equals(nextToken)
299294
|| lcToken.equals("timestamp") && "with".equals(nextToken)
300295
|| lcToken.equals("time") && "zone".equals(nextToken) );
301296
}
297+
else {
298+
return "'".equals(next);
299+
}
302300
}
303301
else {
304302
return false;
@@ -351,15 +349,15 @@ public static List<String> collectColumnNames(String template) {
351349
int begin = 0;
352350
int match;
353351
while ( ( match = template.indexOf(TEMPLATE, begin) ) >= 0 ) {
354-
int start = match + TEMPLATE.length() + 1;
352+
final int start = match + TEMPLATE.length() + 1;
355353
for ( int loc = start;; loc++ ) {
356354
if ( loc == template.length() - 1 ) {
357355
names.add( template.substring( start ) );
358356
begin = template.length();
359357
break;
360358
}
361359
else {
362-
char ch = template.charAt( loc );
360+
final char ch = template.charAt( loc );
363361
if ( PUNCTUATION.indexOf(ch) >= 0 || WHITESPACE.indexOf(ch) >= 0 ) {
364362
names.add( template.substring( start, loc ) );
365363
begin = loc;
@@ -401,17 +399,16 @@ private static boolean isType(String lcToken, TypeConfiguration typeConfiguratio
401399
}
402400

403401
private static boolean isIdentifier(String token) {
404-
if ( isBoolean( token ) ) {
405-
return false;
406-
}
407-
return token.charAt( 0 ) == '`'
408-
|| ( //allow any identifier quoted with backtick
409-
isLetter( token.charAt( 0 ) ) && //only recognizes identifiers beginning with a letter
410-
token.indexOf( '.' ) < 0
411-
);
402+
return token.charAt( 0 ) == '`' // allow any identifier quoted with backtick
403+
|| isLetter( token.charAt( 0 ) ) // only recognizes identifiers beginning with a letter
404+
&& token.indexOf( '.' ) < 0
405+
&& !isBoolean( token );
412406
}
413407

414408
private static boolean isBoolean(String token) {
415-
return "true".equals( token ) || "false".equals( token );
409+
return switch ( token.toLowerCase( Locale.ROOT ) ) {
410+
case "true", "false" -> true;
411+
default -> false;
412+
};
416413
}
417414
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/DateTimeUtils.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Locale;
2121
import java.util.TimeZone;
2222

23+
import org.hibernate.Internal;
2324
import org.hibernate.dialect.Dialect;
2425
import org.hibernate.sql.ast.spi.SqlAppender;
2526

@@ -32,6 +33,7 @@
3233
* @author Steve Ebersole
3334
* @author Gavin King
3435
*/
36+
@Internal
3537
public final class DateTimeUtils {
3638
private DateTimeUtils() {
3739
}
@@ -435,8 +437,8 @@ public static <T extends Temporal> T adjustToDefaultPrecision(T temporal, Dialec
435437
return adjustToPrecision( temporal, d.getDefaultTimestampPrecision(), d );
436438
}
437439

438-
public static <T extends Temporal> T adjustToPrecision(T temporal, int precision, Dialect d) {
439-
return d.doesRoundTemporalOnOverflow()
440+
public static <T extends Temporal> T adjustToPrecision(T temporal, int precision, Dialect dialect) {
441+
return dialect.doesRoundTemporalOnOverflow()
440442
? roundToSecondPrecision( temporal, precision )
441443
: truncateToPrecision( temporal, precision );
442444
}
@@ -484,6 +486,7 @@ public static <T extends Temporal> T roundToSecondPrecision(T temporal, int prec
484486
}
485487
final long nanos = roundToPrecision( temporal.get( ChronoField.NANO_OF_SECOND ), precision );
486488
if ( nanos == 1000000000L ) {
489+
//noinspection unchecked
487490
return (T) temporal.plus( 1L, ChronoUnit.SECONDS ).with( ChronoField.NANO_OF_SECOND, 0L );
488491
}
489492
//noinspection unchecked
@@ -501,27 +504,17 @@ public static long roundToPrecision(int nano, int precision) {
501504
}
502505

503506
private static int pow10(int exponent) {
504-
switch ( exponent ) {
505-
case 0:
506-
return 1;
507-
case 1:
508-
return 10;
509-
case 2:
510-
return 100;
511-
case 3:
512-
return 1_000;
513-
case 4:
514-
return 10_000;
515-
case 5:
516-
return 100_000;
517-
case 6:
518-
return 1_000_000;
519-
case 7:
520-
return 10_000_000;
521-
case 8:
522-
return 100_000_000;
523-
default:
524-
return (int) Math.pow( 10, exponent );
525-
}
507+
return switch ( exponent ) {
508+
case 0 -> 1;
509+
case 1 -> 10;
510+
case 2 -> 100;
511+
case 3 -> 1_000;
512+
case 4 -> 10_000;
513+
case 5 -> 100_000;
514+
case 6 -> 1_000_000;
515+
case 7 -> 10_000_000;
516+
case 8 -> 100_000_000;
517+
default -> (int) Math.pow( 10, exponent );
518+
};
526519
}
527520
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ public boolean isTypeNameRegistered(final String typeName) {
267267
return true;
268268
}
269269
}
270-
271270
return false;
272271
}
273272
}

0 commit comments

Comments
 (0)