From 937ab5f4b271670e4bce16f8054aec61de424938 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 13 Dec 2022 12:06:09 +0100 Subject: [PATCH] Polishing (aligned with main) --- .../support/SQLExceptionSubclassTranslator.java | 14 +++++++------- .../r2dbc/connection/ConnectionFactoryUtils.java | 4 ++-- .../dao/CannotAcquireLockException.java | 5 ++++- .../dao/CannotSerializeTransactionException.java | 5 ++++- .../dao/ConcurrencyFailureException.java | 10 ++++------ .../dao/DataIntegrityViolationException.java | 9 +++++++-- .../dao/DeadlockLoserDataAccessException.java | 5 ++++- .../springframework/dao/DuplicateKeyException.java | 5 ++++- .../dao/PessimisticLockingFailureException.java | 10 +++++----- .../http/codec/ClientCodecConfigurer.java | 12 ++++++------ .../http/codec/ServerCodecConfigurer.java | 10 +++++----- 11 files changed, 52 insertions(+), 37 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java index 7e86c84fce43..f13039ff5619 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java @@ -69,10 +69,10 @@ protected DataAccessException doTranslate(String task, @Nullable String sql, SQL if (ex instanceof SQLTransientConnectionException) { return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLTransactionRollbackException) { + if (ex instanceof SQLTransactionRollbackException) { return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLTimeoutException) { + if (ex instanceof SQLTimeoutException) { return new QueryTimeoutException(buildMessage(task, sql, ex), ex); } } @@ -80,19 +80,19 @@ else if (ex instanceof SQLNonTransientException) { if (ex instanceof SQLNonTransientConnectionException) { return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLDataException) { + if (ex instanceof SQLDataException) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLIntegrityConstraintViolationException) { + if (ex instanceof SQLIntegrityConstraintViolationException) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLInvalidAuthorizationSpecException) { + if (ex instanceof SQLInvalidAuthorizationSpecException) { return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLSyntaxErrorException) { + if (ex instanceof SQLSyntaxErrorException) { return new BadSqlGrammarException(task, (sql != null ? sql : ""), ex); } - else if (ex instanceof SQLFeatureNotSupportedException) { + if (ex instanceof SQLFeatureNotSupportedException) { return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); } } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java index dc3fab49d326..c69dc2f49e57 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -221,7 +221,7 @@ public static DataAccessException convertR2dbcException(String task, @Nullable S return new QueryTimeoutException(buildMessage(task, sql, ex), ex); } } - if (ex instanceof R2dbcNonTransientException) { + else if (ex instanceof R2dbcNonTransientException) { if (ex instanceof R2dbcNonTransientResourceException) { return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); } diff --git a/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java b/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java index d5b113e9f5e2..5a36c2381545 100644 --- a/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java +++ b/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2022 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. @@ -20,6 +20,9 @@ * Exception thrown on failure to acquire a lock during an update, * for example during a "select for update" statement. * + *

Consider handling the general {@link PessimisticLockingFailureException} + * instead, semantically including a wider range of locking-related failures. + * * @author Rod Johnson */ @SuppressWarnings("serial") diff --git a/spring-tx/src/main/java/org/springframework/dao/CannotSerializeTransactionException.java b/spring-tx/src/main/java/org/springframework/dao/CannotSerializeTransactionException.java index 1dfe7f541674..7b6223e0ebed 100644 --- a/spring-tx/src/main/java/org/springframework/dao/CannotSerializeTransactionException.java +++ b/spring-tx/src/main/java/org/springframework/dao/CannotSerializeTransactionException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2022 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. @@ -20,6 +20,9 @@ * Exception thrown on failure to complete a transaction in serialized mode * due to update conflicts. * + *

Consider handling the general {@link PessimisticLockingFailureException} + * instead, semantically including a wider range of locking-related failures. + * * @author Rod Johnson */ @SuppressWarnings("serial") diff --git a/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java b/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java index cc990803f483..4f1031ce3f14 100644 --- a/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java +++ b/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2022 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. @@ -19,17 +19,15 @@ import org.springframework.lang.Nullable; /** - * Exception thrown on concurrency failure. + * Exception thrown on various data access concurrency failures. * - *

This exception should be subclassed to indicate the type of failure: - * optimistic locking, failure to acquire lock, etc. + *

This exception provides subclasses for specific types of failure, + * in particular optimistic locking versus pessimistic locking. * * @author Thomas Risberg * @since 1.1 * @see OptimisticLockingFailureException * @see PessimisticLockingFailureException - * @see CannotAcquireLockException - * @see DeadlockLoserDataAccessException */ @SuppressWarnings("serial") public class ConcurrencyFailureException extends TransientDataAccessException { diff --git a/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java b/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java index b1347e1ee946..ad1cc68bb972 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java @@ -19,8 +19,13 @@ /** * Exception thrown when an attempt to insert or update data * results in violation of an integrity constraint. Note that this - * is not purely a relational concept; unique primary keys are - * required by most database types. + * is not purely a relational concept; integrity constraints such + * as unique primary keys are required by most database types. + * + *

Serves as a superclass for more specific exceptions, e.g. + * {@link DuplicateKeyException}. However, it is generally + * recommended to handle {@code DataIntegrityViolationException} + * itself instead of relying on specific exception subclasses. * * @author Rod Johnson */ diff --git a/spring-tx/src/main/java/org/springframework/dao/DeadlockLoserDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/DeadlockLoserDataAccessException.java index 3c946cd56408..9965e0fffe92 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DeadlockLoserDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DeadlockLoserDataAccessException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2022 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. @@ -20,6 +20,9 @@ * Generic exception thrown when the current process was * a deadlock loser, and its transaction rolled back. * + *

Consider handling the general {@link PessimisticLockingFailureException} + * instead, semantically including a wider range of locking-related failures. + * * @author Rod Johnson */ @SuppressWarnings("serial") diff --git a/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java b/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java index b406391a3ff3..36ee084c9e7b 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2022 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. @@ -22,6 +22,9 @@ * Note that this is not necessarily a purely relational concept; * unique primary keys are required by most database types. * + *

Consider handling the general {@link DataIntegrityViolationException} + * instead, semantically including a wider range of constraint violations. + * * @author Thomas Risberg */ @SuppressWarnings("serial") diff --git a/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java b/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java index 3e60eb141bca..31599203a997 100644 --- a/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java +++ b/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2022 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. @@ -21,13 +21,13 @@ * Thrown by Spring's SQLException translation mechanism * if a corresponding database error is encountered. * - *

Serves as superclass for more specific exceptions, like - * CannotAcquireLockException and DeadlockLoserDataAccessException. + *

Serves as a superclass for more specific exceptions, e.g. + * {@link CannotAcquireLockException}. However, it is generally + * recommended to handle {@code PessimisticLockingFailureException} + * itself instead of relying on specific exception subclasses. * * @author Thomas Risberg * @since 1.2 - * @see CannotAcquireLockException - * @see DeadlockLoserDataAccessException * @see OptimisticLockingFailureException */ @SuppressWarnings("serial") diff --git a/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java index 070b0610ee1f..4bcd156a46ff 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -92,11 +92,11 @@ interface ClientDefaultCodecs extends DefaultCodecs { /** * Configure the {@code Decoder} to use for Server-Sent Events. - *

By default if this is not set, and Jackson is available, the - * {@link #jackson2JsonDecoder} override is used instead. Use this property - * if you want to further customize the SSE decoder. - *

Note that {@link #maxInMemorySize(int)}, if configured, will be - * applied to the given decoder. + *

By default if this is not set, and Jackson is available, + * the {@link #jackson2JsonDecoder} override is used instead. + * Use this method to customize the SSE decoder. + *

Note that {@link #maxInMemorySize(int)}, if configured, + * will be applied to the given decoder. * @param decoder the decoder to use */ void serverSentEventDecoder(Decoder decoder); diff --git a/spring-web/src/main/java/org/springframework/http/codec/ServerCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/ServerCodecConfigurer.java index 4bbefc8c939c..bd23db409d8a 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ServerCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ServerCodecConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -78,7 +78,7 @@ static ServerCodecConfigurer create() { /** - * {@link CodecConfigurer.DefaultCodecs} extension with extra client-side options. + * {@link CodecConfigurer.DefaultCodecs} extension with extra server-side options. */ interface ServerDefaultCodecs extends DefaultCodecs { @@ -101,9 +101,9 @@ interface ServerDefaultCodecs extends DefaultCodecs { /** * Configure the {@code Encoder} to use for Server-Sent Events. - *

By default if this is not set, and Jackson is available, the - * {@link #jackson2JsonEncoder} override is used instead. Use this method - * to customize the SSE encoder. + *

By default if this is not set, and Jackson is available, + * the {@link #jackson2JsonEncoder} override is used instead. + * Use this method to customize the SSE encoder. */ void serverSentEventEncoder(Encoder encoder); }