Browse Source

Polishing

pull/31346/head
Juergen Hoeller 2 years ago
parent
commit
407113945d
  1. 6
      spring-context/src/main/java/org/springframework/context/annotation/Configuration.java
  2. 31
      spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java
  3. 26
      spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java
  4. 5
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java

6
spring-context/src/main/java/org/springframework/context/annotation/Configuration.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -104,8 +104,8 @@ import org.springframework.stereotype.Component;
* *
* }</pre> * }</pre>
* *
* <p>{@code @Configuration} classes may not only be bootstrapped using * <p>{@code @Configuration} classes may not only be bootstrapped using component
* component scanning, but may also themselves <em>configure</em> component scanning using * scanning, but may also themselves <em>configure</em> component scanning using
* the {@link ComponentScan @ComponentScan} annotation: * the {@link ComponentScan @ComponentScan} annotation:
* *
* <pre class="code"> * <pre class="code">

31
spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,12 +20,12 @@ import org.springframework.util.Assert;
/** /**
* Implementation of {@link BackOff} that increases the back off period for each * Implementation of {@link BackOff} that increases the back off period for each
* retry attempt. When the interval has reached the {@link #setMaxInterval(long) * retry attempt. When the interval has reached the {@linkplain #setMaxInterval
* max interval}, it is no longer increased. Stops retrying once the * max interval}, it is no longer increased. Stops retrying once the
* {@link #setMaxElapsedTime(long) max elapsed time} has been reached. * {@linkplain #setMaxElapsedTime max elapsed time} has been reached.
* *
* <p>Example: The default interval is {@value #DEFAULT_INITIAL_INTERVAL} ms, * <p>Example: The default interval is {@value #DEFAULT_INITIAL_INTERVAL} ms;
* the default multiplier is {@value #DEFAULT_MULTIPLIER}, and the default max * the default multiplier is {@value #DEFAULT_MULTIPLIER}; and the default max
* interval is {@value #DEFAULT_MAX_INTERVAL}. For 10 attempts the sequence will be * interval is {@value #DEFAULT_MAX_INTERVAL}. For 10 attempts the sequence will be
* as follows: * as follows:
* *
@ -44,10 +44,9 @@ import org.springframework.util.Assert;
* 10 30000 * 10 30000
* </pre> * </pre>
* *
* <p>Note that the default max elapsed time is {@link Long#MAX_VALUE}. Use * <p>Note that the default max elapsed time is {@link Long#MAX_VALUE}.
* {@link #setMaxElapsedTime(long)} to limit the maximum length of time * Use {@link #setMaxElapsedTime} to limit the maximum length of time that an
* that an instance should accumulate before returning * instance should accumulate before returning {@link BackOffExecution#STOP}.
* {@link BackOffExecution#STOP}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 4.1 * @since 4.1
@ -107,7 +106,7 @@ public class ExponentialBackOff implements BackOff {
/** /**
* The initial interval in milliseconds. * Set the initial interval in milliseconds.
*/ */
public void setInitialInterval(long initialInterval) { public void setInitialInterval(long initialInterval) {
this.initialInterval = initialInterval; this.initialInterval = initialInterval;
@ -121,7 +120,7 @@ public class ExponentialBackOff implements BackOff {
} }
/** /**
* The value to multiply the current interval by for each retry attempt. * Set the value to multiply the current interval by for each retry attempt.
*/ */
public void setMultiplier(double multiplier) { public void setMultiplier(double multiplier) {
checkMultiplier(multiplier); checkMultiplier(multiplier);
@ -136,21 +135,21 @@ public class ExponentialBackOff implements BackOff {
} }
/** /**
* The maximum back off time. * Set the maximum back off time in milliseconds.
*/ */
public void setMaxInterval(long maxInterval) { public void setMaxInterval(long maxInterval) {
this.maxInterval = maxInterval; this.maxInterval = maxInterval;
} }
/** /**
* Return the maximum back off time. * Return the maximum back off time in milliseconds.
*/ */
public long getMaxInterval() { public long getMaxInterval() {
return this.maxInterval; return this.maxInterval;
} }
/** /**
* The maximum elapsed time in milliseconds after which a call to * Set the maximum elapsed time in milliseconds after which a call to
* {@link BackOffExecution#nextBackOff()} returns {@link BackOffExecution#STOP}. * {@link BackOffExecution#nextBackOff()} returns {@link BackOffExecution#STOP}.
*/ */
public void setMaxElapsedTime(long maxElapsedTime) { public void setMaxElapsedTime(long maxElapsedTime) {
@ -184,10 +183,9 @@ public class ExponentialBackOff implements BackOff {
@Override @Override
public long nextBackOff() { public long nextBackOff() {
if (this.currentElapsedTime >= maxElapsedTime) { if (this.currentElapsedTime >= getMaxElapsedTime()) {
return STOP; return STOP;
} }
long nextInterval = computeNextInterval(); long nextInterval = computeNextInterval();
this.currentElapsedTime += nextInterval; this.currentElapsedTime += nextInterval;
return nextInterval; return nextInterval;
@ -214,7 +212,6 @@ public class ExponentialBackOff implements BackOff {
return Math.min(i, maxInterval); return Math.min(i, maxInterval);
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("ExponentialBackOff{"); StringBuilder sb = new StringBuilder("ExponentialBackOff{");

26
spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java vendored

@ -252,24 +252,24 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
if (ex instanceof JDBCConnectionException) { if (ex instanceof JDBCConnectionException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex); return new DataAccessResourceFailureException(ex.getMessage(), ex);
} }
if (ex instanceof SQLGrammarException hibJdbcEx) { if (ex instanceof SQLGrammarException hibEx) {
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex); return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
} }
if (ex instanceof QueryTimeoutException hibJdbcEx) { if (ex instanceof QueryTimeoutException hibEx) {
return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex); return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
} }
if (ex instanceof LockAcquisitionException hibJdbcEx) { if (ex instanceof LockAcquisitionException hibEx) {
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex); return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
} }
if (ex instanceof PessimisticLockException hibJdbcEx) { if (ex instanceof PessimisticLockException hibEx) {
return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex); return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
} }
if (ex instanceof ConstraintViolationException hibJdbcEx) { if (ex instanceof ConstraintViolationException hibEx) {
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibEx.getSQL() +
"]; constraint [" + hibJdbcEx.getConstraintName() + "]", ex); "]; constraint [" + hibEx.getConstraintName() + "]", ex);
} }
if (ex instanceof DataException hibJdbcEx) { if (ex instanceof DataException hibEx) {
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex); return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
} }
// end of JDBCException subclass handling // end of JDBCException subclass handling

5
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java

@ -166,9 +166,8 @@ final class DefaultDatabaseClient implements DatabaseClient {
* @return a {@link Publisher} that completes successfully when the connection is closed * @return a {@link Publisher} that completes successfully when the connection is closed
*/ */
private Publisher<Void> closeConnection(Connection connection) { private Publisher<Void> closeConnection(Connection connection) {
return ConnectionFactoryUtils.currentConnectionFactory( return ConnectionFactoryUtils.currentConnectionFactory(obtainConnectionFactory()).then()
obtainConnectionFactory()).then().onErrorResume(Exception.class, .onErrorResume(Exception.class, ex -> Mono.from(connection.close()));
e -> Mono.from(connection.close()));
} }
/** /**

Loading…
Cancel
Save