Skip to content

A custom annotation above the method to generate SQL by the name of the method #1864

Closed
@KirillKurdyukov

Description

@KirillKurdyukov

I'm trying to make an annotation that will participate in SQL generation on a spring-data-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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.com

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions