Skip to content

Commit

Permalink
Clarify DataAccessException/ScriptException declarations for R2DBC
Browse files Browse the repository at this point in the history
Closes gh-30932

(cherry picked from commit 5bcf5c6)
  • Loading branch information
jhoeller committed Jul 24, 2023
1 parent d1efc89 commit 6dea580
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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,7 +20,6 @@
import io.r2dbc.spi.ConnectionFactory;
import reactor.core.publisher.Mono;

import org.springframework.dao.DataAccessException;
import org.springframework.r2dbc.connection.ConnectionFactoryUtils;
import org.springframework.util.Assert;

Expand All @@ -44,17 +43,18 @@ public interface DatabasePopulator {
* already configured and ready to use, must not be {@code null}
* @return {@link Mono} that initiates script execution and is
* notified upon completion
* @throws ScriptException in all other error cases
* @throws ScriptException in case of any errors
*/
Mono<Void> populate(Connection connection) throws ScriptException;
Mono<Void> populate(Connection connection);

/**
* Execute the given {@link DatabasePopulator} against the given {@link ConnectionFactory}.
* @param connectionFactory the {@link ConnectionFactory} to execute against
* @return {@link Mono} that initiates {@link DatabasePopulator#populate(Connection)}
* and is notified upon completion
* @throws ScriptException in case of any errors
*/
default Mono<Void> populate(ConnectionFactory connectionFactory) throws DataAccessException {
default Mono<Void> populate(ConnectionFactory connectionFactory) {
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
return Mono.usingWhen(ConnectionFactoryUtils.getConnection(connectionFactory), //
this::populate, //
Expand Down
@@ -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 Down Expand Up @@ -260,7 +260,7 @@ public void setDataBufferFactory(DataBufferFactory dataBufferFactory) {


@Override
public Mono<Void> populate(Connection connection) throws ScriptException {
public Mono<Void> populate(Connection connection) {
Assert.notNull(connection, "Connection must not be null");
return Flux.fromIterable(this.scripts).concatMap(resource -> {
EncodedResource encodedScript = new EncodedResource(resource, this.sqlScriptEncoding);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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 @@ -125,7 +125,7 @@ public abstract class ScriptUtils {
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#getConnection
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#releaseConnection
*/
public static Mono<Void> executeSqlScript(Connection connection, Resource resource) throws ScriptException {
public static Mono<Void> executeSqlScript(Connection connection, Resource resource) {
return executeSqlScript(connection, new EncodedResource(resource));
}

Expand All @@ -149,7 +149,7 @@ public static Mono<Void> executeSqlScript(Connection connection, Resource resour
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#getConnection
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#releaseConnection
*/
public static Mono<Void> executeSqlScript(Connection connection, EncodedResource resource) throws ScriptException {
public static Mono<Void> executeSqlScript(Connection connection, EncodedResource resource) {
return executeSqlScript(connection, resource, DefaultDataBufferFactory.sharedInstance, false, false,
DEFAULT_COMMENT_PREFIXES, DEFAULT_STATEMENT_SEPARATOR, DEFAULT_BLOCK_COMMENT_START_DELIMITER,
DEFAULT_BLOCK_COMMENT_END_DELIMITER);
Expand Down Expand Up @@ -189,7 +189,7 @@ public static Mono<Void> executeSqlScript(Connection connection, EncodedResource
public static Mono<Void> executeSqlScript(Connection connection, EncodedResource resource,
DataBufferFactory dataBufferFactory, boolean continueOnError, boolean ignoreFailedDrops,
String commentPrefix, @Nullable String separator, String blockCommentStartDelimiter,
String blockCommentEndDelimiter) throws ScriptException {
String blockCommentEndDelimiter) {

return executeSqlScript(connection, resource, dataBufferFactory, continueOnError,
ignoreFailedDrops, new String[] { commentPrefix }, separator,
Expand Down Expand Up @@ -230,7 +230,7 @@ public static Mono<Void> executeSqlScript(Connection connection, EncodedResource
public static Mono<Void> executeSqlScript(Connection connection, EncodedResource resource,
DataBufferFactory dataBufferFactory, boolean continueOnError, boolean ignoreFailedDrops,
String[] commentPrefixes, @Nullable String separator, String blockCommentStartDelimiter,
String blockCommentEndDelimiter) throws ScriptException {
String blockCommentEndDelimiter) {

if (logger.isDebugEnabled()) {
logger.debug("Executing SQL script from " + resource);
Expand Down Expand Up @@ -365,7 +365,7 @@ private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuild
*/
static boolean containsStatementSeparator(EncodedResource resource, String script,
String separator, String[] commentPrefixes, String blockCommentStartDelimiter,
String blockCommentEndDelimiter) throws ScriptException {
String blockCommentEndDelimiter) {

boolean inSingleQuote = false;
boolean inDoubleQuote = false;
Expand Down Expand Up @@ -448,7 +448,7 @@ else if (script.startsWith(blockCommentStartDelimiter, i)) {
*/
static List<String> splitSqlScript(EncodedResource resource, String script,
String separator, String[] commentPrefixes, String blockCommentStartDelimiter,
String blockCommentEndDelimiter) throws ScriptException {
String blockCommentEndDelimiter) {

Assert.hasText(script, "'script' must not be null or empty");
Assert.notNull(separator, "'separator' must not be null");
Expand Down
@@ -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 @@ -22,22 +22,23 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.springframework.dao.DataAccessException;

/**
* Interface declaring methods that accept callback {@link Function}
* to operate within the scope of a {@link Connection}.
* Callback functions operate on a provided connection and must not
* close the connection as the connections may be pooled or be
* subject to other kinds of resource management.
*
* <p> Callback functions are responsible for creating a
* <p>Callback functions are responsible for creating a
* {@link org.reactivestreams.Publisher} that defines the scope of how
* long the allocated {@link Connection} is valid. Connections are
* released after the publisher terminates.
*
* <p>This serves as a base interface for {@link DatabaseClient}.
*
* @author Mark Paluch
* @since 5.3
* @see DatabaseClient
*/
public interface ConnectionAccessor {

Expand All @@ -49,8 +50,9 @@ public interface ConnectionAccessor {
* {@link Function} closure, otherwise resources may get defunct.
* @param action the callback object that specifies the connection action
* @return the resulting {@link Mono}
* @throws org.springframework.dao.DataAccessException in case of any errors
*/
<T> Mono<T> inConnection(Function<Connection, Mono<T>> action) throws DataAccessException;
<T> Mono<T> inConnection(Function<Connection, Mono<T>> action);

/**
* Execute a callback {@link Function} within a {@link Connection} scope.
Expand All @@ -60,7 +62,8 @@ public interface ConnectionAccessor {
* {@link Function} closure, otherwise resources may get defunct.
* @param action the callback object that specifies the connection action
* @return the resulting {@link Flux}
* @throws org.springframework.dao.DataAccessException in case of any errors
*/
<T> Flux<T> inConnectionMany(Function<Connection, Flux<T>> action) throws DataAccessException;
<T> Flux<T> inConnectionMany(Function<Connection, Flux<T>> action);

}
Expand Up @@ -32,9 +32,9 @@
import org.springframework.util.Assert;

/**
* A non-blocking, reactive client for performing database calls requests with
* Reactive Streams back pressure. Provides a higher level, common API over
* R2DBC client libraries.
* A non-blocking, reactive client for performing database calls with Reactive Streams
* back pressure. Provides a higher level, common API over R2DBC client libraries.
* Propagates {@link org.springframework.dao.DataAccessException} variants for errors.
*
* <p>Use one of the static factory methods {@link #create(ConnectionFactory)}
* or obtain a {@link DatabaseClient#builder()} to create an instance.
Expand Down
Expand Up @@ -44,7 +44,6 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.lang.Nullable;
import org.springframework.r2dbc.connection.ConnectionFactoryUtils;
Expand Down Expand Up @@ -105,7 +104,7 @@ public GenericExecuteSpec sql(Supplier<String> sqlSupplier) {
}

@Override
public <T> Mono<T> inConnection(Function<Connection, Mono<T>> action) throws DataAccessException {
public <T> Mono<T> inConnection(Function<Connection, Mono<T>> action) {
Assert.notNull(action, "Callback object must not be null");
Mono<ConnectionCloseHolder> connectionMono = getConnection().map(
connection -> new ConnectionCloseHolder(connection, this::closeConnection));
Expand All @@ -127,7 +126,7 @@ public <T> Mono<T> inConnection(Function<Connection, Mono<T>> action) throws Dat
}

@Override
public <T> Flux<T> inConnectionMany(Function<Connection, Flux<T>> action) throws DataAccessException {
public <T> Flux<T> inConnectionMany(Function<Connection, Flux<T>> action) {
Assert.notNull(action, "Callback object must not be null");
Mono<ConnectionCloseHolder> connectionMono = getConnection().map(
connection -> new ConnectionCloseHolder(connection, this::closeConnection));
Expand Down

0 comments on commit 6dea580

Please sign in to comment.