You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Meindert <me...@pastelebusiness.com> on 2005/10/10 12:27:11 UTC

RE: XML document output from ibatis

I can't find info about the use of a RowHandler in the wikki.

Could anybody please post code/example for returning an org.w3c.dom.Document
using a RowHandler?

-----Original Message-----
From: Ashish Kulkarni [mailto:kulkarni_ash1312@yahoo.com] 
Sent: 13 September 2005 06:07 PM
To: user-java@ibatis.apache.org
Subject: Re: XML document output from ibatis

Parshanth
do you have a code/example of such DAO 

--- Prashanth Sukumaran <pr...@yahoo.com>
wrote:

> Hi Ashish,
>  
> Cool this is fine.  But the idea of a RowHandler is
> to have such conversions out of the DAO.  Also it
> looks clean as if IBatis is returning the Document
> object.  
>  
> The work of the DAO layer is to only execute queries
> and return the data.  You can externalize such
> transformations into the RowHandler.  
>  
> Rgds
> Prashanth Sukumaran.
> 
> Ashish Kulkarni <ku...@yahoo.com> wrote:
> Hi
> this is a way i got around my problem
> // definiation in xml file
> 
>
parameterClass="java.math.BigDecimal"xmlResultName="PO">//
> SQL querry goes herre
> // to get a list of all data from ibatis
> 
> List list = client.queryForList("getdata", new
> BigDecimal("12345"));
> // go through the list
> for (int i = 0; i < list.size(); i++)
> {
> String obj = (String) list.get(i);
> // get byte array input stream from string 
> ByteArrayInputStream byteArray = new
> ByteArrayInputStream(obj.getBytes());
> // create DMO object 
> Document doc =
> factory.newDocumentBuilder().parse(byteArray);
> }
> 
> 
> Ashish
> 
> 
> --- Larry Meadors wrote:
> 
> > Wit apologies to Clinton, my official opinion on
> > iBATIS XML results is
> > that they suck.
> > 
> > If you want to do what you are describing, do it
> in
> > your DAO class. If
> > you want multiple records, do it with a
> RowHandler.
> > 
> > Larry
> > 
> > 
> > On 9/12/05, Ashish Kulkarni
> > wrote:
> > > Hi
> > > Is it possible to get XML document from ibatis
> > > I am trying to get a XML document as a
> resultClass
> > > from ibatis, here is what i am doing
> > > > > parameterClass="java.math.BigDecimal"> >
> xmlResultName="PO" >> > SELECT A.PCPORD AS PCPORD> >
> from Pu1012> > WHERE A.Pcpord = #value#> >
> > > String str =
> > > (String)client.queryForObject("getPOData",
> poNum);
> > > 
> > > I cannot define resultClass =
> > "org.w3c.dom.Document"
> > > 
> > > Is it possible to do so
> > > 
> > > Ashish
> > > 
> > >
> __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam
> > protection around
> > > http://mail.yahoo.com
> > >
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 


A$HI$H


		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.19/92 - Release Date: 07/09/2005
 

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/126 - Release Date: 09/10/2005
 


RE: XML document output from ibatis

Posted by Meindert <me...@pastelebusiness.com>.
Thanks All,

 

To sum it up I did the following (please comment if there is a faster/better
way):

-Created a select statement that returns xml:

<select id="EmpSearch" resultClass="xml" xmlResultName="Employee">

 

-Create an inner class in the DAO class for the rowhandler to “stich” and
control the creation of the xml Document (using dom4j):

  public static class xmlRowHandler implements RowHandler{

    

    private Document domDocument;

    

    public xmlRowHandler(String xmlResultName){

      domDocument = DocumentHelper.createDocument();

      Element root = getDomDocument().addElement( xmlResultName );

    }

    

    public void handleRow(Object object){

      try{

        Document xmlFragment = DocumentHelper.parseText((String) object);

        Element xmlElement = xmlFragment.getRootElement();

        Element root = getDomDocument().getRootElement();

        root.add(xmlElement);

      }catch(DocumentException e){

      }

    }

    

    public Document getDomDocument() {

      return domDocument;

    }

  }

 

-Call the API to fetch the list “through” the rowhandler:

  public Document EmpSearch(String keywords, String filter){

    Object parameterObject = new EmployeeSearch(keywords,filter);

    RowHandler rowHandler=new xmlRowHandler("Employees");

    queryWithRowHandler("EmpSearch", parameterObject, rowHandler); // go
through the list

    Document doc = ((xmlRowHandler) rowHandler).getDomDocument();

    return doc;

  }

 

Clinton; I found page 44 just after I’ve send the mail, this was indeed good
enough to get it working but I guess a bit outdated.

I had to make to make the following assumptions

-The API methode is called queryWithRowHandler and not queryForList

-The Rowhandler interface handleRow methode has only the object as parameter
and not object and list

 

F.Y.I.  ( HYPERLINK
"http://forum.java.sun.com/thread.jspa?forumID=34&tstart=30&threadID=542044&
trange=15"http://forum.java.sun.com/thread.jspa?forumID=34&tstart=30&threadI
D=542044&trange=15 )

When running the query with XML as result on Tomcat with java 1.5.0_03 it
result in error:

javax.xml.transform.TransformerFactoryConfigurationError: Provider
org.apache.xalan.processor.TransformerFactoryImpl not found

 

This is because tomcat java is called with the following argument:
-Djava.endorsed.dirs="X:\my_app\Portal\tomcat\common\endorsed"

In this directory you find two jar files: xercesImpl.jar and xml-apis.jar
needed by tomcat and that must be loaded before all xmsl stuff present in
the jdk (1.4 naming problem). And in the file xml-apis.jar the
TransformerFactoryImpl is set to
"org.apache.xalan.processor.TransformerFactoryImpl".

The solution: remove the file xml-apis.jar from the directory.

 

 

MEINDERT HOVING



   _____  

From: Samael Cui [mailto:crazyasp@gmail.com] 
Sent: 11 October 2005 04:09 AM
To: user-java@ibatis.apache.org; Clinton Begin
Subject: Re: XML document output from ibatis

 

U can get a List by queryForList or get a String object  by
queryForObject.The list contents a String array.The String is xml format.

2005/10/10, Clinton Begin <HYPERLINK
"mailto:clinton.begin@gmail.com"clinton.begin@gmail.com>:

RowHandler is fully documented in the iBATIS for Java developer guide.  Page
44 had an explanation, and page 45 has an example.  There's no difference in
usage whether you're returning XML, a JavaBean or a primitive.

Cheers,
Clinton

 

On 10/10/05, Meindert <HYPERLINK "mailto:meindert@pastelebusiness.com" \n
meindert@pastelebusiness.com> wrote:


I can't find info about the use of a RowHandler in the wikki.

Could anybody please post code/example for returning an org.w3c.dom.Document
using a RowHandler?

-----Original Message-----
From: Ashish Kulkarni [mailto: HYPERLINK "mailto:kulkarni_ash1312@yahoo.com"
\nkulkarni_ash1312@yahoo.com]
Sent: 13 September 2005 06:07 PM
To: HYPERLINK "mailto:user-java@ibatis.apache.org"
\nuser-java@ibatis.apache.org
Subject: Re: XML document output from ibatis 

Parshanth
do you have a code/example of such DAO

--- Prashanth Sukumaran <HYPERLINK "mailto:prashanthsukumaran@yahoo.com"
\nprashanthsukumaran@yahoo.com >
wrote:

> Hi Ashish,
>
> Cool this is fine.  But the idea of a RowHandler is
> to have such conversions out of the DAO.  Also it
> looks clean as if IBatis is returning the Document
> object.
>
> The work of the DAO layer is to only execute queries 
> and return the data.  You can externalize such
> transformations into the RowHandler.
>
> Rgds
> Prashanth Sukumaran.
>
> Ashish Kulkarni <HYPERLINK "mailto:kulkarni_ash1312@yahoo.com" \n
kulkarni_ash1312@yahoo.com> wrote:
> Hi
> this is a way i got around my problem
> // definiation in xml file
>
>
parameterClass="java.math.BigDecimal"xmlResultName="PO">// 
> SQL querry goes herre
> // to get a list of all data from ibatis
>
> List list = client.queryForList("getdata", new
> BigDecimal("12345"));
> // go through the list 
> for (int i = 0; i < list.size(); i++)
> {
> String obj = (String) list.get(i);
> // get byte array input stream from string
> ByteArrayInputStream byteArray = new
> ByteArrayInputStream( obj.getBytes());
> // create DMO object
> Document doc =
> factory.newDocumentBuilder().parse(byteArray);
> }
>
>
> Ashish
>
>
> --- Larry Meadors wrote:
> 
> > Wit apologies to Clinton, my official opinion on
> > iBATIS XML results is
> > that they suck.
> >
> > If you want to do what you are describing, do it
> in
> > your DAO class. If 
> > you want multiple records, do it with a
> RowHandler.
> >
> > Larry
> >
> >
> > On 9/12/05, Ashish Kulkarni
> > wrote:
> > > Hi
> > > Is it possible to get XML document from ibatis 
> > > I am trying to get a XML document as a
> resultClass
> > > from ibatis, here is what i am doing
> > > > > parameterClass="java.math.BigDecimal"> >
> xmlResultName="PO" >> > SELECT A.PCPORD AS PCPORD> >
> from Pu1012> > WHERE A.Pcpord = #value#> >
> > > String str =
> > > (String)client.queryForObject("getPOData", 
> poNum);
> > >
> > > I cannot define resultClass =
> > "org.w3c.dom.Document"
> > >
> > > Is it possible to do so
> > >
> > > Ashish 
> > >
> > >
> __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam
> > protection around 
> > > HYPERLINK "http://mail.yahoo.com" \nhttp://mail.yahoo.com
> > >
> >
>
>
> __________________________________________________ 
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam 
> protection around
> HYPERLINK "http://mail.yahoo.com" \nhttp://mail.yahoo.com
>
> __________________________________________________ 
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam 
> protection around
> HYPERLINK "http://mail.yahoo.com" \nhttp://mail.yahoo.com


A$HI$H



__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005
HYPERLINK "http://mail.yahoo.com" \nhttp://mail.yahoo.com

--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.19/92 - Release Date: 07/09/2005


--
No virus found in this outgoing message. 
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/126 - Release Date: 09/10/2005







 

--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/126 - Release Date: 09/10/2005


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.13/126 - Release Date: 09/10/2005
 

Re: XML document output from ibatis

Posted by Samael Cui <cr...@gmail.com>.
U can get a List by queryForList or get a String object by
queryForObject.The list contents a String array.The String is xml format.

2005/10/10, Clinton Begin <cl...@gmail.com>:
>
> RowHandler is fully documented in the iBATIS for Java developer guide.
> Page 44 had an explanation, and page 45 has an example. There's no
> difference in usage whether you're returning XML, a JavaBean or a primitive.
>
> Cheers,
> Clinton
>
> On 10/10/05, Meindert <me...@pastelebusiness.com> wrote:
> >
> >
> > I can't find info about the use of a RowHandler in the wikki.
> >
> > Could anybody please post code/example for returning an
> > org.w3c.dom.Document
> > using a RowHandler?
> >
> > -----Original Message-----
> > From: Ashish Kulkarni [mailto: kulkarni_ash1312@yahoo.com]
> > Sent: 13 September 2005 06:07 PM
> > To: user-java@ibatis.apache.org
> > Subject: Re: XML document output from ibatis
> >
> > Parshanth
> > do you have a code/example of such DAO
> >
> > --- Prashanth Sukumaran <pr...@yahoo.com>
> > wrote:
> >
> > > Hi Ashish,
> > >
> > > Cool this is fine. But the idea of a RowHandler is
> > > to have such conversions out of the DAO. Also it
> > > looks clean as if IBatis is returning the Document
> > > object.
> > >
> > > The work of the DAO layer is to only execute queries
> > > and return the data. You can externalize such
> > > transformations into the RowHandler.
> > >
> > > Rgds
> > > Prashanth Sukumaran.
> > >
> > > Ashish Kulkarni < kulkarni_ash1312@yahoo.com> wrote:
> > > Hi
> > > this is a way i got around my problem
> > > // definiation in xml file
> > >
> > >
> > parameterClass="java.math.BigDecimal"xmlResultName="PO">//
> > > SQL querry goes herre
> > > // to get a list of all data from ibatis
> > >
> > > List list = client.queryForList("getdata", new
> > > BigDecimal("12345"));
> > > // go through the list
> > > for (int i = 0; i < list.size(); i++)
> > > {
> > > String obj = (String) list.get(i);
> > > // get byte array input stream from string
> > > ByteArrayInputStream byteArray = new
> > > ByteArrayInputStream( obj.getBytes());
> > > // create DMO object
> > > Document doc =
> > > factory.newDocumentBuilder().parse(byteArray);
> > > }
> > >
> > >
> > > Ashish
> > >
> > >
> > > --- Larry Meadors wrote:
> > >
> > > > Wit apologies to Clinton, my official opinion on
> > > > iBATIS XML results is
> > > > that they suck.
> > > >
> > > > If you want to do what you are describing, do it
> > > in
> > > > your DAO class. If
> > > > you want multiple records, do it with a
> > > RowHandler.
> > > >
> > > > Larry
> > > >
> > > >
> > > > On 9/12/05, Ashish Kulkarni
> > > > wrote:
> > > > > Hi
> > > > > Is it possible to get XML document from ibatis
> > > > > I am trying to get a XML document as a
> > > resultClass
> > > > > from ibatis, here is what i am doing
> > > > > > > parameterClass="java.math.BigDecimal"> >
> > > xmlResultName="PO" >> > SELECT A.PCPORD AS PCPORD> >
> > > from Pu1012> > WHERE A.Pcpord = #value#> >
> > > > > String str =
> > > > > (String)client.queryForObject("getPOData",
> > > poNum);
> > > > >
> > > > > I cannot define resultClass =
> > > > "org.w3c.dom.Document"
> > > > >
> > > > > Is it possible to do so
> > > > >
> > > > > Ashish
> > > > >
> > > > >
> > > __________________________________________________
> > > > > Do You Yahoo!?
> > > > > Tired of spam? Yahoo! Mail has the best spam
> > > > protection around
> > > > > http://mail.yahoo.com
> > > > >
> > > >
> > >
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam
> > > protection around
> > > http://mail.yahoo.com
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam
> > > protection around
> > > http://mail.yahoo.com
> >
> >
> > A$HI$H
> >
> >
> >
> > __________________________________
> > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > http://mail.yahoo.com
> >
> > --
> > No virus found in this incoming message.
> > Checked by AVG Anti-Virus.
> > Version: 7.0.344 / Virus Database: 267.10.19/92 - Release Date:
> > 07/09/2005
> >
> >
> > --
> > No virus found in this outgoing message.
> > Checked by AVG Anti-Virus.
> > Version: 7.0.344 / Virus Database: 267.11.13/126 - Release Date:
> > 09/10/2005
> >
> >
> >
>

Re: XML document output from ibatis

Posted by Clinton Begin <cl...@gmail.com>.
RowHandler is fully documented in the iBATIS for Java developer guide. Page
44 had an explanation, and page 45 has an example. There's no difference in
usage whether you're returning XML, a JavaBean or a primitive.

Cheers,
Clinton

On 10/10/05, Meindert <me...@pastelebusiness.com> wrote:
>
>
> I can't find info about the use of a RowHandler in the wikki.
>
> Could anybody please post code/example for returning an
> org.w3c.dom.Document
> using a RowHandler?
>
> -----Original Message-----
> From: Ashish Kulkarni [mailto:kulkarni_ash1312@yahoo.com]
> Sent: 13 September 2005 06:07 PM
> To: user-java@ibatis.apache.org
> Subject: Re: XML document output from ibatis
>
> Parshanth
> do you have a code/example of such DAO
>
> --- Prashanth Sukumaran <pr...@yahoo.com>
> wrote:
>
> > Hi Ashish,
> >
> > Cool this is fine. But the idea of a RowHandler is
> > to have such conversions out of the DAO. Also it
> > looks clean as if IBatis is returning the Document
> > object.
> >
> > The work of the DAO layer is to only execute queries
> > and return the data. You can externalize such
> > transformations into the RowHandler.
> >
> > Rgds
> > Prashanth Sukumaran.
> >
> > Ashish Kulkarni <ku...@yahoo.com> wrote:
> > Hi
> > this is a way i got around my problem
> > // definiation in xml file
> >
> >
> parameterClass="java.math.BigDecimal"xmlResultName="PO">//
> > SQL querry goes herre
> > // to get a list of all data from ibatis
> >
> > List list = client.queryForList("getdata", new
> > BigDecimal("12345"));
> > // go through the list
> > for (int i = 0; i < list.size(); i++)
> > {
> > String obj = (String) list.get(i);
> > // get byte array input stream from string
> > ByteArrayInputStream byteArray = new
> > ByteArrayInputStream(obj.getBytes());
> > // create DMO object
> > Document doc =
> > factory.newDocumentBuilder().parse(byteArray);
> > }
> >
> >
> > Ashish
> >
> >
> > --- Larry Meadors wrote:
> >
> > > Wit apologies to Clinton, my official opinion on
> > > iBATIS XML results is
> > > that they suck.
> > >
> > > If you want to do what you are describing, do it
> > in
> > > your DAO class. If
> > > you want multiple records, do it with a
> > RowHandler.
> > >
> > > Larry
> > >
> > >
> > > On 9/12/05, Ashish Kulkarni
> > > wrote:
> > > > Hi
> > > > Is it possible to get XML document from ibatis
> > > > I am trying to get a XML document as a
> > resultClass
> > > > from ibatis, here is what i am doing
> > > > > > parameterClass="java.math.BigDecimal"> >
> > xmlResultName="PO" >> > SELECT A.PCPORD AS PCPORD> >
> > from Pu1012> > WHERE A.Pcpord = #value#> >
> > > > String str =
> > > > (String)client.queryForObject("getPOData",
> > poNum);
> > > >
> > > > I cannot define resultClass =
> > > "org.w3c.dom.Document"
> > > >
> > > > Is it possible to do so
> > > >
> > > > Ashish
> > > >
> > > >
> > __________________________________________________
> > > > Do You Yahoo!?
> > > > Tired of spam? Yahoo! Mail has the best spam
> > > protection around
> > > > http://mail.yahoo.com
> > > >
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> > protection around
> > http://mail.yahoo.com
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> > protection around
> > http://mail.yahoo.com
>
>
> A$HI$H
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>
> --
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.10.19/92 - Release Date: 07/09/2005
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.11.13/126 - Release Date:
> 09/10/2005
>
>
>