Add Nullability support into Java DSL
This commit is contained in:
@@ -2,4 +2,5 @@
|
||||
* Provides classes for supporting Java DSL for R2DBC components.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
@org.springframework.lang.NonNullFields
|
||||
package org.springframework.integration.r2dbc.dsl;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020-2022 the original author or authors.
|
||||
* Copyright 2020-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.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.endpoint.AbstractMessageSource;
|
||||
import org.springframework.integration.expression.ExpressionUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.r2dbc.core.ColumnMapRowMapper;
|
||||
import org.springframework.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.r2dbc.core.RowsFetchSpec;
|
||||
@@ -75,10 +76,12 @@ public class R2dbcMessageSource extends AbstractMessageSource<Publisher<?>> {
|
||||
|
||||
private boolean expectSingleResult = false;
|
||||
|
||||
private StandardEvaluationContext evaluationContext;
|
||||
private StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
|
||||
|
||||
@Nullable
|
||||
private String updateSql;
|
||||
|
||||
@Nullable
|
||||
private BiFunction<DatabaseClient.GenericExecuteSpec, Object, DatabaseClient.GenericExecuteSpec> bindFunction;
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
* Provides classes for supporting R2DBC inbound components.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
@org.springframework.lang.NonNullFields
|
||||
package org.springframework.integration.r2dbc.inbound;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class R2dbcMessageHandler extends AbstractReactiveMessageHandler {
|
||||
|
||||
private final StatementMapper statementMapper;
|
||||
|
||||
private StandardEvaluationContext evaluationContext;
|
||||
private StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
|
||||
|
||||
private Expression queryTypeExpression = new ValueExpression<>(Type.INSERT);
|
||||
|
||||
@@ -170,7 +170,8 @@ public class R2dbcMessageHandler extends AbstractReactiveMessageHandler {
|
||||
|
||||
private Mono<Void> handleDelete(Message<?> message) {
|
||||
if (this.tableNameExpression != null) {
|
||||
String tableName = evaluateTableNameExpression(message);
|
||||
String tableName = this.tableNameExpression.getValue(this.evaluationContext, message, String.class);
|
||||
Assert.notNull(tableName, "'tableNameExpression' must not evaluate to null");
|
||||
Criteria criteria = evaluateCriteriaExpression(message);
|
||||
StatementMapper.DeleteSpec deleteSpec =
|
||||
this.statementMapper.createDelete(tableName)
|
||||
@@ -188,7 +189,8 @@ public class R2dbcMessageHandler extends AbstractReactiveMessageHandler {
|
||||
|
||||
private Mono<Void> handleUpdate(Message<?> message) {
|
||||
if (this.tableNameExpression != null) {
|
||||
String tableName = evaluateTableNameExpression(message);
|
||||
String tableName = this.tableNameExpression.getValue(this.evaluationContext, message, String.class);
|
||||
Assert.notNull(tableName, "'tableNameExpression' must not evaluate to null");
|
||||
Map<String, Object> values = evaluateValuesExpression(message);
|
||||
Map<SqlIdentifier, Object> updateMap = transformIntoSqlIdentifierMap(values);
|
||||
Criteria criteria = evaluateCriteriaExpression(message);
|
||||
@@ -216,7 +218,8 @@ public class R2dbcMessageHandler extends AbstractReactiveMessageHandler {
|
||||
@SuppressWarnings("deprecation")
|
||||
private Mono<Void> handleInsert(Message<?> message) {
|
||||
if (this.tableNameExpression != null) {
|
||||
String tableName = evaluateTableNameExpression(message);
|
||||
String tableName = this.tableNameExpression.getValue(this.evaluationContext, message, String.class);
|
||||
Assert.notNull(tableName, "'tableNameExpression' must not evaluate to null");
|
||||
Map<String, Object> values = evaluateValuesExpression(message);
|
||||
|
||||
StatementMapper.InsertSpec insertSpec = this.statementMapper.createInsert(tableName);
|
||||
@@ -237,13 +240,6 @@ public class R2dbcMessageHandler extends AbstractReactiveMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private String evaluateTableNameExpression(Message<?> message) {
|
||||
String tableName =
|
||||
this.tableNameExpression.getValue(this.evaluationContext, message, String.class); // NOSONAR
|
||||
Assert.notNull(tableName, "'tableNameExpression' must not evaluate to null");
|
||||
return tableName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> evaluateValuesExpression(Message<?> message) {
|
||||
Assert.notNull(this.valuesExpression,
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
* Provides classes for supporting R2DBC outbound components.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
@org.springframework.lang.NonNullFields
|
||||
package org.springframework.integration.r2dbc.outbound;
|
||||
|
||||
Reference in New Issue
Block a user