Thanks for pointing that out, Frank. Unfortunately, I don't think that
creating bind names will often be very useful. Consider the situation
where I have an IN clause:
where X in
(
1,
2,
3
)
and I want to instead use enum constants for these three magic numbers.
To use bind, I'd first have to create 3 bind names, one for each of
the magic numbers, and then I could use the bind name in place of the
number. That would look something like this:
<select id="selectAllAccounts" resultMap="AccountMap">
<bind name="RETAIL" value="
@org.sample.beans...@RETAIL.toInt()" />
<bind name="RESELLER" value="
@org.sample.beans...@RESELLER.toInt()" />
<bind name="AGENT" value="
@org.sample.beans...@AGENT.toInt()" />
...
where X in
(
${RETAIL},
${RESELLER},
${AGENT}
)
I'd actually save typing by just using the enum constants in the SELECT
statement directly:
<select id="selectAllAccounts" resultMap="AccountMap">
...
where X in
(
${@org.sample.beans...@RETAIL.toInt()},
${@org.sample.beans...@RESELLER.toInt()},
${@org.sample.beans...@AGENT.toInt()}
)
If you were going to use a constant more than once, then using a bind
name would provide some benefit.
While typing this up, I thought it would be handy if I could just put
the enum class name in the bind name, and then add the individual enum
on the end, something like this:
<select id="selectAllAccounts" resultMap="AccountMap">
<bind name="ACCTTYPE" value=" @org.sample.beans.AccountTypeEnum" />
...
where X in
(
${ACCT...@RETAIL.toInt()},
${ACCT...@RESELLER.toInt()},
${ACCT...@AGENT.toInt()}
)
Alas this doesn't work. Type aliases don't work either. Oh well, I'm
happy to be able to use enums at all. We should document that
unadvertised feature.
Thanks.
On 4/22/2013 9:51 AM, Frank Mart�nez wrote:
> Additiona info: You can pass objects from the scripting context to the
> parameterization context using bind:
>
> <bind name="RESELER"
> value=" @org.sample.beans....@RESELLER.toInt__()" />
>
> Then you can use it in the parameterization contex:
>
> #{RELESER}
>
> Cheers,
>
> Frank.
>
>
> On Sun, Apr 21, 2013 at 11:52 PM, Guy Rouillier <
guy.ro...@gmail.com
> <mailto:
guy.ro...@gmail.com>> wrote:
>
> Well, I'll be. Intentionally or otherwise, the current MyBatis
> implementation (I tried 3.1.1) actually handles references to enums
> inside ${}. Here is a working example:
>
> <select id="selectAllAccounts" resultMap="AccountMap">
> SELECT
> id,
> name,
> ${@org.sample.beans....@RESELLER.toInt__()}
> as account_type_id
> FROM
> account
> WHERE
> -- ${} works, #{} does not
> account_type_id =
> ${@org.sample.beans....@RETAIL.toInt()__}
> </select>
>
>
> On 4/19/2013 2:17 AM, Guy Rouillier wrote:
>
> Please see
https://github.com/mybatis/__mybatis-3/issues/32
> <
https://github.com/mybatis/mybatis-3/issues/32>. Thanks.
> 2013/4/18 Frank Mart�nez <
mnes...@gmail.com
> <mailto:
mnes...@gmail.com>>:
>
> Hi Guy,
>
> Maybe you are looking for something like this:
>
https://github.com/mybatis/__velocity-scripting/commit/__9c2fb55193dff3dbe578f10fcb9dfa__1dbcc0e88d
> <mailto:
guy.ro...@gmail.com>>
> wrote:
>
>
> On 3/25/2013 7:30 PM, Guy Rouillier wrote:
>
>
> I see here
>
http://mybatis.github.com/__mybatis-3/configuration.html#__plugins
> <
http://mybatis.github.com/mybatis-3/configuration.html#plugins>
> that
> ParameterHandler is a plugin, so I can
> override it. Let me try
> that. My
> plan is to invoke the
> DefaultParameterHandler, and if that doesn't
> find
> the parameter value, then search along the
> classpath.
>
> What do you think of this approach? It
> would allow you to use enums
> (and static class variables) without having
> to create bind
> variables for
> each one.
>
>
>
> I thought about this issue again tonight while I
> was out walking the
> dog;
> I get all my insights then :). MyBatis 3.2 now
> permits pluggable
> scripting
> engines. I just reread
>
http://code.google.com/p/__mybatis/issues/detail?id=583
> mybatis-user+unsubscribe@__
googlegroups.com
> <mailto:
mybatis-user%2Bunsu...@googlegroups.com>.
> For more options, visit
>
https://groups.google.com/__groups/opt_out
> <
https://groups.google.com/groups/opt_out>.
>
>
>
>
>
> --
> Frank D. Mart�nez M.
>
> --
> You received this message because you are subscribed
> to the Google
> Groups
> "mybatis-user" group.
> To unsubscribe from this group and stop receiving
> emails from it,
> send an
> email to mybatis-user+unsubscribe@__
googlegroups.com
> <mailto:
mybatis-user%2Bunsu...@googlegroups.com>.
> For more options, visit
>
https://groups.google.com/__groups/opt_out
> <
https://groups.google.com/groups/opt_out>.
>
>
>
>
>
>
>
>
>
> --
> Guy Rouillier
>
> --
> You received this message because you are subscribed to the Google
> Groups "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to mybatis-user+unsubscribe@__
googlegroups.com
> <mailto:
mybatis-user%2Bunsu...@googlegroups.com>.
> For more options, visit
https://groups.google.com/__groups/opt_out
> <
https://groups.google.com/groups/opt_out>.
>
>
>
>
>
> --
> Frank D. Mart�nez M.
>
> --
> You received this message because you are subscribed to the Google
> Groups "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
mybatis-user...@googlegroups.com.