-
Notifications
You must be signed in to change notification settings - Fork 197
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
JdbcRepository - support ability to tokenize and inject table name in @Query strings - particularly useful for inheritance #2944
Comments
JDBC and drivers don't support parametrizing the table name |
Doesn't Micronaut data take care of taking the supplied Query value and generating a prepared statement of sorts? If so, can Micronaut data not substitute the table name token with the table name value from the associated entity class - just as it would with any other query defined in the repository that did not use an @query annotation? |
It does it at the compilation time, we try to avoid doing this kind of stuff at runtime |
Can above not be achieved at compile too though? |
Where do you store the token? |
The developer would put something static like @query(select * from |
Feature description
Consider a set of tables with a common set of base columns and a common set of queries that would apply to said columns.
Should the queries associated with the said columns not be achievable using the smart query finder method naming strategy, then one needs to leverage @query("SELECT XXX FROM YYY WHERE ZZZ") style annotations.
It would be extremely useful if we could tokenize the table YYY piece above and automatically substitute with the entity model classes table name and thus not have to hardcode the table name in the query.
It is particularly relevant when using JdbcRepository inheritance ... e.g.
public interface RetryableOperationsTaskRepository<E extends RetryableOperationsTask, I extends Long> extends PageableRepository<E, I> {
}
@JdbcRepository
public abstract class RetryableOperationsSalesTaskRepository implements RetryableOperationsTaskRepository<RetryableOperationsSalesTask, Long> {
}
@JdbcRepository
public abstract class RetryableOperationsMarketingTaskRepository implements RetryableOperationsTaskRepository<RetryableOperationsMarketingTask, Long> {
}
The only difference between the two overriding findAndLockApplicableTasks methods above is the table name.
Ideally we would not have needed to override these methods and instead could have inherited directly from the top-level interface.
However we currently have no way in the interface @query to have some type of dynamic tokenized table_name that can be substituted in.
We are looking for something like the following in the top-level interface -
The text was updated successfully, but these errors were encountered: