Take a look in the developers guide at dynamic SQL:

http://ibatis.apache.org/javadownloads.cgi

Larry


On 3/22/07, Andrew McDougall <[EMAIL PROTECTED]> wrote:

My question is below that I sent yesterday but didn't register first. Is
there any chance that I can get some ideas on this issue I have below?

Thanks.
Andrew


----- Forwarded Message ----
From: Andrew McDougall <[EMAIL PROTECTED]>
To: [email protected]
Sent: Wednesday, March 21, 2007 11:23:54 PM
Subject: Having an architectural issue need some ideas



To whom it may concern,

    I'm writting an application using iBatis and it has been really
excellent so far but now I'm stuck on how to get this last part to work!
Anyway here's my situation; I have a Vector of objects contained in it and I
pass that into my DAOImpl and this is where I'd normally just pass the
object into the queryForList, update,insert methods along with the name of
the sql to call in the xml properties file. But in this case I have multiple
objects that have the same fields being populated in each object and I need
to be able to take these fields and pass them into the xml properties file
where they are used in the sql statements as the values passed in. At this
point I also need to be able to build dynamic statement in the sql based on
if there are values in these fields. So potentially I could have a huge
select statement or just a very short one depending on the data passed in
those objects.

For example:
Vector vector = new Vector();
 Rule rule;

Iterator itr = rgplist.iterator();

//Have the group(s). Now need to get the set of rules for each group.

while(itr.hasNext()){

        grp = (Groups)itr.next();

        //Get the rules for each group and put it in a list

        ruleslst = getRules(grp);

        for(int i = 0; i < ruleslst.size(); i++){

                rule = (Rule)  vector.get(i);

                vector.add(rule);

         }

}



buildWhereClause(vector);



public buildWhereClause(Vector vector){

    mtf.insertWhereCluase(vector);

}



DAOImpl

Rule rule;

public void insertWhereClause(Vector vector){

    for(int i=0;i<vector.size();i++){

        rule = (Rule)vector.get(i);



        //These are the fields that I need to pass in from the object
depending on how many are in the vector.

        //these same fields can be just one or many but I don't want to
overwrite the fields on each iteration.

        rule.getCellId();

        rule.getCellRuleID();

        rule.getCellTypeID();

        rule.getCellTypeRuleGrp();

        rule.getNam();

        rule.getCd();



    }

    getSqlMapClientTemplate().insert("insertWhereClause",
????);

}





Cell.xml

resultMap (didn't include)



<insert "insertWhereClause">

     insert into tableA (a , b, c., d, e, f) values (#a#, #b#, #c#, #d#,
#e#, #f#)

</insert>





So how can I do this?


Reply via email to