I would tend towards using stringtemplate for this, doing it in the
rewriter certainly works, but you are now tied to your own grammar
(far from the end of the world).
I'll get some docu on the stringtemplate approach up today, if I can
(my son is sick, so my day is already a bit of a mess), which should
help a lot in general as well as with your specific case. For what you
described, given the class:
@ExternalizedSqlViaStringTemplate3
class Foo {
@SqlQuery
String findName(@Define("table") String table, @Bind("id") int id);
}
You'd have a template group file on the classpath at
/com/example/Foo.sql.stg with the contents
findName(table) <<
select name from user_<table> where id = :id
>>
(I took the liberty of changing the select so that the table name
suffix is being passed in)
When this executes it will find the template group for the Foo class,
and load the template from the template group for the method name
(findName). The @Define'd value wil be passed to the template (matches
on the formal parameter names) and interpolated. Then the resultant
sql will be parsed (rewritten) to determine the named parameters for
binding.
Regardless of which approach you take, be careful about the source of
strings for interpolation. The interpolation needs to happen before
the prepared statement is created (unlike named parameter binding) so
the string becomes part of the statement itself, opening the door to
sql injection attacks.
> --
>
>