feat: Support adding @YdbType annotation to method parameters
To cover the following (and all similar) case:
interface MyRepository extends ListCrudRepository<MyEntity, String> {
@Query(
"""
SELECT <....>
<....>
LIMIT :limit
"""
)
List<MyEntity> findWithLimit(@Param("limit") long limit);
}
The inferred limit parameter type here is Int64, while YDB requires it to be exaclty UInt64.
There are other cases where implicit type conversion fails. So a way to control this behavior would be great. An existing @YdbType annotation seems like a good solution.
@zdazzy Existing YdbMappingJdbcConverter should solve this. This custom JdbcConverter is applied on both named and positional parameters.
Have you extended the AbstractYdbJdbcConfiguration?
@mipo256 The annotation is currently only applicable to fields. Placing it on method parameter will result in a compilation error. The issue has nothing to do with configuration.
Yes, I got the general idea of what you're trying to do.
CC: @KirillKurdyukov please, add the pending-design tag for the issue
The first top-level review of the problem unravels the following approach.
We can specify the custom RepositoryFactoryBeanSupport in the @EnableJdbcRepositories, extended from JdbcRepositoryFactoryBean likely. We need it to override the creation of the JdbcRepositoryFactory child that has it's own QueryLookupStrategy defined. And here, we can construct our own QueryMethod with our own implementation of getParameters().
That would solve the problem. However, there are a couple of caveats.
- This would require to extend a lot of stuff from the original Spring Data Commons/Spring Data JDBC infrastructure. That is generally not a big deal, since it is designed in this way specifically
- The larger problem is that the
JdbcQueryLookupStrategythat is native to Spring Data JDBC, likeCreateIfNotFoundQueryLookupStrategy, which is used by default, is not a public API. Therefore, we would have to extendRelationalQueryLookupStrategyand duplicate some code from the original source tree.
So, we need to think about it more deeply.
CC: @KirillKurdyukov
Related https://github.com/spring-projects/spring-data-relational/issues/1998
UPDATE: After discussion with Spring Data team: The corresponding Spring Data JDBC change would be introduced in 4.0.x major release. When this will be done, we'll be able to implement this feature.
CC: @zdazzy @KirillKurdyukov
UPDATE: After discussion with Spring Data team: The corresponding Spring Data JDBC change would be introduced in 4.0.x major release. When this will be done, we'll be able to implement this feature.
Thanks Misha!
Related https://github.com/spring-projects/spring-data-commons/pull/3259