GH-3072: Allow JDBC inbound query changes

Resolves https://github.com/spring-projects/spring-integration/issues/3072

* Assert for selectQuery setter
This commit is contained in:
Gary Russell
2019-10-04 15:39:22 -04:00
committed by Artem Bilan
parent 2a8615539f
commit 7733da651f

View File

@@ -56,22 +56,22 @@ public class JdbcPollingChannelAdapter extends AbstractMessageSource<Object> {
private final NamedParameterJdbcOperations jdbcOperations;
private final String selectQuery;
private RowMapper<?> rowMapper;
private SqlParameterSource sqlQueryParameterSource;
private boolean updatePerRow = false;
private String updateSql;
private SqlParameterSourceFactory sqlParameterSourceFactory = new ExpressionEvaluatingSqlParameterSourceFactory();
private boolean sqlParameterSourceFactorySet;
private int maxRows = 0;
private volatile String selectQuery;
private volatile String updateSql;
/**
* Constructor taking {@link DataSource} from which the DB Connection can be
* obtained and the select query to execute to retrieve new rows.
@@ -89,7 +89,6 @@ public class JdbcPollingChannelAdapter extends AbstractMessageSource<Object> {
* @param selectQuery query to execute
*/
public JdbcPollingChannelAdapter(JdbcOperations jdbcOperations, String selectQuery) {
Assert.hasText(selectQuery, "'selectQuery' must be specified.");
this.jdbcOperations = new NamedParameterJdbcTemplate(jdbcOperations) {
@Override
@@ -105,7 +104,7 @@ public class JdbcPollingChannelAdapter extends AbstractMessageSource<Object> {
};
this.selectQuery = selectQuery;
setSelectQuery(selectQuery);
this.rowMapper = new ColumnMapRowMapper();
}
@@ -116,6 +115,16 @@ public class JdbcPollingChannelAdapter extends AbstractMessageSource<Object> {
}
}
/**
* Set the select query.
* @param selectQuery the query.
* @since 5.2.1
*/
public final void setSelectQuery(String selectQuery) {
Assert.hasText(selectQuery, "'selectQuery' must be specified.");
this.selectQuery = selectQuery;
}
public void setUpdateSql(String updateSql) {
this.updateSql = updateSql;
}