ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Schrader" <teds.mailing.li...@gmail.com>
Subject Re: Using an array instead of a List
Date Sat, 03 Mar 2007 01:11:32 GMT
Hi Collin,

How about a derived getter for use by the web services?  Here's what I mean:

public class ProgramVO {

       // programID is in here somewhere.

       // List of ProgramActivityVOs
       private List activities;

       public List getActivities() {
               return activities;
       }
       public void setActivities(List activities) {
               this.activities = activities;
       }

      /**
       * Derived getter. See getActivites().
       *  Note: I did not compile this; it's just for illustration.
       *  Probably could be more efficient, too.
       */
      public ProgramActivityVO[] getActivitiesAsArray() {
           final ProgramActivityVO[] result =
                  new ProgramActivityVO[getActivites().size()];

           for(int i = 0; i < getActivites().size(); ++i) {
                result[i] = (ProgramActivityVO)getActivites().get(i);
           }

           return result;
      }
}


This way, iBATIS can give you the List, and you can give Axis the
array it needs by calling getActivitesAsArray() instead of
getActivities().

Ted



On 02/03/07, Collin Peters <cadiolis@gmail.com> wrote:
> I'm not sure if I follow.  After looking over the <iterate> tag, it
> looks like it is only for adding dynamic SQL *into* a select
> statement.  I am looking for a way to get data *out of* a select
> statement and into a Java array.
>
> Do you have any examples or links of what you mean?
>
> On 3/2/07, Poitras Christian <Christian.Poitras@ircm.qc.ca> wrote:
> > From what I know, arrays can be used with getters, by not setters.
> > For instance, the <iterate> tag should work with arrays and Lists, but
> > not resultMap.
> >
> > Christian
> >
> > -----Original Message-----
> > From: Collin Peters [mailto:cadiolis@gmail.com]
> > Sent: Friday, 02 March 2007 15:07
> > To: user-java@ibatis.apache.org
> > Subject: Using an array instead of a List
> >
> > This is the same question as this post, which never got fully
> > answered:
> > http://www.mail-archive.com/user-java@ibatis.apache.org/msg06454.html
> >
> > I have a POJO which has an array of another POJO in it (N+1 style from
> > the iBatis guide).  I have gotten this to work with a java.util.List,
> > but I need it to also work with a straight Java array.  The reason for
> > doing this is simply because I want to use the same POJO with some web
> > services.  I am using Axis2 for web services which does not support
> > (yet) using a List, you must use an old-school array of objects.
> >
> > So the question is simple.  Can iBatis support an array of POJO objects
> > instead of using a List of POJO objects?  I know using a List would be
> > better, and I wish I could, but I cannot at the moment.
> >
> > Sample POJOs:
> >
> > public class ProgramVO {
> >
> >         private Integer programID;
> >         private ProgramActivityVO[] activities;  //Using an array
> > instead of a List
> >
> >         public Integer getProgramID() {
> >                 return programID;
> >         }
> >         public void setProgramID(Integer programID) {
> >                 this.programID = programID;
> >         }
> >
> >         public ProgramActivityVO[] getActivities() {
> >                 return activities;
> >         }
> >         public void setActivities(ProgramActivityVO[] activities) {
> >                 this.activities = activities;
> >         }
> >
> > }
> >
> >
> > public class ProgramActivityVO {
> >
> >         private Integer programActivityID;
> >         private Integer activityID;
> >
> >         public Integer getProgramActivityID() {
> >                 return programActivityID;
> >         }
> >         public void setProgramActivityID(Integer programActivityID) {
> >                 this.programActivityID = programActivityID;
> >         }
> >
> >         public Integer getActivityID() {
> >                 return activityID;
> >         }
> >         public void setActivityID(Integer activityID) {
> >                 this.activityID = activityID;
> >         }
> > }
> >
> > SQL Map:
> >
> >         <resultMap id="programResult" class="Program"
> > groupBy="programID">
> >                 <result property="programID"/>
> >                 <result property="activities"
> > resultMap="program.programActivityResult"/>
> >         </resultMap>
> >
> >         <resultMap id="programActivityResult" class="ProgramActivity">
> >                 <result property="programActivityID"
> > column="programActivityID" />
> >                 <result property="activityID" column="activityID" />
> >         </resultMap>
> >
> >
> > Regards,
> > Collin Peters
> >
>

Mime
View raw message