Browse Source

Clarify DataAccessException/ScriptException declarations for R2DBC

Closes gh-30932
pull/31496/head
Juergen Hoeller 2 years ago
parent
commit
5bcf5c6f7c
  1. 10
      spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/DatabasePopulator.java
  2. 4
      spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java
  3. 14
      spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java
  4. 15
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionAccessor.java
  5. 6
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java
  6. 5
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java

10
spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/DatabasePopulator.java

@ -1,5 +1,5 @@ @@ -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.
@ -20,7 +20,6 @@ import io.r2dbc.spi.Connection; @@ -20,7 +20,6 @@ import io.r2dbc.spi.Connection;
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;
@ -44,17 +43,18 @@ public interface DatabasePopulator { @@ -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, //

4
spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java

@ -1,5 +1,5 @@ @@ -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.
@ -260,7 +260,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { @@ -260,7 +260,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
@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);

14
spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java

@ -1,5 +1,5 @@ @@ -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.
@ -125,7 +125,7 @@ public abstract class ScriptUtils { @@ -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));
}
@ -149,7 +149,7 @@ public abstract class ScriptUtils { @@ -149,7 +149,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, 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);
@ -189,7 +189,7 @@ public abstract class ScriptUtils { @@ -189,7 +189,7 @@ public abstract class ScriptUtils {
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,
@ -230,7 +230,7 @@ public abstract class ScriptUtils { @@ -230,7 +230,7 @@ public abstract class ScriptUtils {
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);
@ -365,7 +365,7 @@ public abstract class ScriptUtils { @@ -365,7 +365,7 @@ public abstract class ScriptUtils {
*/
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;
@ -448,7 +448,7 @@ public abstract class ScriptUtils { @@ -448,7 +448,7 @@ public abstract class ScriptUtils {
*/
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");

15
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionAccessor.java

@ -1,5 +1,5 @@ @@ -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.
@ -22,8 +22,6 @@ import io.r2dbc.spi.Connection; @@ -22,8 +22,6 @@ import io.r2dbc.spi.Connection;
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}.
@ -31,13 +29,16 @@ import org.springframework.dao.DataAccessException; @@ -31,13 +29,16 @@ import org.springframework.dao.DataAccessException;
* 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 {
@ -49,8 +50,9 @@ public interface ConnectionAccessor { @@ -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.
@ -60,7 +62,8 @@ public interface ConnectionAccessor { @@ -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);
}

6
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java

@ -37,9 +37,9 @@ import org.springframework.r2dbc.core.binding.BindMarkersFactory; @@ -37,9 +37,9 @@ import org.springframework.r2dbc.core.binding.BindMarkersFactory;
import org.springframework.util.Assert;
/**
* A non-blocking, reactive client for performing database calls 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 the static factory method {@link #create(ConnectionFactory)} or obtain
* a {@linkplain DatabaseClient#builder() builder} to create an instance.

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

@ -47,7 +47,6 @@ import org.reactivestreams.Publisher; @@ -47,7 +47,6 @@ import org.reactivestreams.Publisher;
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;
@ -108,7 +107,7 @@ class DefaultDatabaseClient implements DatabaseClient { @@ -108,7 +107,7 @@ class DefaultDatabaseClient implements DatabaseClient {
}
@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));
@ -130,7 +129,7 @@ class DefaultDatabaseClient implements DatabaseClient { @@ -130,7 +129,7 @@ class DefaultDatabaseClient implements DatabaseClient {
}
@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));

Loading…
Cancel
Save