I 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 this.
DocumentStore - represents the actual row of data, and contains a ->
Document - contains a byte[] that holds the actual data.
 
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.

Thanks for the help...
 
<code>
<sqlMap namespace="DocumentStore">
 
  <typeAlias alias="DocumentStore" type="com.sybase.cosmos.domain.DocumentStore"/>
  <typeAlias alias="Document" type="com.sybase.cosmos.domain.Document"/>
 
  <resultMap id="DocumentStoreResult" class="DocumentStore">
    <result column="id" jdbcType="NUMERIC" property="id"/>
    <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
    <result column="order_code" jdbcType="VARCHAR" property="orderCode"/>
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="mod_date" jdbcType="TIMESTAMP" property="modifiedDate" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="{textPointer=text_pointer,dataLength=data_length}" property="document" select="DocumentStore.loadDoc"/>
  </resultMap>
 
  <resultMap id="DocumentResult" class="Document" >
    <result column="document" jdbcType="LONGVARCHAR" property="bytes"/>
  </resultMap>
 
  <!-- Retrieves the record without the document based upon the PrimaryKey -->
  <select id="findByPrimaryKey" resultMap="DocumentStoreResult">
    select
      docStore.id
    , docStore.order_no
    , docStore.order_code
    , docStore.create_date
    , docStore.mod_date
    , docStore.version
    , textptr(document) as text_pointer
    , datalength(document) as data_length
    from
      op_document_store docStore
    where
      docStore.id = #id:NUMERIC#
  </select>
 
  <select id="loadDoc" resultMap="DocumentResult">
    readtext op_document_store.document #textPointer# 0 #dataLength#
  </select>
</code>


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of "Larry Meadors" <[EMAIL PROTECTED]>
Sent: Friday, September 22, 2006 1:24 PM
To: user-java@ibatis.apache.org
Subject: Re: Result mapping

You may have to put it into a bean or Map. I'd try that.

Larry


On 9/22/06, [EMAIL PROTECTED]
<[EMAIL PROTECTED]>wrote:
>
>
> I didn't even think of doing this. I'm so accustomed to providing a
> resultMap that I didn't even think to try a resultClass.
>
> I plugged it in but now when I start I see the following exception:
>
>
> Cause: com.ibatis.sqlmap.client.SqlMapException: Error.
> Could not set result class. Cause:
> java.lang.ClassNotFoundException: byte[]
>
> ________________________________
> From: "Jeff Butler" <[EMAIL PROTECTED]>[mailto:"Jeff Butler"
> <[EMAIL PROTECTED]>]
> Sent: Friday, September 22, 2006 12:16 PM
> To: user-java@ibatis.apache.org
> Subject: Re: Result mapping
>
>
>
> Did you try setting resultClass="byte[]"? I think it might work (no
> resultMap in this case). It will work the same as if you set resultClass to
> some other simple type (like Integer) - I think iBATIS is smart enough to
> know that these types don't really have properties.
>
> So I'm thinking this:
>
> > readtext op_document_store.document #textPointer# 0 #dataLength# >
>
>
> Then do this:
>
> byte[] doc = (byte[]) queryForObject(...);
>
> It would be worth a try...
>
> Jeff Butler
>
>
> On 9/22/06, [EMAIL PROTECTED]
> <[EMAIL PROTECTED]>wrote:
> >
> >
> > iBatis 2.2.0 (just compiled from source)
> > Sybase ASE 12.5
> >
> > 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.
> > From the Sybase documentation:
> >
> > Instead of storing potentially large text and image data in the table,
> Adaptive Server stores it in a special structure. A text pointer (textptr)
> which points to the page where the data is actually stored is assigned.
> >
> > 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?
> >
> > Thanks for the help.
> >
> > Below is my SQL Map:
> >
> >
> > > type="com.sybase.cosmos.domain.DocumentStore"/>
> >
> >
> >
> >
> >
> > > property="createDate" />
> > > />
> >
> > > column="{textPointer=text_pointer,dataLength=data_length}"
> property="bytes" select="DocumentStore.loadDoc"/>
> >

> >
> >
> >
> >

> >
> > > resultMap="DocumentStoreResult"> > > select > > docStore.id > > , docStore.order_no > > , docStore.order_code > > , docStore.create_date > > , docStore.mod_date > > , docStore.version > > , textptr(document) as text_pointer > > , datalength(document) as data_length > > from > > document_store docStore > > where > > docStore.id = #id:NUMERIC# > >
> >
> >
> > > resultMap="DocumentStoreDocResult"> > > readtext op_document_store.document #textPointer# 0 #dataLength# > >
> >

> >
> >
> >
> > Chris Mathrusse
> > [EMAIL PROTECTED]
> > (925) 236-5553
> >
>
>

Reply via email to