Quantcast

Check if parameter exists?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Check if parameter exists?

Stephen Friedrich-2
I have a "baseQuery", i.e. a complex piece of sql, that I have put into an <sql> tag for reuse.
That snippet is used as a subquery in many different queries.
To optimize performance I'd like to add a where clause to the baseQuery itself like so:
        <where>
            <if test="projectId != null">
                t.project_id = ${projectId}
            </if>
            <if test="taskId != null">
                and t.id = ${taskId}
            </if>
        </where>
The problem is that neither "projectId" nor "taskId" parameters are present in all queries.
How can I check if the specific query has these parameters?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Check if parameter exists?

Eduardo Macarron
Use _parameter.containsKey(xxx)

El día 20 de abril de 2012 17:23, Stephen Friedrich
<[hidden email]> escribió:

> I have a "baseQuery", i.e. a complex piece of sql, that I have put into an
> <sql> tag for reuse.
> That snippet is used as a subquery in many different queries.
> To optimize performance I'd like to add a where clause to the baseQuery
> itself like so:
>         <where>
>             <if test="projectId != null">
>                 t.project_id = ${projectId}
>             </if>
>             <if test="taskId != null">
>                 and t.id = ${taskId}
>             </if>
>         </where>
> The problem is that neither "projectId" nor "taskId" parameters are present
> in all queries.
> How can I check if the specific query has these parameters?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Check if parameter exists?

Stephen Friedrich-2
Thanks a million! Works perfectly and makes all the difference for my app (10 times speedup for common use cases).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Check if parameter exists?

Mike Fotiou
In reply to this post by Eduardo Macarron
Hi Eduardo,

  What is this mysterious "_parameter" value?  Does it represent the parameter map that Mybatis generates when more than one parameter is used in the call to the mapper statement?

Thanks,

Mike

On Fri, Apr 20, 2012 at 11:37 AM, Eduardo Macarron <[hidden email]> wrote:
Use _parameter.containsKey(xxx)

El día 20 de abril de 2012 17:23, Stephen Friedrich
<[hidden email]> escribió:
> I have a "baseQuery", i.e. a complex piece of sql, that I have put into an
> <sql> tag for reuse.
> That snippet is used as a subquery in many different queries.
> To optimize performance I'd like to add a where clause to the baseQuery
> itself like so:
>         <where>
>             <if test="projectId != null">
>                 t.project_id = ${projectId}
>             </if>
>             <if test="taskId != null">
>                 and t.id = ${taskId}
>             </if>
>         </where>
> The problem is that neither "projectId" nor "taskId" parameters are present
> in all queries.
> How can I check if the specific query has these parameters?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Check if parameter exists?

Eduardo Macarron
The input parameter is always stored under the key _parameter in the
OGNL context.
Loading...