ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: transparent values to SQL statements?
Date Sat, 14 Jul 2007 04:31:07 GMT
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 <shan.ss@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.
>
>

Mime
View raw message