diff --git a/src/main/java/org/springframework/data/r2dbc/core/DatabaseClient.java b/src/main/java/org/springframework/data/r2dbc/core/DatabaseClient.java index 613917ef..6e090499 100644 --- a/src/main/java/org/springframework/data/r2dbc/core/DatabaseClient.java +++ b/src/main/java/org/springframework/data/r2dbc/core/DatabaseClient.java @@ -27,7 +27,6 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import java.util.function.UnaryOperator; import org.reactivestreams.Publisher; @@ -892,7 +891,7 @@ public interface DatabaseClient { * * @param filter the filter to be added to the chain. */ - default S filter(UnaryOperator filter) { + default S filter(Function filter) { Assert.notNull(filter, "Statement FilterFunction must not be null!"); diff --git a/src/main/java/org/springframework/data/r2dbc/core/DefaultDatabaseClient.java b/src/main/java/org/springframework/data/r2dbc/core/DefaultDatabaseClient.java index 37777d83..f4204c9c 100644 --- a/src/main/java/org/springframework/data/r2dbc/core/DefaultDatabaseClient.java +++ b/src/main/java/org/springframework/data/r2dbc/core/DefaultDatabaseClient.java @@ -272,15 +272,6 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { return new DefaultTypedExecuteSpec<>(byIndex, byName, sqlSupplier, filterFunction, typeToRead); } - /** - * Customization hook. - */ - protected DefaultTypedExecuteSpec createTypedExecuteSpec(Map byIndex, - Map byName, Supplier sqlSupplier, StatementFilterFunction filterFunction, - BiFunction mappingFunction) { - return new DefaultTypedExecuteSpec<>(byIndex, byName, sqlSupplier, filterFunction, mappingFunction); - } - /** * Customization hook. */ @@ -354,7 +345,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { String sql = getRequiredSql(sqlSupplier); - Function executeFunction = it -> { + Function statementFactory = it -> { if (logger.isDebugEnabled()) { logger.debug("Executing SQL statement [" + sql + "]"); @@ -412,7 +403,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { return statement; }; - Function> resultFunction = toFunction(sql, filterFunction, executeFunction); + Function> resultFunction = toFunction(sql, filterFunction, statementFactory); return new DefaultSqlResult<>(DefaultDatabaseClient.this, // sql, // @@ -582,7 +573,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { @SuppressWarnings("unchecked") protected class DefaultTypedExecuteSpec extends ExecuteSpecSupport implements TypedExecuteSpec { - private final @Nullable Class typeToRead; + private final Class typeToRead; private final BiFunction mappingFunction; DefaultTypedExecuteSpec(Map byIndex, Map byName, @@ -600,16 +591,6 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { } } - DefaultTypedExecuteSpec(Map byIndex, Map byName, - Supplier sqlSupplier, StatementFilterFunction filterFunction, - BiFunction mappingFunction) { - - super(byIndex, byName, sqlSupplier, filterFunction); - - this.typeToRead = null; - this.mappingFunction = mappingFunction; - } - @Override public TypedExecuteSpec as(Class resultType) { @@ -717,8 +698,8 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { this.page = Pageable.unpaged(); } - DefaultSelectSpecSupport(SqlIdentifier table, List projectedFields, Criteria criteria, Sort sort, - Pageable page) { + DefaultSelectSpecSupport(SqlIdentifier table, List projectedFields, @Nullable Criteria criteria, + Sort sort, Pageable page) { this.table = table; this.projectedFields = projectedFields; this.criteria = criteria; @@ -772,13 +753,13 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { } protected abstract DefaultSelectSpecSupport createInstance(SqlIdentifier table, List projectedFields, - Criteria criteria, Sort sort, Pageable page); + @Nullable Criteria criteria, Sort sort, Pageable page); } private class DefaultGenericSelectSpec extends DefaultSelectSpecSupport implements GenericSelectSpec { - DefaultGenericSelectSpec(SqlIdentifier table, List projectedFields, Criteria criteria, Sort sort, - Pageable page) { + DefaultGenericSelectSpec(SqlIdentifier table, List projectedFields, @Nullable Criteria criteria, + Sort sort, Pageable page) { super(table, projectedFields, criteria, sort, page); } @@ -861,7 +842,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { @Override protected DefaultGenericSelectSpec createInstance(SqlIdentifier table, List projectedFields, - Criteria criteria, Sort sort, Pageable page) { + @Nullable Criteria criteria, Sort sort, Pageable page) { return new DefaultGenericSelectSpec(table, projectedFields, criteria, sort, page); } } @@ -883,8 +864,8 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { this.mappingFunction = dataAccessStrategy.getRowMapper(typeToRead); } - DefaultTypedSelectSpec(SqlIdentifier table, List projectedFields, Criteria criteria, Sort sort, - Pageable page, @Nullable Class typeToRead, BiFunction mappingFunction) { + DefaultTypedSelectSpec(SqlIdentifier table, List projectedFields, @Nullable Criteria criteria, + Sort sort, Pageable page, Class typeToRead, BiFunction mappingFunction) { super(table, projectedFields, criteria, sort, page); @@ -975,7 +956,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { @Override protected DefaultTypedSelectSpec createInstance(SqlIdentifier table, List projectedFields, - Criteria criteria, Sort sort, Pageable page) { + @Nullable Criteria criteria, Sort sort, Pageable page) { return new DefaultTypedSelectSpec<>(table, projectedFields, criteria, sort, page, this.typeToRead, this.mappingFunction); } @@ -1223,11 +1204,11 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { private final @Nullable Class typeToUpdate; private final @Nullable SqlIdentifier table; - private final Update assignments; - private final Criteria where; + private final @Nullable Update assignments; + private final @Nullable Criteria where; - DefaultGenericUpdateSpec(@Nullable Class typeToUpdate, @Nullable SqlIdentifier table, Update assignments, - Criteria where) { + DefaultGenericUpdateSpec(@Nullable Class typeToUpdate, @Nullable SqlIdentifier table, + @Nullable Update assignments, @Nullable Criteria where) { this.typeToUpdate = typeToUpdate; this.table = table; this.assignments = assignments; @@ -1256,6 +1237,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { SqlIdentifier table; if (StringUtils.isEmpty(this.table)) { + Assert.state(this.typeToUpdate != null, "Type to update must not be null!"); table = dataAccessStrategy.getTableName(this.typeToUpdate); } else { table = this.table; @@ -1277,6 +1259,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { mapper = mapper.forType(this.typeToUpdate); } + Assert.state(this.assignments != null, "Update assignments must not be null!"); StatementMapper.UpdateSpec update = mapper.createUpdate(table, this.assignments); if (this.where != null) { @@ -1291,11 +1274,11 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { class DefaultTypedUpdateSpec implements TypedUpdateSpec, UpdateSpec { - private final @Nullable Class typeToUpdate; + private final Class typeToUpdate; private final @Nullable SqlIdentifier table; - private final T objectToUpdate; + private final @Nullable T objectToUpdate; - DefaultTypedUpdateSpec(@Nullable Class typeToUpdate, @Nullable SqlIdentifier table, T objectToUpdate) { + DefaultTypedUpdateSpec(Class typeToUpdate, @Nullable SqlIdentifier table, @Nullable T objectToUpdate) { this.typeToUpdate = typeToUpdate; this.table = table; this.objectToUpdate = objectToUpdate; @@ -1390,9 +1373,9 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { private final @Nullable Class typeToDelete; private final @Nullable SqlIdentifier table; - private final Criteria where; + private final @Nullable Criteria where; - DefaultDeleteSpec(@Nullable Class typeToDelete, @Nullable SqlIdentifier table, Criteria where) { + DefaultDeleteSpec(@Nullable Class typeToDelete, @Nullable SqlIdentifier table, @Nullable Criteria where) { this.typeToDelete = typeToDelete; this.table = table; this.where = where; @@ -1420,6 +1403,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { SqlIdentifier table; if (StringUtils.isEmpty(this.table)) { + Assert.state(this.typeToDelete != null, "Type to delete must not be null!"); table = dataAccessStrategy.getTableName(this.typeToDelete); } else { table = this.table; @@ -1608,9 +1592,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor { // Invoke method on target Connection. try { - Object retVal = method.invoke(this.target, args); - - return retVal; + return method.invoke(this.target, args); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } diff --git a/src/main/java/org/springframework/data/r2dbc/core/StatementFilterFunction.java b/src/main/java/org/springframework/data/r2dbc/core/StatementFilterFunction.java index c5a271f7..520b7ab6 100644 --- a/src/main/java/org/springframework/data/r2dbc/core/StatementFilterFunction.java +++ b/src/main/java/org/springframework/data/r2dbc/core/StatementFilterFunction.java @@ -61,5 +61,4 @@ public interface StatementFilterFunction { return (request, next) -> filter(request, afterRequest -> afterFilter.filter(afterRequest, next)); } - }