Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Sep 29, 2023
1 parent 4cf5c77 commit 4071139
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -104,8 +104,8 @@
*
* }</pre>
*
* <p>{@code @Configuration} classes may not only be bootstrapped using
* component scanning, but may also themselves <em>configure</em> component scanning using
* <p>{@code @Configuration} classes may not only be bootstrapped using component
* scanning, but may also themselves <em>configure</em> component scanning using
* the {@link ComponentScan @ComponentScan} annotation:
*
* <pre class="code">
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,12 +20,12 @@

/**
* 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
* {@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,
* the default multiplier is {@value #DEFAULT_MULTIPLIER}, and the default max
* <p>Example: The default interval is {@value #DEFAULT_INITIAL_INTERVAL} ms;
* the default multiplier is {@value #DEFAULT_MULTIPLIER}; and the default max
* interval is {@value #DEFAULT_MAX_INTERVAL}. For 10 attempts the sequence will be
* as follows:
*
Expand All @@ -44,10 +44,9 @@
* 10 30000
* </pre>
*
* <p>Note that the default max elapsed time is {@link Long#MAX_VALUE}. Use
* {@link #setMaxElapsedTime(long)} to limit the maximum length of time
* that an instance should accumulate before returning
* {@link BackOffExecution#STOP}.
* <p>Note that the default max elapsed time is {@link Long#MAX_VALUE}.
* Use {@link #setMaxElapsedTime} to limit the maximum length of time that an
* instance should accumulate before returning {@link BackOffExecution#STOP}.
*
* @author Stephane Nicoll
* @since 4.1
Expand Down Expand Up @@ -107,7 +106,7 @@ public ExponentialBackOff(long initialInterval, double multiplier) {


/**
* The initial interval in milliseconds.
* Set the initial interval in milliseconds.
*/
public void setInitialInterval(long initialInterval) {
this.initialInterval = initialInterval;
Expand All @@ -121,7 +120,7 @@ public long getInitialInterval() {
}

/**
* 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) {
checkMultiplier(multiplier);
Expand All @@ -136,21 +135,21 @@ public double getMultiplier() {
}

/**
* The maximum back off time.
* Set the maximum back off time in milliseconds.
*/
public void setMaxInterval(long maxInterval) {
this.maxInterval = maxInterval;
}

/**
* Return the maximum back off time.
* Return the maximum back off time in milliseconds.
*/
public long getMaxInterval() {
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}.
*/
public void setMaxElapsedTime(long maxElapsedTime) {
Expand Down Expand Up @@ -184,10 +183,9 @@ private class ExponentialBackOffExecution implements BackOffExecution {

@Override
public long nextBackOff() {
if (this.currentElapsedTime >= maxElapsedTime) {
if (this.currentElapsedTime >= getMaxElapsedTime()) {
return STOP;
}

long nextInterval = computeNextInterval();
this.currentElapsedTime += nextInterval;
return nextInterval;
Expand All @@ -214,7 +212,6 @@ private long multiplyInterval(long maxInterval) {
return Math.min(i, maxInterval);
}


@Override
public String toString() {
StringBuilder sb = new StringBuilder("ExponentialBackOff{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,24 +252,24 @@ protected DataAccessException convertHibernateAccessException(HibernateException
if (ex instanceof JDBCConnectionException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof SQLGrammarException hibJdbcEx) {
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex);
if (ex instanceof SQLGrammarException hibEx) {
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
}
if (ex instanceof QueryTimeoutException hibJdbcEx) {
return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex);
if (ex instanceof QueryTimeoutException hibEx) {
return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
}
if (ex instanceof LockAcquisitionException hibJdbcEx) {
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex);
if (ex instanceof LockAcquisitionException hibEx) {
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
}
if (ex instanceof PessimisticLockException hibJdbcEx) {
return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex);
if (ex instanceof PessimisticLockException hibEx) {
return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
}
if (ex instanceof ConstraintViolationException hibJdbcEx) {
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() +
"]; constraint [" + hibJdbcEx.getConstraintName() + "]", ex);
if (ex instanceof ConstraintViolationException hibEx) {
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibEx.getSQL() +
"]; constraint [" + hibEx.getConstraintName() + "]", ex);
}
if (ex instanceof DataException hibJdbcEx) {
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibJdbcEx.getSQL() + "]", ex);
if (ex instanceof DataException hibEx) {
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + hibEx.getSQL() + "]", ex);
}
// end of JDBCException subclass handling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ private Mono<Connection> getConnection() {
* @return a {@link Publisher} that completes successfully when the connection is closed
*/
private Publisher<Void> closeConnection(Connection connection) {
return ConnectionFactoryUtils.currentConnectionFactory(
obtainConnectionFactory()).then().onErrorResume(Exception.class,
e -> Mono.from(connection.close()));
return ConnectionFactoryUtils.currentConnectionFactory(obtainConnectionFactory()).then()
.onErrorResume(Exception.class, ex -> Mono.from(connection.close()));
}

/**
Expand Down

0 comments on commit 4071139

Please sign in to comment.