You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Shan Syed <sh...@gmail.com> on 2007/07/14 02:16:01 UTC

transparent values to SQL statements?

Hi,

I'd like to transparently send parameters to SQL functions, without having
to include those parameters always through my code.
For example,

<select id="getAllMatchingPeople" parameterClass="com.blah.Person"
resultMap="personParameterResult">
SELECT * from person
WHERE
lastname = #lastname#
AND
recordstatus = #recordstatus#
</select>

Where the "recordstatus" property is not inside my Person domain object, but
something configured separately; perhaps "injected" into the map object
somehow.

Thus, my code would look like this:
sqlMap.queryForList("getAllMatchingPeople", myPersonQueryByExampleObject);

Is there a way to achieve this in a straight forward manner? I don't want to
have multiple SQL function and fragments for the status, since
there could be many many statuses, all of which will be applied under
different contexts.

Re: transparent values to SQL statements?

Posted by Larry Meadors <lm...@apache.org>.
Is there a way to achieve this in a straight forward manner?

What you are asking for, no. :-)

It's possible, I think, but it would be a non-trivial exercise. My
guess is that you could create a proxy over the SqlMapClient that
would create a cglib enhanced version of your bean to add the property
on the fly.

However, if you could live with a query like this instead:

<select id="getAllMatchingPeople" resultMap="personParameterResult">
  SELECT * from person
  WHERE
  lastname = #person.lastname#
  AND
  recordstatus = #whatever.recordstatus#
</select>

You could put your beans in a map, and pass the map to the
SqlMapClient instead of the bean. That way, your beans stay pristine,
and you don't have to delve into the dark arts of bytecode
enhancement...you'd need a red lightsaber for that.

Larry


On 7/13/07, Shan Syed <sh...@gmail.com> wrote:
> Hi,
>
> I'd like to transparently send parameters to SQL functions, without having
> to include those parameters always through my code.
> For example,
>
> <select id="getAllMatchingPeople" parameterClass=" com.blah.Person"
> resultMap="personParameterResult">
> SELECT * from person
> WHERE
> lastname = #lastname#
> AND
> recordstatus = #recordstatus#
> </select>
>
> Where the "recordstatus" property is not inside my Person domain object, but
> something configured separately; perhaps "injected" into the map object
> somehow.
>
> Thus, my code would look like this:
> sqlMap.queryForList("getAllMatchingPeople", myPersonQueryByExampleObject);
>
> Is there a way to achieve this in a straight forward manner? I don't want to
> have multiple SQL function and fragments for the status, since
> there could be many many statuses, all of which will be applied under
> different contexts.
>
>