ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shannon, Bryan" <BShan...@Tribune.com>
Subject RE: Changing a sqlMap dynamically?
Date Wed, 12 Oct 2005 16:25:51 GMT
It looks like the original response from Larry *is* the way you want to do
it.

It is essentially an "on the fly" sql map.  I use this construct in a few
select cases (searches with arbitrarily complex arguments, etc.) 

I use it basically when I need to write my own SQL, but still have iBatis do
the black magic of turning rows and ResultSets into actual objects and
lists.  Works like a charm.  :-)

You still have to create a map; and give the map a name.  The VALUE that you
pass into it is SQL code you wrote arbitrarily.

Even using something like session.select("my arbitrary sql") won't work
because you'd still have to tell iBatis (somehow) what resultmap/class you
need to use, etc. etc.

Hope this helps!

-Bryan


-----Original Message-----
From: Dan Bradley [mailto:debradley@gmail.com]
Sent: Thursday, October 06, 2005 12:09 PM
To: lmeadors@apache.org
Cc: user-java@ibatis.apache.org
Subject: Re: Changing a sqlMap dynamically?


Hi Larry -

Thanks for the reply, but I think you misunderstood the question. I
understand that I can put arbitrary SQL into a named select element
within a sqlMap file. That then gets called, by name, from
SqlMapExecutor/Session.

What I'm wondering is if there's either:

- a way to (essentially) call session.select("my arbitrary sql")
instead of session.select("namedQuery")
- or to created new named mappings at runtime such that
select("namedQuery") is calling a query that doesn't exist in the XML
file on disk.

My goal is, if I have 10 entities, and they all have a query that
looks like "select * from tablename" and the only that that varies is
the tablename, I'd like to be able to have my Java create that query
on the fly. I'm looking to build a general framework that handles some
of the plumbing for me instead of requiring a lot of hand work to be
done building the XML files.

Thanks.

On 10/6/05, Larry Meadors <lmeadors@apache.org> wrote:
> <select id="getWhatever" resultClass="java.util.HashMap"
remapResults="true">
> $whateverSqlYouWant$
> </select>
>
> Larry
>
>
> On 10/6/05, Dan Bradley <debradley@gmail.com> wrote:
> > Using iBATIS you normally create an XML file with a sqlMap element
> > that defines SQL queries that can be referenced by name. Is it also
> > possible to create these queries dynamically, through Java, instead of
> > hard-coding them all in XML? I'm hoping to build some framework code
> > that will programatically create some common queries based on the
> > properties of an object, instead of writing a "getAll" or "getById"
> > query for every entity which varies only in the table name.
> >
> > SqlMapExecutor's query/insert/delete methods require the name of a
> > mapped statement and don't appear to allow arbitrary SQL. If iBATIS
> > supports what I'm looking for, where would you hook into the system in
> > order to create new mappings on the fly?
> >
> > Thanks.
> >
>

Mime
View raw message