Skip to content
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

Allow alternative JdbcOperations implementations #23066

Closed
wants to merge 1 commit into from

Conversation

marschall
Copy link
Contributor

@marschall marschall commented May 30, 2019

Change various JDBC abstraction classes to allow them to work with
JdbcOperations instead of JdbcTemplate. This allows the usage of
custom JdbcOperations that for example perform additional logging.

The following classes have been updated

  • AbstractJdbcCall
  • SimpleJdbcCall
  • AbstractJdbcInsert
  • SimpleJdbcInsert
  • JdbcBeanDefinitionReader
  • RdbmsOperation
  • StoredProcedure

This is a backwards compatible change. All existing JdbcTemplate
methods are kept.

Closes gh-23065

@marschall
Copy link
Contributor Author

This change is backwards compatible.

NamedParameterJdbcTemplate#getJdbcTemplate() already throws an exception when the JdbcOperations implementation is not a JdbcTemplate so I went for the same behavior.

This is similar to #8440 and I exclude JdbcDaoSupport for that reason.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 30, 2019
@jhoeller jhoeller self-assigned this Jun 7, 2019
Change various JDBC abstraction classes to allow them to work with
JdbcOperations instead of JdbcTemplate. This allows the usage of
custom JdbcOperations that for example perform additional logging.

The following classes have been updated

- AbstractJdbcCall
- SimpleJdbcCall
- AbstractJdbcInsert
- SimpleJdbcInsert
- JdbcBeanDefinitionReader
- RdbmsOperation
- StoredProcedure

This is a backwards compatible change. All existing JdbcTemplate
methods are kept.

Closes spring-projectsgh-23065
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 19, 2020
@jhoeller jhoeller added this to the 5.x Backlog milestone Jul 19, 2020
@jhoeller
Copy link
Contributor

Coming back to this, I'm wondering how beneficial it is to decorate JdbcOperations - rather than extend JdbcTemplate directly and add some logging in overridden methods, along the lines of #23106... RdbmsOperation for example is quite a JdbcTemplate wrapper, it is rather natural to keep interacting with JdbcTemplate proper there. Maybe we can make it easier to add custom logging in a JdbcTemplate subclass, we could consider a revision in that direction instead.

@jhoeller
Copy link
Contributor

From the perspective above, I'm closing this PR for the time being. A separate issue for extending JdbcTemplate along those lines would be welcome, although the existing extension possibilities might be sufficient for those purposes already.

@jhoeller jhoeller closed this Jul 12, 2023
@jhoeller jhoeller removed this from the 6.x Backlog milestone Jul 12, 2023
@snicoll snicoll added the status: declined A suggestion or change that we don't feel we should currently apply label Jul 12, 2023
@marschall
Copy link
Contributor Author

Favor composition over inheritance :-)

For reference, here's our JdbcOperations implementation https://github.com/marschall/jfr-jdbctemplate/blob/master/src/main/java/com/github/marschall/jfr/jdbctemplate/JfrJdbcOperations.java. At first glance it looks like the implementation would be simpler with a logging callback where we get the SQL query, row count and query duration without having to extract it ourselves. However due to the design of JFR we can not set the duration of an event explicitly. Instead we need to create and start an event before the operation and stop it afterwards. So we would need two callbacks, one before the execution that returns an event and a second after the execution that gets passed the event. I can't speak to the need of other monitoring solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for alternative JdbcOperations implementations
4 participants