ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject Result mapping
Date Fri, 22 Sep 2006 18:52:02 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=652293718-22092006><FONT size=2>iBatis 2.2.0 (just compiled

from source)</FONT></SPAN></DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>Sybase ASE 
12.5</FONT></SPAN></DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>I'm storing an XML document

into a db table. I've defined the column as an IMAGE datatype. Sybase stores 
these large amounts of data on pages, external to the table. 
</FONT></SPAN></DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>From the Sybase 
documentation:</FONT></SPAN></DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=652293718-22092006>Instead of storing potentially large text

and image data in the table, Adaptive Server stores it in a special structure. A 
text pointer (<B>textptr</B>) which points to the page where the data is 
actually stored is assigned. </SPAN></DIV>
<DIV><SPAN class=652293718-22092006></SPAN>&nbsp;</DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>Retrieving the data is
a two 
step process. You must first get the pointer and the length of the data and then 
you can retrieve the data. So I'm first performing a select to retrieve the row 
of data less the IMAGE column. Then in my resultMap, on the IMAGE column, I 
define a select attribute to perform the load of the data. Everything appears to 
work correctly. I can step through the code and see everything getting fired 
correctly and the data being returned in a byte[]. My problem here is the way I 
have defined my resultMap for the retrieval of the IMAGE data. At first I 
thought that I would define the resultClass as my object that expected to 
receive the data, but that is not correct. (I get a ClassCastException because 
the returned object is not of the expected type to be assigned.) I need to 
define the resultClass as a byte[] for everything to succeed correctly, but if I 
define my resultClass as a byte[], then what is the property of the byte[] that 
will be assigned the result? I can't leave the property attribute off of the 
Result element as that makes the XML invalid, so how do I get around 
this?</FONT></SPAN></DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>Thanks for the 
help.</FONT></SPAN></DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>Below is my SQL 
Map:</FONT></SPAN></DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>&lt;code&gt;<BR>&nbsp;

&lt;typeAlias alias="DocumentStore" 
type="com.sybase.cosmos.domain.DocumentStore"/&gt;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=652293718-22092006><FONT size=2>&nbsp; &lt;resultMap

class="DocumentStore" id="DocumentStoreResult"&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="bytes" 
select="DocumentStore.loadDoc"/&gt;<BR>&nbsp; &lt;/resultMap&gt;<BR>&nbsp;

<BR>&nbsp; &lt;resultMap class="byte[]" 
id="DocumentStoreDocResult"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;result

column="document" jdbcType="LONGVARCHAR" property="bytes"/&gt;<BR>&nbsp; 
&lt;/resultMap&gt;<BR>&nbsp; <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;

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;!-- <BR>&nbsp;&nbsp;&nbsp;
Retrieves 
the document based upon the text pointer and the length of the data 
<BR>&nbsp;&nbsp;&nbsp; The record must first be retrieved to aquire these

values. <BR>&nbsp; --&gt;<BR>&nbsp; &lt;select id="loadDoc" 
parameterClass="DocumentStore" 
resultMap="DocumentStoreDocResult"&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>
<DIV><SPAN class=652293718-22092006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV align=left><FONT size=2>Chris Mathrusse</FONT></DIV>
<DIV align=left><FONT size=2><A 
href="mailto:christopher.mathrusse@sybase.com">christopher.mathrusse@sybase.com</A></FONT></DIV>
<DIV align=left><FONT size=2>(925) 236-5553</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>


Mime
View raw message