ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Berry" <chriswbe...@gmail.com>
Subject Re: <parameterMap> and <update> ???
Date Fri, 07 Jul 2006 00:19:48 GMT
Yes, you are right.

But like I said in the original text, I am wiring Axis-generated
"XMLBeans" (i.e. beans generated from the WSDL/XSD definitions of a
web service) directly to iBatis SQLMaps. Thus, I can end up with
almost zero code!! This is really cool. And I eventually hope to write
a code generator for this, so that I can generate CRUD data services
"for free".

But Axis tends to wrap up integers and the like into it's own type
classes (e.g. UnsignedInt, UnsignedLong, etc.). My current workaround
solution is to build a "wrapper bean" around the Axis XMLBean to
handle the conversion (essentially what you are proposing). But this
is defeats the nice direct mapping, where the Axis generated bean is
my DAO -- which indeed it is to the rest of the system. The current
alternative introduces an unnecessary interim Object.

Thanks for all your help,
Cheers
-- Chris

On 7/6/06, Jeff Butler <jeffgbutler@gmail.com> wrote:
>
> You're right - no way to express the handler here.  But I would submit that
> you don't need it here.  iBATIS will return an Integer from the insert
> statement and you can change it to your desired type in your DAO method.
> You would right the same kind of code in a type handler.
>
>
> Jeff Butler
>
>
>
> On 7/5/06, Chris Berry <chriswberry@gmail.com> wrote:
> > Does that work with this syntax??
> > I don't see how to express the Handler here??
> > Thanks for all your help.
> > Cheers,
> > -- Chris
> >
> > <insert id="insertBlogEntryMySQL" parameterClass="blogEntryBean" >
> >    INSERT INTO Blog (Name, Title, Text, CreateUTC)
> >    VALUES (#name#, #title#, #text#, #createUTC#)
> >
> >    <selectKey keyProperty="id" resultClass="int" >
> >      SELECT LAST_INSERT_ID()
> >    </selectKey>
> > </insert>
> >
> >
> > On 7/4/06, Jeff Butler < jeffgbutler@gmail.com> wrote:
> > >
> > > Hold off on the JIRA issue - I just wrote a test and the select key DOES
> > > honor the type handler if you specify it on the generated field.  This
> this
> > > mapping worked in my test:
> > >
> > > <insert id="testInsert" parameterClass="test.Animal">
> > >   <selectKey resultClass="test.WierdKey" keyProperty="id">
> > >     select max(id) + 1 from Animal <!-- bad practice - just for test -->
> > >   </selectKey>
> > >   insert into Animal values (#id,handler=test.WierdKeyHandler#, #type#,
> > > #name#)
> > > </insert>
> > >
> > > Try it out.
> > >
> > >
> > > Jeff Butler
> > >
> > >
> > >
> > >
> > > On 7/4/06, Jeff Butler <jeffgbutler@gmail.com> wrote:
> > > >
> > > >
> > > > Currently there is no way to use a type handler with <selectKey>
- but
> I
> > > think that would be a logical enhancement for iBATIS.  If you want, make
> a
> > > new JIRA issue for this.  Or, if you don't want to access JIRA let me
> know
> > > and I'll do it.
> > > >
> > > >
> > > > Jeff Butler
> > > >
> > > >
> > > > On 7/4/06, Chris Berry <chriswberry@gmail.com > wrote:
> > > > > This stuff works great!!
> > > > > Is there anyway to use this to specify a TypeHandler with
> <selectkey> ??
> > > > >
> > > > > <insert id="insertBlogEntryMySQL" parameterClass="blogEntryBean"
>
> > > > >    insert into Blog (Name, Title, Text) values (#name#, #title#,
> #text#)
> > > > >
> > > > >    <selectKey keyProperty="idInt" resultClass="int" >
> > > > >      select LAST_INSERT_ID()
> > > > >    </selectKey>
> > > > > </insert>
> > > > >
> > > > > Thanks,
> > > > > -- Chris
> > > > >
> > > > >
> > > > > On 7/4/06, Chris Berry < chriswberry@gmail.com> wrote:
> > > > > > Thank you Jeff
> > > > > >
> > > > > > On 7/4/06, Jeff Butler <jeffgbutler@gmail.com > wrote:
> > > > > > >
> > > > > > > There's a link here:
> > > > > > >
> > > > > > > http://ibatis.apache.org/javadownloads.html
> > > > > > >
> > > > > > > "Latest Open Office Documents in Subversion", you want
> > > iBATIS-SqlMaps-2.pdf.
> > > > > > >
> > > > > > > The syntax is:
> > > > > > >
> > > > > > >
> > >
> #propertyName,javaType=?,jdbcType=?,mode=?,nullValue=?,handler=?#
> > > > > > >
> > > > > > >
> > > > > > > Jeff Butler
> > > > > > >
> > > > > > >
> > > > > > > On 7/4/06, Chris Berry < chriswberry@gmail.com> wrote:
> > > > > > > > Thanks Jeff.
> > > > > > > > For posterity (and to save me and others the trouble
of
> finding
> > > the
> > > > > > > > pdf in SVN ;-) would you mind posting the syntax??
> > > > > > > > Thank you.
> > > > > > > > Cheers,
> > > > > > > > -- Chris
> > > > > > > >
> > > > > > > > On 7/4/06, Jeff Butler < jeffgbutler@gmail.com>
wrote:
> > > > > > > > >
> > > > > > > > > If you use a parameter map, then you need to
use question
> marks
> > > in the
> > > > > > > > > statement rather than named parameters.  This
is why we
> rarely
> > > recommend
> > > > > > > > > using formal parameters maps - the inline maps
seem more
> > > intuitive.
> > > > > > > > >
> > > > > > > > > There is syntax with inline parameter maps to
add type a
> type
> > > handler -
> > > > > > > see
> > > > > > > > > the latest sqlmap pdf in SVN for details (I just
recently
> added
> > > > > > > > > documentation for it, but it's been available
for quite some
> > > time).
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Jeff Butler
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > On 7/4/06, Chris Berry < chriswberry@gmail.com
> wrote:
> > > > > > > > > > Greetings,
> > > > > > > > > > This question is related to a previous post
I previously
> made
> > > about
> > > > > > > > > > <selectkey>, but this one is about
using <update> and
> > > <parameterMap>
> > > > > > > > > >
> > > > > > > > > > I am using iBatis coupled with Axis. This
is a great
> > > combination. Axis
> > > > > > > > > > generates "XMLBeans" for the Request/Response,
and I map
> them
> > > directly
> > > > > > > > > > into SQLMaps using iBatis. Thus, very little
code is
> required.
> > > > > > > > > >
> > > > > > > > > > Axis tends to wrap primitives (from the
XSD) in it's own
> types
> > > (e.g.
> > > > > > > > > > UnsignedLong). This is not normally a problem,
except when
> > > dealing
> > > > > > > > > > with keys.
> > > > > > > > > >
> > > > > > > > > > I am having a great deal of trouble getting
<parameterMap>
> to
> > > work
> > > > > > > > > > with <update>. Could someone please
help?? I must be doing
> > > something
> > > > > > > > > > silly, but I cannot see what it is???
> > > > > > > > > >
> > > > > > > > > > Thanks,
> > > > > > > > > > -- Chris
> > > > > > > > > >
> > > > > > > > > > Details follow::
> > > > > > > > > >
> > > > > > > > > > <parameterMap class="blogEntryClass"
id="blogEntryParams"
> >
> > > > > > > > > >    <parameter property="name" />
> > > > > > > > > >    <parameter property="title" />
> > > > > > > > > >    <parameter property="text" />
> > > > > > > > > >    <parameter property="updateUTC" />
> > > > > > > > > >    <parameter property="id"
> > > > > > > > > >            jdbcType="INTEGER"
> > > > > > > > > >
> > > > > > > javaType="org.apache.axis.types.UnsignedLong "
> > > > > > > > > >
> > > > > > > > >
> > > > > > >
> > >
> typeHandler="etrade.utils.ibatis.UnsignedLongTypeHandler"
> > > > > > > > > />
> > > > > > > > > > </parameterMap>
> > > > > > > > > >
> > > > > > > > > > <update id="updateBlogEntry"
> parameterMap="blogEntryParams">
> > > > > > > > > >    update Blog set Name=#name#, Title=#title#,
> Text=#text#,
> > > > > > > > > > UpdateUTC=#updateUTC# where Id=#id#
> > > > > > > > > > </update>
> > > > > > > > > >
> > > > > > > > > > I always get a
> > > > > > > > > >    [junit] --- The error occurred in config/sqlMap-
> blog.xml.
> > > > > > > > > >    [junit] --- The error occurred while
applying a
> parameter
> > > map.
> > > > > > > > > >    [junit] --- Check the blogEntryParams.
> > > > > > > > > >    [junit] --- Check the parameter mapping
for the 'name'
> > > property.
> > > > > > > > > >    [junit] --- Cause: java.sql.SQLException:
Parameter
> index
> > > out of
> > > > > > > > > > range (1 > number of parameters, which
is 0).]; nested
> > > exception is
> > > > > > > > > > com
> > > > > > > > > >
> > > .ibatis.common.jdbc.exception.NestedSQLException:
> > > > > > > > > >
> > > > > > > > > > I get this error in whatever order I put
together the
> > > > > > > <parameterMap>!!!
> > > > > > > > > >
> > > > > > > > > > The BlogEntry_t Class looks like this::
> > > > > > > > > >
> > > > > > > > > > public class BlogEntry_t  implements java.io.Serializable
> {
> > > > > > > > > >    .....
> > > > > > > > > >    public
> org.apache.axis.types.UnsignedLong
> > > getId()
> > > > > > > {
> > > > > > > > > >        return id;
> > > > > > > > > >    }
> > > > > > > > > >    public void setId(
> > > > > > > org.apache.axis.types.UnsignedLong
> > > > > > > > > id) {
> > > > > > > > > >        this.id = id;
> > > > > > > > > >    }
> > > > > > > > > >    ......
> > > > > > > > > >
> > > > > > > > > > I cannot see what is wrong with my <parameterMap>
????
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > >
> > >
> -----------------------------------------------------------------------
> > > > > > > > > > But if I DON'T use a <parameterMap>,
and do this
> > > > > > > > > >
> > > > > > > > > > <update id="updateBlogEntry"
> parameterClass="blogEntryBean">
> > > > > > > > > >    update Blog set Name=#name#, Title=#title#,
> Text=#text#,
> > > > > > > > > > UpdateUTC=#updateUTC# where Id=#idInt#
> > > > > > > > > > </update>
> > > > > > > > > >
> > > > > > > > > > And then build a "wrapper Bean", like this
> > > > > > > > > >
> > > > > > > > > > public class BlogEntryBean
> > > > > > > > > > extends BlogEntry_t
> > > > > > > > > > {
> > > > > > > > > > .....
> > > > > > > > > > public BlogEntryBean( BlogEntry_t base )
> > > > > > > > > > {
> > > > > > > > > >    .....
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > .....
> > > > > > > > > > public int getIdInt()
> > > > > > > > > > {
> > > > > > > > > >    org.apache.axis.types.UnsignedLong uid
> =
> > > > > > > > > super.getId ();
> > > > > > > > > >    return uid.intValue();
> > > > > > > > > > }
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > And call like this::
> > > > > > > > > >    getSqlMapClientTemplate().update(
> > > > > > > "updateBlogEntry",
> > > > > > > > > new
> > > > > > > > > > BlogEntryBean(entry)  );
> > > > > > > > > >
> > > > > > > > > > Then it works perfectly.
> > > > > > > > > >
> > > > > > > > > > But I really don't want to use a wrapper
Bean. It would be
> so
> > > much
> > > > > > > > > > cleaner without one.
> > > > > > > > > > (I am trying to establish a pattern for
building
> Axis/iBatis
> > > web
> > > > > > > > > > services at my company)
> > > > > > > > > >
> > > > > > > > > > Thanks,
> > > > > > > > > > -- Chris
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
>

Mime
View raw message