From 355fa258bd2d98fb34e41450baaa657ef49fe0e9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 14 Jul 2023 14:52:15 +0200 Subject: [PATCH] Polishing --- .../scheduling/annotation/Scheduled.java | 10 ++++++++-- .../support/GenericConversionService.java | 5 ++--- .../springframework/jdbc/core/JdbcTemplate.java | 14 ++++---------- .../AbstractFallbackSQLExceptionTranslator.java | 9 ++++++--- .../SQLErrorCodeSQLExceptionTranslator.java | 17 +++++++---------- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java index 983d341e782..319165d2bec 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java @@ -28,8 +28,8 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; /** * Annotation that marks a method to be scheduled. Exactly one of the - * {@link #cron}, {@link #fixedDelay}, or {@link #fixedRate} attributes must be - * specified. + * {@link #cron}, {@link #fixedDelay}, or {@link #fixedRate} attributes + * must be specified. * *

The annotated method must expect no arguments. It will typically have * a {@code void} return type; if not, the returned value will be ignored @@ -40,6 +40,12 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * done manually or, more conveniently, through the {@code } * XML element or {@link EnableScheduling @EnableScheduling} annotation. * + *

This annotation can be used as a {@linkplain Repeatable repeatable} + * annotation. If several scheduled declarations are found on the same method, + * each of them will be processed independently, with a separate trigger firing + * for each of them. As a consequence, such co-located schedules may overlap + * and execute multiple times in parallel or in immediate succession. + * *

This annotation may be used as a meta-annotation to create custom * composed annotations with attribute overrides. * diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 6065d468524..5cff48af210 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -205,8 +205,7 @@ public class GenericConversionService implements ConfigurableConversionService { * @param targetType the target type * @return the converted value * @throws ConversionException if a conversion exception occurred - * @throws IllegalArgumentException if targetType is {@code null}, - * or sourceType is {@code null} but source is not {@code null} + * @throws IllegalArgumentException if targetType is {@code null} */ @Nullable public Object convert(@Nullable Object source, TypeDescriptor targetType) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 225ab2b1223..eb0fb2475bc 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -445,9 +445,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { logger.debug("Executing SQL query [" + sql + "]"); } - /** - * Callback to execute the query. - */ + // Callback to execute the query. class QueryStatementCallback implements StatementCallback, SqlProvider { @Override @Nullable @@ -542,9 +540,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { logger.debug("Executing SQL update [" + sql + "]"); } - /** - * Callback to execute the update statement. - */ + // Callback to execute the update statement. class UpdateStatementCallback implements StatementCallback, SqlProvider { @Override public Integer doInStatement(Statement stmt) throws SQLException { @@ -570,9 +566,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { logger.debug("Executing SQL batch update of " + sql.length + " statements"); } - /** - * Callback to execute the batch update. - */ + // Callback to execute the batch update. class BatchUpdateStatementCallback implements StatementCallback, SqlProvider { @Nullable @@ -1376,7 +1370,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } } } - if (!(param.isResultsParameter())) { + if (!param.isResultsParameter()) { sqlColIndex++; } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java index 44b8838b210..f1546734ac1 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,8 @@ import org.springframework.util.Assert; * * @author Juergen Hoeller * @since 2.5.6 + * @see #doTranslate + * @see #setFallbackTranslator */ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExceptionTranslator { @@ -42,8 +44,8 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep /** - * Override the default SQL state fallback translator - * (typically a {@link SQLStateSQLExceptionTranslator}). + * Set the fallback translator to use when this translator cannot find a + * specific match itself. */ public void setFallbackTranslator(@Nullable SQLExceptionTranslator fallback) { this.fallbackTranslator = fallback; @@ -51,6 +53,7 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep /** * Return the fallback exception translator, if any. + * @see #setFallbackTranslator */ @Nullable public SQLExceptionTranslator getFallbackTranslator() { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java index 80f89796049..c4ba08dbfec 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,8 +75,6 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep private static final int MESSAGE_SQL_THROWABLE_CONSTRUCTOR = 4; private static final int MESSAGE_SQL_SQLEX_CONSTRUCTOR = 5; - - /** Error codes used by this translator. */ @Nullable private SingletonSupplier sqlErrorCodes; @@ -194,9 +192,9 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep if (sqlErrorCodes != null) { SQLExceptionTranslator customTranslator = sqlErrorCodes.getCustomSqlExceptionTranslator(); if (customTranslator != null) { - DataAccessException customDex = customTranslator.translate(task, sql, sqlEx); - if (customDex != null) { - return customDex; + dae = customTranslator.translate(task, sql, sqlEx); + if (dae != null) { + return dae; } } } @@ -224,11 +222,10 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep for (CustomSQLErrorCodesTranslation customTranslation : customTranslations) { if (Arrays.binarySearch(customTranslation.getErrorCodes(), errorCode) >= 0 && customTranslation.getExceptionClass() != null) { - DataAccessException customException = createCustomException( - task, sql, sqlEx, customTranslation.getExceptionClass()); - if (customException != null) { + dae = createCustomException(task, sql, sqlEx, customTranslation.getExceptionClass()); + if (dae != null) { logTranslation(task, sql, sqlEx, true); - return customException; + return dae; } } }