ydb-java-dialects icon indicating copy to clipboard operation
ydb-java-dialects copied to clipboard

feat: Support adding @YdbType annotation to method parameters

Open zdazzy opened this issue 1 year ago • 8 comments

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 avatar Feb 13 '25 09:02 zdazzy

@zdazzy Existing YdbMappingJdbcConverter should solve this. This custom JdbcConverter is applied on both named and positional parameters.

Have you extended the AbstractYdbJdbcConfiguration?

mipo256 avatar Feb 17 '25 13:02 mipo256

@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.

zdazzy avatar Feb 20 '25 19:02 zdazzy

Yes, I got the general idea of what you're trying to do.

CC: @KirillKurdyukov please, add the pending-design tag for the issue

mipo256 avatar Feb 21 '25 05:02 mipo256

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.

  1. 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
  2. The larger problem is that the JdbcQueryLookupStrategy that is native to Spring Data JDBC, like CreateIfNotFoundQueryLookupStrategy, which is used by default, is not a public API. Therefore, we would have to extend RelationalQueryLookupStrategy and duplicate some code from the original source tree.

So, we need to think about it more deeply.

CC: @KirillKurdyukov

mipo256 avatar Feb 21 '25 06:02 mipo256

Related https://github.com/spring-projects/spring-data-relational/issues/1998

mipo256 avatar Feb 21 '25 06:02 mipo256

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

mipo256 avatar Mar 14 '25 09:03 mipo256

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

Thanks Misha!

KirillKurdyukov avatar Mar 17 '25 07:03 KirillKurdyukov

Related https://github.com/spring-projects/spring-data-commons/pull/3259

mipo256 avatar Mar 24 '25 10:03 mipo256