ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brent Ryan" <br...@blackboard.com>
Subject RE: iBatis enhancements (Annotations and/or Dynamic beanutils support)
Date Wed, 03 May 2006 10:14:59 GMT
ahhh... now I see.  Thanks for enlightening me guys.

Brent


-----Original Message-----
From:	Yusuf [mailto:Yusuf@ekalife.co.id]
Sent:	Tue 5/2/2006 9:15 PM
To:	user-java@ibatis.apache.org
Cc:	
Subject:	RE: iBatis enhancements (Annotations and/or Dynamic beanutils support)

Oh... All this time I thought that was a bug :)
Thanks for the correction.
 
Yusuf

-----Original Message-----
From: Jeff Butler [mailto:jeffgbutler@gmail.com]
Sent: Wednesday, May 03, 2006 10:52 AM
To: user-java@ibatis.apache.org
Subject: Re: iBatis enhancements (Annotations and/or Dynamic beanutils
support)


iBATIS has special code to deal with HashMaps.  If in your mapping you
specify #someProperty#, then iBATIS will call
HashMap.get("someProperty") - it has essentially the same effect as the
DynaBean functionality. 
 
The values in the HashMap can be of any type.  iBATIS infers the proper
JDBC type from the Java type just as it does with regular Java beans.
iBATIS does not read the database meta data, it makes reasonable
assumptions from the Java types.  You can also override this in the SQL
map.  For example, if you set java.util.Date in the HashMap, then iBATIS
will call the setDate() function.  If this is not what you want (as
Yusuf mentions), then you can specify the JDBC type like this:
 
insert into sometable (timestamp_column) values
(#timestampProperty:TIMESTAMP#)
 
BTW - Yusuf - this is not a bug, you need to override the JDBC type as
shown above and continue to use java.util.Date.
 
If you use a HashMap in a resultMap, then iBATIS will end up calling
getObject() - so the JDBC driver will decide what the returned data type
is.
 
Jeff Butler

 
On 5/2/06, Brent Ryan < bryan@blackboard.com
<mailto:bryan@blackboard.com> > wrote: 

Hmmm... Guess I missed that one in the documentation.  I'll give it a
whirl!  Although, I think the LazyDynaBean approach is cleaner, if it 
worked.

Can my value of my HashMap values be of type BigDecimal, String, or
Date?  How does iBatis know what to cast them as?  Does it work like I
think hibernate works where it goes and gets the meta data from the 
table to figure it out?

Brent

-----Original Message-----
From: Yusuf [mailto: Yusuf@ekalife.co.id <mailto:Yusuf@ekalife.co.id> ]
Sent: Tuesday, May 02, 2006 7:53 PM
To: user-java@ibatis.apache.org <mailto:user-java@ibatis.apache.org> 
Subject: RE: iBatis enhancements (Annotations and/or Dynamic beanutils
support)

actually, i think it worked like that.. i've been using HashMaps for
quite some time to pass parameters, just like Jeff said: 

HashMap hm = new HashMap();
hm.put(fieldName, value);
service.insert(hm);

one thing you have to notice though, i don't know if this is a bug, but
if you put a java.util.Date in a HashMap, then it'll only save the date 
value, not the time (example: the value
"01/01/1981 19:23:12" will be saved as "01/01/1981 00:00:00)

yusuf

-----Original Message-----
From: Brent Ryan [mailto:  <mailto:bryan@blackboard.com>
bryan@blackboard.com]
Sent: Wednesday, May 03, 2006 9:39 AM
To: user-java@ibatis.apache.org <mailto:user-java@ibatis.apache.org> 
Subject: RE: iBatis enhancements (Annotations and/or Dynamic beanutils 
support)


How would I do the sqlmap?  Is there a way to match the fieldName with a
column if I use the hashmap?  How would this look in the sql map?

<insert id="insertMerchant" parameterClass=" java.util.HashMap">
   <selectKey resultClass="int" keyProperty="merchantId" > select
EXTENDED_MERCHANT_SEQ.NEXTVAL as merchantId from DUAL</selectKey>
   insert into EXTENDED_MERCHANTS (MERCHANT_ID, NAME, CONTACT, EMAIL, 
PHONE, COMMENTS, VENDOR_ID, VENDOR_SITE_ID, INVOICE_EMAIL,
EXTERNAL_MERCHANT)
   values (#merchantId#, #merchantName#, #merchantContact#,
#merchantEmail#, #merchantPhone#, #merchantComments#, #vendorId#,
#vendorSiteId#, #invoiceEmail#, #externalMerchant#) 
</insert>

Will iBatis assume that the key of the hash matches the values()?  I
wasn't aware that this is how it worked... Would it assume that
everything in the hash is in the same order as the columns?  I don't 
think it works like this... Does it?

And to answer your other questions....yes, I basically parse the text
file and cast the value to either BigDecimal or Date depending on
another configuration in a properties file. 

Brent

From: Jeff Butler [mailto: jeffgbutler@gmail.com
<mailto:jeffgbutler@gmail.com> ]
Sent: Tuesday, May 02, 2006 7:30 PM
To: user-java@ibatis.apache.org  <mailto:user-java@ibatis.apache.org> 
Subject: Re: iBatis enhancements (Annotations and/or Dynamic beanutils
support)


You didn't say how you were getting "value" (I'm assuming you must parse
the text line and do type conversions somewhere else), but why not 
something as simple as this...

HashMap hm = new HashMap();
hm.put(fieldName, value);
service.insert(hm);

Am I missing something that's really fundamental?

Jeff Butler


On 5/2/06, Brent Ryan < bryan@blackboard.com
<mailto:bryan@blackboard.com> > wrote:

       If I have a text file with fields name, email, phone and I want
to load this into a table using iBatis... how would you do this?

       Example text file:
       brent, abc@something.com <mailto:abc@something.com> , 5555555555

       //This would normally be loaded from a properties file
       String fieldName = "name"; 

       DynaBean obj = new LazyDynaBean();

       PropertyUtils.set(obj, fieldName, value);

       //insert my data using iBatis
       service.insert(obj);

       Now, how can I do that with a hashmap? 


       Brent


       From: Jeff Butler [mailto: jeffgbutler@gmail.com
<mailto:jeffgbutler@gmail.com>  ]

       Sent: Tuesday, May 02, 2006 7:10 PM

       To: user-java@ibatis.apache.org
<mailto:user-java@ibatis.apache.org> 
       Subject: Re: iBatis enhancements (Annotations and/or Dynamic
beanutils support)




Is there some reason that a HashMap won't work for you here?  It works
fine in iBATIS with exactly the syntax you've specified below.  You're 
probably doing the same amount of work to load up the DynaBean that you
would do to load a HashMap.

Regarding annotations - As I thought more about it I remembered that
we've just recently stopped supporting JDK 1.3!  I think it will be a
while before can sefely add any Java 5 specific features.

Jeff Butler


On 5/2/06, Brent Ryan < bryan@blackboard.com
<mailto:bryan@blackboard.com>  > wrote:

       Well, my usecase for beanutils is that I didn't want to have to
create POJO's at all.  I wanted my application and iBatis to figure out
dynamically the data that I'm putting into a database.  In this
particular application I have a bunch of configuration information in a 
properties file and one of the configurations is "fieldNames".  These
field names correspond directly to the fieldNames in my POJO's.

       If iBatis supported this then I would be able to specify 
something like this in my sqlmap:

       <typeAlias alias="merchant"
type="org.apache.commons.beanutils.LazyDynaBean"/>

       <insert id="insertMerchant" parameterClass="merchant"> 
           <selectKey resultClass="int" keyProperty="merchantId" >
select EXTENDED_MERCHANT_SEQ.NEXTVAL as merchantId from DUAL</selectKey>

           insert into EXTENDED_MERCHANTS (MERCHANT_ID, NAME, CONTACT, 
EMAIL, PHONE, COMMENTS, VENDOR_ID, VENDOR_SITE_ID, INVOICE_EMAIL,
EXTERNAL_MERCHANT)
           values (#merchantId#, #merchantName#, #merchantContact#,
#merchantEmail#, #merchantPhone#, #merchantComments#, #vendorId#, 
#vendorSiteId#, #invoiceEmail#, #externalMerchant#)
         </insert>

       Basically, I'm lazy and I didn't want to have to create a POJO.
It seems like I'm constantly having to enter the same field names over 
and over again...  This would just be one place to eliminate that.

       For annotations...  I wasn't really sure other then I've seen
some cool uses with the hibernate annotations.  Maybe replace some of
the result map configurations, default values, etc.. with annotations.
Other then that, I'm not sure of another use for this...

       Brent


        From: Jeff Butler [mailto:  <mailto:jeffgbutler@gmail.com>
jeffgbutler@gmail.com ]
       Sent: Tuesday, May 02, 2006 6:15 PM
       To: user-java@ibatis.apache.org
<mailto:user-java@ibatis.apache.org> 
       Subject: Re: iBatis enhancements (Annotations and/or Dynamic 
beanutils support)



       Regarding beanutils - this has been discussed on the list
several times.  The general feeling is that we want to keep the iBATIS
dependancies to a minimum, so I don't think we'll see direct support of 
DynaBeans.  You certainly could use a HashMap as a result class in
iBATIS, and then create LazyDynaMap instances from the returned
HashMaps.  This would give you DynaBean behavior and would work directly
with iBATIS today.  Is there something about that approach that doesn't 
work for you?

       Regarding annotations - could you be more specific about what
you're looking for?

       Jeff Butler


       On 5/2/06, Brent Ryan <  <mailto:bryan@blackboard.com>
bryan@blackboard.com > wrote:

               Anyone know if Java 5 annotations or dynamic beanutils
support will work in a future version of iBatis?

               Brent




               This e-mail is intended only for the personal and 
confidential use of the recipient(s) named above.
               It may include Blackboard confidential and proprietary
information, and is not for redistribution.







       This e-mail is intended only for the personal and confidential 
use of the recipient(s) named above.
       It may include Blackboard confidential and proprietary
information, and is not for redistribution.



This e-mail is intended only for the personal and confidential use of 
the recipient(s) named above.
It may include Blackboard confidential and proprietary information, and
is not for redistribution.






Mime
View raw message