I’m trying to make an annotation that will participate in SQL generation on a spring-date-jdbc. You can say this is a hint for using an index in a database.
It can look like:
@UseIndex("name_index")
findByName(String name)
I found a way to implement an interceptor from JdbcRepositoryFactoryBean:
class UseIndexInterceptor : MethodInterceptor {
override fun invoke(invocation: MethodInvocation): Any? {
val useIndex = invocation.method.getAnnotation(UseIndex::class.java)
threadBoundUseIndex.set(useIndex)
try {
return invocation.proceed()
} finally {
threadBoundUseIndex.remove()
}
}
}
And use it in MySelectRenderContext
And the question is, is it possible to do something better?