ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject RE: Result mapping
Date Sat, 23 Sep 2006 16:13:41 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META http-equiv=Content-Type content="text/html; charset=us-ascii" inline 
Content-Disposition: format="flowed" plain; text Content-Type: 7bit 
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

size=2>I&nbsp;managed to get this working. It wasn't to difficult but I did need 
to wrap the byte[] within an object. So now my structure looks like 
<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

size=2>DocumentStore - represents the actual row of data, and contains a 
<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

size=2>Document - contains a byte[] that holds the actual 
<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

size=2>I'm rather happy about the implementation as I did not need to hold onto 
the references to the pointer and data length which was returned from the first 
query. iBatis keeps track of this for me and passes it as parameters to my 
second query when I need to fetch the data, which of course only transpires when 
the Document object is requested. Below is the SQL Map that did the trick. 
<BR><BR>Thanks for the help...</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

size=2>&lt;code&gt;<BR>&lt;sqlMap namespace="DocumentStore"&gt;<BR>&nbsp;

<BR>&nbsp; &lt;typeAlias alias="DocumentStore" 
type="com.sybase.cosmos.domain.DocumentStore"/&gt;<BR>&nbsp; &lt;typeAlias

<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

size=2>&nbsp; &lt;resultMap id="DocumentStoreResult" 
class="DocumentStore"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result column="id"

jdbcType="NUMERIC" property="id"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result

column="order_no" jdbcType="VARCHAR" 
property="orderNo"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result column="order_code"

jdbcType="VARCHAR" property="orderCode"/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result

column="create_date" jdbcType="TIMESTAMP" property="createDate" 
/&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result column="mod_date" jdbcType="TIMESTAMP"

property="modifiedDate" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result column="version"

jdbcType="INTEGER" property="version" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result

column="{textPointer=text_pointer,dataLength=data_length}" property="document" 
select="DocumentStore.loadDoc"/&gt;<BR>&nbsp; &lt;/resultMap&gt;<BR>&nbsp;

<BR>&nbsp; &lt;resultMap id="DocumentResult" class="Document" 
&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result column="document" jdbcType="LONGVARCHAR"

property="bytes"/&gt;<BR>&nbsp; &lt;/resultMap&gt;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=784480516-23092006><FONT color=#0000ff

size=2>&nbsp; &lt;!-- Retrieves the record without the document based upon the

PrimaryKey --&gt;<BR>&nbsp; &lt;select id="findByPrimaryKey" 
resultMap="DocumentStoreResult"&gt;<BR>&nbsp;&nbsp;&nbsp; select 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; docStore.id<BR>&nbsp;&nbsp;&nbsp;
docStore.order_no<BR>&nbsp;&nbsp;&nbsp; , 
docStore.order_code<BR>&nbsp;&nbsp;&nbsp; , 
docStore.create_date<BR>&nbsp;&nbsp;&nbsp; , 
docStore.mod_date<BR>&nbsp;&nbsp;&nbsp; , docStore.version<BR>&nbsp;&nbsp;&nbsp;

, textptr(document) as text_pointer<BR>&nbsp;&nbsp;&nbsp; , datalength(document)

as data_length<BR>&nbsp;&nbsp;&nbsp; from<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

op_document_store docStore<BR>&nbsp;&nbsp;&nbsp; where 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; docStore.id = #id:NUMERIC#<BR>&nbsp;

&lt;/select&gt;<BR>&nbsp; <BR>&nbsp; &lt;select id="loadDoc"

resultMap="DocumentResult"&gt;<BR>&nbsp;&nbsp;&nbsp; readtext 
op_document_store.document #textPointer# 0 #dataLength#<BR>&nbsp; 
&lt;/select&gt;<BR>&lt;/code&gt; <BR></FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma><FONT size=2><B>From:</B> larry.meadors@gmail.com

[mailto:larry.meadors@gmail.com] <B>On Behalf Of </B>"Larry Meadors" 
&lt;lmeadors@apache.org&gt;<BR><B>Sent:</B> Friday, September 22,
2006 1:24 
PM<BR><B>To:</B> user-java@ibatis.apache.org<BR><B>Subject:</B>
Re: Result 
<DIV></DIV>You may have to put it into a bean or Map. I'd try that. 
<BR><BR>Larry <BR><BR><BR>On 9/22/06, Christopher.Mathrusse@sybase.com

<BR>&gt; I didn't 
even think of doing this. I'm so accustomed to providing a <BR>&gt; resultMap 
that I didn't even think to try a resultClass. <BR>&gt; <BR>&gt; I plugged
it in 
but now when I start I see the following exception: <BR>&gt; <BR>&gt;
Cause: com.ibatis.sqlmap.client.SqlMapException: Error. <BR>&gt; Could not set 
result class. Cause: <BR>&gt; java.lang.ClassNotFoundException: byte[] <BR>&gt;

<BR>&gt; ________________________________ <BR>&gt; From: "Jeff Butler"


<BR>&gt; Sent: Friday, September 22, 2006 12:16 PM <BR>&gt; To: 
user-java@ibatis.apache.org <BR>&gt; Subject: Re: Result mapping <BR>&gt;

<BR>&gt; <BR>&gt; <BR>&gt; Did you try setting resultClass="byte[]"?
I think it 
might work (no <BR>&gt; resultMap in this case). It will work the same as if you

set resultClass to <BR>&gt; some other simple type (like Integer) - I think 
iBATIS is smart enough to <BR>&gt; know that these types don't really have 
properties. <BR>&gt; <BR>&gt; So I'm thinking this: <BR>&gt;
<BR>&gt; <SELECT 
id=loadDoc resultClass="byte[]" parameterClass="DocumentStore"> &gt; readtext 
  op_document_store.document #textPointer# 0 #dataLength# &gt;</SELECT> <BR>&gt;

<BR>&gt; <BR>&gt; Then do this: <BR>&gt; <BR>&gt;
byte[] doc = (byte[]) 
queryForObject(...); <BR>&gt; <BR>&gt; It would be worth a try... <BR>&gt;

<BR>&gt; Jeff Butler <BR>&gt; <BR>&gt; <BR>&gt; On
Christopher.Mathrusse@sybase.com <BR>&gt; 
&gt; <BR>&gt; 
&gt; iBatis 2.2.0 (just compiled from source) <BR>&gt; &gt; Sybase ASE 12.5

<BR>&gt; &gt; <BR>&gt; &gt; I'm storing an XML document into a
db table. I've 
defined the column as an <BR>&gt; IMAGE datatype. Sybase stores these large 
amounts of data on pages, external <BR>&gt; to the table. <BR>&gt; &gt;
From the 
Sybase documentation: <BR>&gt; &gt; <BR>&gt; &gt; Instead of storing
large text and image data in the table, <BR>&gt; Adaptive Server stores it in a

special structure. A text pointer (textptr) <BR>&gt; which points to the page 
where the data is actually stored is assigned. <BR>&gt; &gt; <BR>&gt;
Retrieving the data is a two step process. You must first get the pointer 
<BR>&gt; and the length of the data and then you can retrieve the data. So I'm 
first <BR>&gt; performing a select to retrieve the row of data less the IMAGE 
column. Then <BR>&gt; in my resultMap, on the IMAGE column, I define a select 
attribute to perform <BR>&gt; the load of the data. Everything appears to work 
correctly. I can step <BR>&gt; through the code and see everything getting fired

correctly and the data <BR>&gt; being returned in a byte[]. My problem here is 
the way I have defined my <BR>&gt; resultMap for the retrieval of the IMAGE 
data. At first I thought that I <BR>&gt; would define the resultClass as my 
object that expected to receive the data, <BR>&gt; but that is not correct. (I 
get a ClassCastException because the returned <BR>&gt; object is not of the 
expected type to be assigned.) I need to define the <BR>&gt; resultClass as a 
byte[] for everything to succeed correctly, but if I define <BR>&gt; my 
resultClass as a byte[], then what is the property of the byte[] that <BR>&gt; 
will be assigned the result? I can't leave the property attribute off of the 
<BR>&gt; Result element as that makes the XML invalid, so how do I get around 
this? <BR>&gt; &gt; <BR>&gt; &gt; Thanks for the help. <BR>&gt;
&gt; <BR>&gt; 
&gt; Below is my SQL Map: <BR>&gt; &gt; <BR>&gt; &gt; <CODE><BR>&gt;
<TYPEALIAS <BR alias="DocumentStore">&gt; 
type="com.sybase.cosmos.domain.DocumentStore"/&gt; <BR>&gt; &gt; <BR>&gt;
<RESULTMAP class=DocumentStore id=DocumentStoreResult><BR>&gt; &gt; <RESULT

property="id" jdbcType="NUMERIC" column="id" /><BR>&gt; &gt; <RESULT 
property="orderNo" jdbcType="VARCHAR" column="order_no" /><BR>&gt; &gt; <RESULT

property="orderCode" jdbcType="VARCHAR" column="order_code" /><BR>&gt; &gt;

<RESULT <BR jdbcType="TIMESTAMP" column="create_date">&gt; property="createDate"

/&gt; <BR>&gt; &gt; <RESULT <BR property="modifiedDate" jdbcType="TIMESTAMP"

column="mod_date">&gt; /&gt; <BR>&gt; &gt; <RESULT property="version"

jdbcType="INTEGER" column="version" /><BR>&gt; &gt; <RESULT <BR>&gt;

column="{textPointer=text_pointer,dataLength=data_length}" <BR>&gt; 
property="bytes" select="DocumentStore.loadDoc"/&gt; <BR>&gt; &gt; 
</RESULTMAP><BR>&gt; &gt; <BR>&gt; &gt; <RESULTMAP class=byte[]

id=DocumentStoreDocResult><BR>&gt; &gt; <RESULT property="bytes" 
jdbcType="LONGVARCHAR" column="document" /><BR>&gt; &gt; </RESULTMAP><BR>&gt;

&gt; <BR>&gt; &gt; <SELECT id=findByPrimaryKey <BR>&gt; 
  resultMap="DocumentStoreResult"&gt; &gt; &gt; select &gt; &gt; docStore.id

  &gt; &gt; , docStore.order_no &gt; &gt; , docStore.order_code &gt; &gt;
  docStore.create_date &gt; &gt; , docStore.mod_date &gt; &gt; , 
  docStore.version &gt; &gt; , textptr(document) as text_pointer &gt; &gt;
  datalength(document) as data_length &gt; &gt; from &gt; &gt; document_store

  docStore &gt; &gt; where &gt; &gt; docStore.id = #id:NUMERIC# &gt; &gt;</SELECT>

<BR>&gt; &gt; <BR>&gt; &gt; <!--
<BR>> >     Retrieves the document based upon the text pointer and the length
<BR>> the data
<BR>> >     The record must first be retrieved to aquire these values.
<BR>> >   --><BR>&gt; &gt; <SELECT id=loadDoc parameterClass="DocumentStore"

<BR>&gt; resultMap="DocumentStoreDocResult"&gt; &gt; &gt; readtext 
  op_document_store.document #textPointer# 0 #dataLength# &gt; &gt;</SELECT>

<BR>&gt; &gt; </CODE><BR>&gt; &gt; <BR>&gt; &gt;
<BR>&gt; &gt; <BR>&gt; &gt; 
Chris Mathrusse <BR>&gt; &gt; christopher.mathrusse@sybase.com <BR>&gt;
(925) 236-5553 <BR>&gt; &gt; <BR>&gt; <BR>&gt; <BR><BR></BODY></HTML>

View raw message