diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/DatabasePopulator.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/DatabasePopulator.java index 467a25549cf..8adf9831b30 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/DatabasePopulator.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/DatabasePopulator.java @@ -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; 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 { * 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 populate(Connection connection) throws ScriptException; + Mono 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 populate(ConnectionFactory connectionFactory) throws DataAccessException { + default Mono populate(ConnectionFactory connectionFactory) { Assert.notNull(connectionFactory, "ConnectionFactory must not be null"); return Mono.usingWhen(ConnectionFactoryUtils.getConnection(connectionFactory), // this::populate, // diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java index a6aeac31364..86dc2f4fcf2 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.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"); * you may not use this file except in compliance with the License. @@ -260,7 +260,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { @Override - public Mono populate(Connection connection) throws ScriptException { + public Mono 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); diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java index c374d68c05a..18437ddca93 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java @@ -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 { * @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#getConnection * @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#releaseConnection */ - public static Mono executeSqlScript(Connection connection, Resource resource) throws ScriptException { + public static Mono executeSqlScript(Connection connection, Resource resource) { return executeSqlScript(connection, new EncodedResource(resource)); } @@ -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 executeSqlScript(Connection connection, EncodedResource resource) throws ScriptException { + public static Mono 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 { public static Mono 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 { public static Mono 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 { */ 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 { */ static List 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"); diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionAccessor.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionAccessor.java index 9f794ce6710..d3424708960 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionAccessor.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionAccessor.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"); * you may not use this file except in compliance with the License. @@ -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; * close the connection as the connections may be pooled or be * subject to other kinds of resource management. * - *

Callback functions are responsible for creating a + *

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. * + *

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 { * {@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 */ - Mono inConnection(Function> action) throws DataAccessException; + Mono inConnection(Function> action); /** * Execute a callback {@link Function} within a {@link Connection} scope. @@ -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 */ - Flux inConnectionMany(Function> action) throws DataAccessException; + Flux inConnectionMany(Function> action); } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java index 1086ef49339..f0884d07f27 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java @@ -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. * *

Use the static factory method {@link #create(ConnectionFactory)} or obtain * a {@linkplain DatabaseClient#builder() builder} to create an instance. diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java index 18c485be1c9..a781664d804 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java @@ -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 { } @Override - public Mono inConnection(Function> action) throws DataAccessException { + public Mono inConnection(Function> action) { Assert.notNull(action, "Callback object must not be null"); Mono connectionMono = getConnection().map( connection -> new ConnectionCloseHolder(connection, this::closeConnection)); @@ -130,7 +129,7 @@ class DefaultDatabaseClient implements DatabaseClient { } @Override - public Flux inConnectionMany(Function> action) throws DataAccessException { + public Flux inConnectionMany(Function> action) { Assert.notNull(action, "Callback object must not be null"); Mono connectionMono = getConnection().map( connection -> new ConnectionCloseHolder(connection, this::closeConnection));