Skip to content

SqlParameterSource needs method for extracting parameter names [SPR-16361] #20908

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

Closed
spring-projects-issues opened this issue Jan 9, 2018 · 7 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 9, 2018

Philippe Marschall opened SPR-16361 and commented

NamedParameterJdbcOperations supports passing in custom implementations of SqlParameterSource. Unfortunately doing so silently breaks. The issue is that SqlParameterSource offers no way of accessing the names of the parameters so SqlParameterSourceUtils#extractCaseInsensitiveParameterNames has to cast to the implementation classes BeanPropertySqlParameterSource and MapSqlParameterSource. For any other implementation class an empty map is returned.


Affects: 5.0.2

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I suppose you're using SimpleJdbcInsert and friends there? Parameter name extraction isn't needed for regular NamedParameterJdbcTemplate usage but is indeed used for matching purposes in insert and call operation objects.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've introduced a getParameterNames() method on SqlParameterSource, with a default implementation that returns null for not determinable. Being at it, I've also added default implementations of getSqlType and getTypeName.

@spring-projects-issues
Copy link
Collaborator Author

Philippe Marschall commented

Thanks for the quick response. Actually we were using NamedParameterJdbcTemplate#query(String, SqlParameterSource, RowCallbackHandler)

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

How is SqlParameterSourceUtils#extractCaseInsensitiveParameterNames being reached there? It only seems to be called from Table/CallMetaDataContext which is only being used by AbstractJdbcInsert/Call.

@spring-projects-issues
Copy link
Collaborator Author

Philippe Marschall commented

I confused two things. We have a custom NamedParameterJdbcTemplate subclass that uses Oracle extensions (OraclePreparedStatement#setObjectAtName) to directly bind parameters by name without having to parse and rewrite the query.

We could contribute the implementation if that is of interest, it would need some cleanup (eg. we compile against Oracle classes which would be a no-go for Spring).

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Alright, my implementation here should be good to go then.

As for the Oracle extension, you could consider submitting it to the Spring Data JDBC Extensions project which has plenty of Oracle extensions already (built against the Oracle JDBC driver API): https://github.com/spring-projects/spring-data-jdbc-ext/tree/master/spring-data-oracle

@spring-projects-issues
Copy link
Collaborator Author

Philippe Marschall commented

Thank you, I wasn't aware of this.

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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants