Hi,
We need to parameterize the table name. In Jdbi, we can achieve this by using the StringTemplate. However, it is very complicated to use StringTemplate for this sort of easy task.
Example usage will be like this.
@SqlUpdate("insert into ::tablePrefix_my_table (id, name) values (:id, :name)")
void insert(@Replace("tablePrefix") String prefix, @Bind("id") int id, @Bind("name") String name);
Before running we replace the ::tablePrefix with prefix value.
We can also use this for IN queries.
@SqlUpdate("insert into something (id, name) values (::commaSeparatedIds)")
void insert(@Replace("commaSeparatedIds") String commaSeparatedIds, @Bind("id") int id, @Bind("name") String name);
As described [1], IN queries are handled by StringTemplate, however, there are two loops, one for generating the template, one for adding the parameters. By the proposed solution, there is one loop for generating the string and a replace.
Is this applicable?
--
_ob