Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 59178 invoked from network); 3 May 2006 03:52:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 May 2006 03:52:35 -0000 Received: (qmail 79960 invoked by uid 500); 3 May 2006 03:52:33 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 79934 invoked by uid 500); 3 May 2006 03:52:33 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 79920 invoked by uid 99); 3 May 2006 03:52:33 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 May 2006 20:52:33 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of jeffgbutler@gmail.com designates 66.249.82.206 as permitted sender) Received: from [66.249.82.206] (HELO wx-out-0102.google.com) (66.249.82.206) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 May 2006 20:52:31 -0700 Received: by wx-out-0102.google.com with SMTP id s8so63212wxc for ; Tue, 02 May 2006 20:52:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=CsNTbUi6YfX+w6PzaANe+8vzippVnjGPtOa26gm5eQHmtsb1RtenaCWQ80p5MBtutpnvrblk+dzx2+9sP8RwXtYgyuqaO1D1zkfxBd5TJWe0Pbyz5WbCAbsb7iSlkLdkGkxX7WnR2os2UbmigdPQOUWqErinIpoXr/Rf/N5hRhs= Received: by 10.70.28.6 with SMTP id b6mr1324843wxb; Tue, 02 May 2006 20:52:10 -0700 (PDT) Received: by 10.70.69.17 with HTTP; Tue, 2 May 2006 20:52:10 -0700 (PDT) Message-ID: Date: Tue, 2 May 2006 22:52:10 -0500 From: "Jeff Butler" To: user-java@ibatis.apache.org Subject: Re: iBatis enhancements (Annotations and/or Dynamic beanutils support) In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_13117_26456531.1146628330764" References: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_13117_26456531.1146628330764 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 JDB= C 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, i= f 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 show= n 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 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] > Sent: Tuesday, May 02, 2006 7:53 PM > To: 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 =3D 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:bryan@blackboard.com] > Sent: Wednesday, May 03, 2006 9:39 AM > To: 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? > > > select > EXTENDED_MERCHANT_SEQ.NEXTVAL as merchantId from DUAL > 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#) > > > 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] > Sent: Tuesday, May 02, 2006 7:30 PM > To: 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 =3D 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 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, 5555555555 > > //This would normally be loaded from a properties file > String fieldName =3D "name"; > > DynaBean obj =3D 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 ] > > Sent: Tuesday, May 02, 2006 7:10 PM > > To: 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 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: > > type=3D"org.apache.commons.beanutils.LazyDynaBean"/> > > > > select EXTENDED_MERCHANT_SEQ.NEXTVAL as merchantId from DUAL > > 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#) > > > 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:jeffgbutler@gmail.com ] > Sent: Tuesday, May 02, 2006 6:15 PM > To: 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 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. > > > ------=_Part_13117_26456531.1146628330764 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
iBATIS has special code to deal with HashMaps.  If in your mappin= g you specify #someProperty#, then iBATIS will call HashMap.get("= someProperty") - it has essentially the same effect as the DynaBean fu= nctionality.
 
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 reasonab= le assumptions from the Java types.  You can also override this in the= SQL map.  For example, if you set=20 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 spec= ify the JDBC type like this:
 
insert into sometable (timestamp_column) values (#timestampProperty:TI= MESTAMP#)
 
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 call= ing getObject() - so the JDBC driver will decide what the returned data typ= e is.
 
Jeff Butler

 
On 5/2/06, B= rent Ryan <bryan@blackboard.= com> wrote:
Hmmm... Guess I missed that one = in the documentation.  I'll give it a
whirl!  Althou= gh, 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?&= nbsp; Does it work like I
think hibernate works where it goes and g= ets the meta data from the
table to figure it out?

Brent

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

actually, i think it work= ed like that.. i've been using HashMaps for
quite some time to pass para= meters, just like Jeff said:

HashMap hm =3D new HashMap();
hm.put(fieldName, value);
servi= ce.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&qu= ot; will be saved as "01/01/1981 00:00:00)

yusuf

-----Or= iginal Message-----
From: Brent Ryan [mailto: bryan@blackboard.com]
Sent: Wednesday, May 03, 2006 9:39 AM
To: <= a href=3D"mailto:user-java@ibatis.apache.org">user-java@ibatis.apache.org
Subject: RE: iBatis enhancements (Annotations and/or Dynamic beanutil= s
support)


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

<insert id=3D"insertMerc= hant" parameterClass=3D" java.util.HashMap">
   <selectKey resultClass=3D&qu= ot;int" keyProperty=3D"merchantId" > select
EXTENDED_M= ERCHANT_SEQ.NEXTVAL as merchantId from DUAL</selectKey>
 &nbs= p; insert into EXTENDED_MERCHANTS (MERCHANT_ID, NAME, CONTACT, EMAIL,
PHONE, COMMENTS, VENDOR_ID, VENDOR_SITE_ID, INVOICE_EMAIL,
EXTERNAL_= MERCHANT)
   values (#merchantId#, #merchantName#, #merchantCo= ntact#,
#merchantEmail#, #merchantPhone#, #merchantComments#, #vendorId#= ,
#vendorSiteId#, #invoiceEmail#, #externalMerchant#)
</insert>

Will iBatis assume that the key of the hash matc= hes 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 th= e columns?  I don't
think it works like this... Does it?

And to answer your other qu= estions....yes, I basically parse the text
file and cast the value to ei= ther BigDecimal or Date depending on
another configuration in a properti= es file.

Brent

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


You didn't say how you were getting "value&= quot; (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 =3D new HashMap();
= hm.put(fieldName, value);
service.insert(hm);

Am I missing someth= ing that's really fundamental?

Jeff Butler


On 5/2/06, Bre= nt Ryan < bryan@blackboard.com> wrote:=

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

       Example text file:
  =      brent, abc@so= mething.com, 5555555555

       //T= his would normally be loaded from a properties file
   &n= bsp;   String fieldName =3D "name";

       DynaBean obj =3D new LazyDynaB= ean();

       PropertyUtils.set(obj, f= ieldName, value);

       //insert my d= ata using iBatis
       service.insert(obj= );

       Now, how can I do that with = a hashmap?


       Brent


 &nb= sp;     From: Jeff Butler [mailto:jeffgbutler@gmail.com ]

   &n= bsp;   Sent: Tuesday, May 02, 2006 7:10 PM

  &nb= sp;    To: user-java@ibatis.apache.org
       Sub= ject: Re: iBatis enhancements (Annotations and/or Dynamic
beanutils supp= ort)




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=20 1.3!  I think it will be a
while before can sefely add any Jav= a 5 specific features.

Jeff Butler


On 5/2/06, Brent Ryan = <bryan@blackboard.com > w= rote:

       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 pu= tting 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=3D"merchant"
type=3D"org.apach= e.commons.beanutils.LazyDynaBean"/>

    =    <insert id=3D"insertMerchant" parameterClass=3D&q= uot;merchant">
           <select= Key resultClass=3D"int" keyProperty=3D"merchantId" >=
select EXTENDED_MERCHANT_SEQ.NEXTVAL as merchantId from DUAL</select= Key>

          = insert into EXTENDED_MERCHANTS (MERCHANT_ID, NAME, CONTACT,
EMAIL, PHONE, COMMENTS, VENDOR_ID, VENDOR_SITE_ID, INVOICE_EMAIL,
EX= TERNAL_MERCHANT)
         &= nbsp; values (#merchantId#, #merchantName#, #merchantContact#,
#merchant= Email#, #merchantPhone#, #merchantComments#, #vendorId#,
#vendorSiteId#, #invoiceEmail#, #externalMerchant#)
  &nbs= p;      </insert>

   &= nbsp;   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... &= nbsp;I wasn't really sure other then I've seen
some cool uses with the h= ibernate annotations.  Maybe replace some of
the result map configurations, default values, etc.. with annotations.
O= ther then that, I'm not sure of another use for this...

  =      Brent


     &nb= sp;  From: Jeff Butler [mailto: jeffgbutler@gmail.com ]
       Sent: T= uesday, May 02, 2006 6:15 PM
       To: 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
depen= dancies to a minimum, so I don't think we'll see direct support of
DynaBeans.  You certainly could use a HashMap as a result cla= ss in
iBATIS, and then create LazyDynaMap instances from the returnedHashMaps.  This would give you DynaBean behavior and would work = directly
with iBATIS today.  Is there something about that app= roach that doesn't
work for you?

       Regarding ann= otations - could you be more specific about what
you're looking for?
=
       Jeff Butler


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

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

         &nb= sp;     Brent




   &nbs= p;           This e-mail = is intended only for the personal and
confidential use of the recipient(s) named above.
   =             It may i= nclude Blackboard confidential and proprietary
information, and is not f= or redistribution.







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



This e-mail is intended onl= y 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.


=

------=_Part_13117_26456531.1146628330764--