Skip to content

GH-2727: Ensure JDBC queries are logged #2730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2019

Conversation

artembilan
Copy link
Member

Fixes: #2727

The JdbcTemplate logs a message for the sql to execute when it is
supplied by the QueryProvider.

  • Refactor JdbcPollingChannelAdapter to use new introduced internal
    PreparedStatementCreatorWithMaxRows with the QueryProvider
  • Refactor JdbcMessageHandler to instantiate a generatedKeysStatementCreator
    based on the PreparedStatementCreatorFactory
  • Verify in the JdbcOutboundGatewayParserTests that both fixes logs
    sql queries properly

this.jdbcOperations.update(this.updateSql, this.sqlParameterSourceFactory.createParameterSource(obj));
}

private static final class PreparedStatementCreatorWithMaxRows implements PreparedStatementCreator, SqlProvider {
Copy link
Contributor

@garyrussell garyrussell Feb 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we implement all the delegate's interfaces?

	private class PreparedStatementCreatorImpl
			implements PreparedStatementCreator, PreparedStatementSetter, SqlProvider, ParameterDisposer {

I see code like this in the template...

			finally {
				if (pss instanceof ParameterDisposer) {
					((ParameterDisposer) pss).cleanupParameters();
				}
			}

Fixes: spring-projects#2727

The `JdbcTemplate` logs a message for the sql to execute when it is
supplied by the `QueryProvider`.

* Refactor `JdbcPollingChannelAdapter` to use new introduced internal
`PreparedStatementCreatorWithMaxRows` with the `QueryProvider`
* Refactor `JdbcMessageHandler` to instantiate a `generatedKeysStatementCreator`
based on the `PreparedStatementCreatorFactory`
* Verify in the `JdbcOutboundGatewayParserTests` that both fixes logs
sql queries properly
@garyrussell garyrussell merged commit 04875b7 into spring-projects:master Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an ability to log SQL queries executing in JdbcTemplate class provided by JdbcPollingChannelAdapter class when debug is enabled.
2 participants