|
18 | 18 | import io.r2dbc.spi.ConnectionFactory;
|
19 | 19 | import io.r2dbc.spi.Row;
|
20 | 20 | import io.r2dbc.spi.RowMetadata;
|
| 21 | +import io.r2dbc.spi.Statement; |
21 | 22 | import reactor.core.publisher.Mono;
|
22 | 23 |
|
23 | 24 | import java.util.Arrays;
|
|
26 | 27 | import java.util.function.Consumer;
|
27 | 28 | import java.util.function.Function;
|
28 | 29 | import java.util.function.Supplier;
|
| 30 | +import java.util.function.UnaryOperator; |
29 | 31 |
|
30 | 32 | import org.reactivestreams.Publisher;
|
31 | 33 |
|
|
37 | 39 | import org.springframework.data.r2dbc.query.Update;
|
38 | 40 | import org.springframework.data.r2dbc.support.R2dbcExceptionTranslator;
|
39 | 41 | import org.springframework.data.relational.core.sql.SqlIdentifier;
|
| 42 | +import org.springframework.util.Assert; |
40 | 43 |
|
41 | 44 | /**
|
42 | 45 | * A non-blocking, reactive client for performing database calls requests with Reactive Streams back pressure. Provides
|
@@ -142,6 +145,16 @@ interface Builder {
|
142 | 145 | */
|
143 | 146 | Builder exceptionTranslator(R2dbcExceptionTranslator exceptionTranslator);
|
144 | 147 |
|
| 148 | + /** |
| 149 | + * Configures a {@link ExecuteFunction} to execute {@link Statement} objects. |
| 150 | + * |
| 151 | + * @param executeFunction must not be {@literal null}. |
| 152 | + * @return {@code this} {@link Builder}. |
| 153 | + * @since 1.1 |
| 154 | + * @see Statement#execute() |
| 155 | + */ |
| 156 | + Builder executeFunction(ExecuteFunction executeFunction); |
| 157 | + |
145 | 158 | /**
|
146 | 159 | * Configures a {@link ReactiveDataAccessStrategy}.
|
147 | 160 | *
|
@@ -186,7 +199,7 @@ interface Builder {
|
186 | 199 | /**
|
187 | 200 | * Contract for specifying a SQL call along with options leading to the exchange.
|
188 | 201 | */
|
189 |
| - interface GenericExecuteSpec extends BindSpec<GenericExecuteSpec> { |
| 202 | + interface GenericExecuteSpec extends BindSpec<GenericExecuteSpec>, StatementFilterSpec<GenericExecuteSpec> { |
190 | 203 |
|
191 | 204 | /**
|
192 | 205 | * Define the target type the result should be mapped to. <br />
|
@@ -231,7 +244,7 @@ interface GenericExecuteSpec extends BindSpec<GenericExecuteSpec> {
|
231 | 244 | /**
|
232 | 245 | * Contract for specifying a SQL call along with options leading to the exchange.
|
233 | 246 | */
|
234 |
| - interface TypedExecuteSpec<T> extends BindSpec<TypedExecuteSpec<T>> { |
| 247 | + interface TypedExecuteSpec<T> extends BindSpec<TypedExecuteSpec<T>>, StatementFilterSpec<TypedExecuteSpec<T>> { |
235 | 248 |
|
236 | 249 | /**
|
237 | 250 | * Define the target type the result should be mapped to. <br />
|
@@ -866,4 +879,31 @@ interface BindSpec<S extends BindSpec<S>> {
|
866 | 879 | */
|
867 | 880 | S bindNull(String name, Class<?> type);
|
868 | 881 | }
|
| 882 | + |
| 883 | + /** |
| 884 | + * Contract for applying a {@link StatementFilterFunction}. |
| 885 | + * |
| 886 | + * @since 1.1 |
| 887 | + */ |
| 888 | + interface StatementFilterSpec<S extends StatementFilterSpec<S>> { |
| 889 | + |
| 890 | + /** |
| 891 | + * Add the given filter to the end of the filter chain. |
| 892 | + * |
| 893 | + * @param filter the filter to be added to the chain. |
| 894 | + */ |
| 895 | + default S filter(UnaryOperator<Statement> filter) { |
| 896 | + |
| 897 | + Assert.notNull(filter, "Statement FilterFunction must not be null!"); |
| 898 | + |
| 899 | + return filter((statement, next) -> next.execute(filter.apply(statement))); |
| 900 | + } |
| 901 | + |
| 902 | + /** |
| 903 | + * Add the given filter to the end of the filter chain. |
| 904 | + * |
| 905 | + * @param filter the filter to be added to the chain. |
| 906 | + */ |
| 907 | + S filter(StatementFilterFunction filter); |
| 908 | + } |
869 | 909 | }
|
0 commit comments