Ananth.Majumdar | 1 Sep 07:50 2008

Help required regarding showing pdf from blob data.

Hi,

 

          We are using Ibatis with Spring in our project. We have requirement to store pdf files in the database as blob columns and retrieve them and show them again as pdf. Currently we are doing the following.

 

 

1.       We are converting the pdf file into a byte array and saving it as a blob column

2.       While retrieving we are reading the blob column as a byte array

3.       While converting the byte array to pdf, we are facing encoding problems. A pdf file is generated and data is written into it, but when we try to open it says ‘Cannot open because it is not a supported file type or the file has been damaged’.

 

Please refer the files attached.

 

In the main method, we try to insert a row into the employee table. The ‘description’ field is a blob column in the Employee table.

 

// This is the code for retrieval

 

 

Employee emp1 = (Employee) sqlMap.queryForObject("getEmployee", "45");

                                               

                                                byte[] desc=emp1.getDesc();

                                               

                               

                                               

                                                String filename="abc.pdf";

                                                FileOutputStream fos=new FileOutputStream(filename);

                                               

                                                fos.write(desc);

                                                fos.close();

 

Please tell us, how can we convert the byte array to pdf file. Please tell us if there are any other ways to achieve this functionality.

We feel that it has something to do with the encoding formats.

 

 

 

Regards,

Ananth.

 

This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly
prohibited and may be unlawful.


Attachment (Employee.java): application/octet-stream, 1277 bytes
Attachment (Employee.xml): text/xml, 1212 bytes
Attachment (TestIbatis.java): application/octet-stream, 5447 bytes
Richard Yee | 2 Sep 01:15 2008
Picon

Re: Help required regarding showing pdf from blob data.

Ananth,
You aren't storing PDF data into your blob. You are storing a String. 
You need to store a PDF in order to retrieve a PDF.
You should use a PDF library to construct a PDF file.

The error you are getting is caused by the fact that you are writing a 
String that you retrieved from the database to a file with a .pdf 
extension. The Adobe Acrobat Reader attempts to read the file as a PDF 
but fails because the file isn't in PDF format.

-Richard

Ananth.Majumdar <at> cognizant.com wrote:
>
> Hi,
>
> We are using Ibatis with Spring in our project. We have requirement to 
> store pdf files in the database as blob columns and retrieve them and 
> show them again as pdf. Currently we are doing the following.
>
> 1. We are converting the pdf file into a byte array and saving it as a 
> blob column
>
> 2. While retrieving we are reading the blob column as a byte array
>
> 3. While converting the byte array to pdf, we are facing encoding 
> problems. A pdf file is generated and data is written into it, but 
> when we try to open it says ‘Cannot open because it is not a supported 
> file type or the file has been damaged’.
>
> Please refer the files attached.
>
> In the main method, we try to insert a row into the employee table. 
> The ‘description’ field is a blob column in the Employee table.
>
> // This is the code for retrieval
>
> Employee emp1 = (Employee) sqlMap.queryForObject("getEmployee", "45");
>
> byte[] desc=emp1.getDesc();
>
> String filename="abc.pdf";
>
> FileOutputStream fos=new FileOutputStream(filename);
>
> fos.write(desc);
>
> fos.close();
>
> Please tell us, how can we convert the byte array to pdf file. Please 
> tell us if there are any other ways to achieve this functionality.
>
> We feel that it has something to do with the encoding formats.
>

tomasz brymora | 2 Sep 03:01 2008
Picon

Re: Help required regarding showing pdf from blob data.

... I don't know if it will help, but look the iText library
http://www.lowagie.com/iText/
(but you probably knew about already)

--- On Mon, 9/1/08, Richard Yee <ryee <at> cruzio.com> wrote:

> From: Richard Yee <ryee <at> cruzio.com>
> Subject: Re: Help required regarding showing pdf from blob data.
> To: user-java <at> ibatis.apache.org
> Date: Monday, September 1, 2008, 7:15 PM
> Ananth,
> You aren't storing PDF data into your blob. You are
> storing a String. 
> You need to store a PDF in order to retrieve a PDF.
> You should use a PDF library to construct a PDF file.
> 
> The error you are getting is caused by the fact that you
> are writing a 
> String that you retrieved from the database to a file with
> a .pdf 
> extension. The Adobe Acrobat Reader attempts to read the
> file as a PDF 
> but fails because the file isn't in PDF format.
> 
> -Richard
> 
> 
> Ananth.Majumdar <at> cognizant.com wrote:
> >
> > Hi,
> >
> > We are using Ibatis with Spring in our project. We
> have requirement to 
> > store pdf files in the database as blob columns and
> retrieve them and 
> > show them again as pdf. Currently we are doing the
> following.
> >
> > 1. We are converting the pdf file into a byte array
> and saving it as a 
> > blob column
> >
> > 2. While retrieving we are reading the blob column as
> a byte array
> >
> > 3. While converting the byte array to pdf, we are
> facing encoding 
> > problems. A pdf file is generated and data is written
> into it, but 
> > when we try to open it says ‘Cannot open because it
> is not a supported 
> > file type or the file has been damaged’.
> >
> > Please refer the files attached.
> >
> > In the main method, we try to insert a row into the
> employee table. 
> > The ‘description’ field is a blob column in the
> Employee table.
> >
> > // This is the code for retrieval
> >
> > Employee emp1 = (Employee)
> sqlMap.queryForObject("getEmployee",
> "45");
> >
> > byte[] desc=emp1.getDesc();
> >
> > String filename="abc.pdf";
> >
> > FileOutputStream fos=new FileOutputStream(filename);
> >
> > fos.write(desc);
> >
> > fos.close();
> >
> > Please tell us, how can we convert the byte array to
> pdf file. Please 
> > tell us if there are any other ways to achieve this
> functionality.
> >
> > We feel that it has something to do with the encoding
> formats.
> >

J R | 2 Sep 19:32 2008
Picon

Re: TypeHandler on ParamterMap not getting invoked


Clinton this does not seem to work. Any other ideas? Any other way around to
handle this? 

Thanks!

Clinton Begin wrote:
> 
> Upgrade to 2.3.3
> 
> Cheers,
> Clinton
> 
> On Thu, Aug 28, 2008 at 5:00 PM, J R <power_of_s <at> yahoo.com> wrote:
> 
>>
>> I have a parameterClass which holds List and a Long, and I have to invoke
>> a
>> typeHandler on List to fit some custom logic. But seems like the
>> typeHandler
>> is not getting invoked.
>>
>> Intent is to have typeHandler invoked so that I can customize the items
>> in
>> the List. Is typeHandler invoked for each reference to list element? or
>> am
>> I
>> doing something wrong?
>>
>> <parameterMap id="queryCustomization"
>> class="com.jrapp.customizations.QueryObject">
>>        <parameter property="keyCount" />
>>        <parameter property="keyList"
>> typeHandler="com.jrapp.ibatis.KeyHandlerCallback" />
>> </parameterMap>
>>
>> public class QueryObject{
>>
>>        private Long keyCount = 0;
>>        private ArrayList KeyList = new ArrayList();
>>
>>       // With proper getters and setters
>> }
>>
>> Snippet of ibatis sqlmap:
>>
>> <dynamic>
>>      <isGreaterThan property="keyCount" compareValue="0">
>>      and (
>>            q.objectListKey in (
>>                     <iterate property="keyList" conjunction=",">
>>                             #keyList[]#
>>                      </iterate>
>>                     )
>> </dynamic>
>>
>> ..So I expect that on "keyList[]" reference in above sqlmap, typehandler
>> would be invoked. Is that wrong assumption? Any way to achieve this?
>>
>> Thanks!
>> --
>> View this message in context:
>> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19210666.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

--

-- 
View this message in context: http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19274746.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

Jeff Butler | 2 Sep 19:45 2008
Picon

Re: TypeHandler on ParamterMap not getting invoked

If you use a <parameterMap>, then you must use question marks as markers in your statement.  I suggest you skip the parameter map completely and specify the type handler in the statement:
 
#keyList[],handler=com.jrapp.ibatis.KeyHandlerCallback#
 
BTW - declared parameter maps will likely go away with iBATIS 3 - we don't like them AT ALL for this exact reason - they are too confusing to use.
 
Jeff Butler

On Tue, Sep 2, 2008 at 12:32 PM, J R <power_of_s <at> yahoo.com> wrote:

Clinton this does not seem to work. Any other ideas? Any other way around to
handle this?

Thanks!


Clinton Begin wrote:
>
> Upgrade to 2.3.3
>
> Cheers,
> Clinton
>
> On Thu, Aug 28, 2008 at 5:00 PM, J R <power_of_s <at> yahoo.com> wrote:
>
>>
>> I have a parameterClass which holds List and a Long, and I have to invoke
>> a
>> typeHandler on List to fit some custom logic. But seems like the
>> typeHandler
>> is not getting invoked.
>>
>> Intent is to have typeHandler invoked so that I can customize the items
>> in
>> the List. Is typeHandler invoked for each reference to list element? or
>> am
>> I
>> doing something wrong?
>>
>> <parameterMap id="queryCustomization"
>> class="com.jrapp.customizations.QueryObject">
>>        <parameter property="keyCount" />
>>        <parameter property="keyList"
>> typeHandler="com.jrapp.ibatis.KeyHandlerCallback" />
>> </parameterMap>
>>
>> public class QueryObject{
>>
>>        private Long keyCount = 0;
>>        private ArrayList KeyList = new ArrayList();
>>
>>       // With proper getters and setters
>> }
>>
>> Snippet of ibatis sqlmap:
>>
>> <dynamic>
>>      <isGreaterThan property="keyCount" compareValue="0">
>>      and (
>>            q.objectListKey in (
>>                     <iterate property="keyList" conjunction=",">
>>                             #keyList[]#
>>                      </iterate>
>>                     )
>> </dynamic>
>>
>> ..So I expect that on "keyList[]" reference in above sqlmap, typehandler
>> would be invoked. Is that wrong assumption? Any way to achieve this?
>>
>> Thanks!
>> --
>> View this message in context:
>> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19210666.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
>
>

--
View this message in context: http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19274746.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Clinton Begin | 2 Sep 20:00 2008
Picon

Re: TypeHandler on ParamterMap not getting invoked

LOL  good catch Jeff... I didn't even notice that.

FWIW:  iBATIS 3 resolves this inconsistency.  No more question marks
anywhere... :-)

Clinton

On Tue, Sep 2, 2008 at 11:45 AM, Jeff Butler <jeffgbutler <at> gmail.com> wrote:
> If you use a <parameterMap>, then you must use question marks as markers in
> your statement.  I suggest you skip the parameter map completely and specify
> the type handler in the statement:
>
> #keyList[],handler=com.jrapp.ibatis.KeyHandlerCallback#
>
> BTW - declared parameter maps will likely go away with iBATIS 3 - we don't
> like them AT ALL for this exact reason - they are too confusing to use.
>
> Jeff Butler
>
> On Tue, Sep 2, 2008 at 12:32 PM, J R <power_of_s <at> yahoo.com> wrote:
>>
>> Clinton this does not seem to work. Any other ideas? Any other way around
>> to
>> handle this?
>>
>> Thanks!
>>
>>
>> Clinton Begin wrote:
>> >
>> > Upgrade to 2.3.3
>> >
>> > Cheers,
>> > Clinton
>> >
>> > On Thu, Aug 28, 2008 at 5:00 PM, J R <power_of_s <at> yahoo.com> wrote:
>> >
>> >>
>> >> I have a parameterClass which holds List and a Long, and I have to
>> >> invoke
>> >> a
>> >> typeHandler on List to fit some custom logic. But seems like the
>> >> typeHandler
>> >> is not getting invoked.
>> >>
>> >> Intent is to have typeHandler invoked so that I can customize the items
>> >> in
>> >> the List. Is typeHandler invoked for each reference to list element? or
>> >> am
>> >> I
>> >> doing something wrong?
>> >>
>> >> <parameterMap id="queryCustomization"
>> >> class="com.jrapp.customizations.QueryObject">
>> >>        <parameter property="keyCount" />
>> >>        <parameter property="keyList"
>> >> typeHandler="com.jrapp.ibatis.KeyHandlerCallback" />
>> >> </parameterMap>
>> >>
>> >> public class QueryObject{
>> >>
>> >>        private Long keyCount = 0;
>> >>        private ArrayList KeyList = new ArrayList();
>> >>
>> >>       // With proper getters and setters
>> >> }
>> >>
>> >> Snippet of ibatis sqlmap:
>> >>
>> >> <dynamic>
>> >>      <isGreaterThan property="keyCount" compareValue="0">
>> >>      and (
>> >>            q.objectListKey in (
>> >>                     <iterate property="keyList" conjunction=",">
>> >>                             #keyList[]#
>> >>                      </iterate>
>> >>                     )
>> >> </dynamic>
>> >>
>> >> ..So I expect that on "keyList[]" reference in above sqlmap,
>> >> typehandler
>> >> would be invoked. Is that wrong assumption? Any way to achieve this?
>> >>
>> >> Thanks!
>> >> --
>> >> View this message in context:
>> >>
>> >> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19210666.html
>> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19274746.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>
>

Reuben Firmin | 2 Sep 20:26 2008

GroupBy issues (multiple child lists, Postgres limit/offset)

We are trying to resolve some N+1 query situations in our application, and are finding a couple of features of our appliation that seem to limit our ability to use the "groupBy" solution. I'm wondering if there are aspects of the issues we aren't seeing.

The problems are these:
1. In places where we have an object structure that has a parent with multiple child lists, it appears that we can't use groupBy to get all of the results with one query. For example,
class Book {
    ...
    List<Author> authors;
    List<Comment> comments;
    List<Subject> subjects;
    ...
For this type of situation, it seems like our choices are to (a) use groupBy for one of the child lists, and selects in the resultMap for the other children (doesn't completely solve N+1 problem, just reduces it), or (b) using a cross-product join of all tables and a custom RowHandler to manage it all with one query.

2. We are using Postgresql, and taking advantage of the "limit" and "offset" keywords to help implement paging of the results we display - the "limit" and "offset" values correspond to the "Results (offset) - (offset + limit) of (n)" message we can display to users. It seems that these aren't going to be compatible with a "groupBy" approach since "limit" and "offset" work at the resultSet level, and "groupBy" works by having a resultSet that's a cross product of at least a couple of tables. That is, we want to rely on the limit and offset ability at the database level (makes queries and resultset handling simpler), but the values refer to domain entities and not resultset rows. We can use the keywords if we aren't worried about N+1 selects, but the values will lose their domain entity meaning if we do cross product queries with groupBy. Is there any way that people have found around this?

Thanks for any advice,
Reuben
J R | 3 Sep 05:50 2008
Picon

Re: TypeHandler on ParamterMap not getting invoked


Thanks Jeff! Is this solution that you provided for skipping parameterMap
going to work with 2.3.3 only or would it work for earlier versions as well?

Jeff Butler-2 wrote:
> 
> If you use a <parameterMap>, then you must use question marks as markers
> in
> your statement.  I suggest you skip the parameter map completely and
> specify
> the type handler in the statement:
> 
> #keyList[],handler=com.jrapp.ibatis.KeyHandlerCallback#
> 
> BTW - declared parameter maps will likely go away with iBATIS 3 - we don't
> like them AT ALL for this exact reason - they are too confusing to use.
> 
> Jeff Butler
> 
> On Tue, Sep 2, 2008 at 12:32 PM, J R <power_of_s <at> yahoo.com> wrote:
> 
>>
>> Clinton this does not seem to work. Any other ideas? Any other way around
>> to
>> handle this?
>>
>> Thanks!
>>
>>
>> Clinton Begin wrote:
>> >
>> > Upgrade to 2.3.3
>> >
>> > Cheers,
>> > Clinton
>> >
>> > On Thu, Aug 28, 2008 at 5:00 PM, J R <power_of_s <at> yahoo.com> wrote:
>> >
>> >>
>> >> I have a parameterClass which holds List and a Long, and I have to
>> invoke
>> >> a
>> >> typeHandler on List to fit some custom logic. But seems like the
>> >> typeHandler
>> >> is not getting invoked.
>> >>
>> >> Intent is to have typeHandler invoked so that I can customize the
>> items
>> >> in
>> >> the List. Is typeHandler invoked for each reference to list element?
>> or
>> >> am
>> >> I
>> >> doing something wrong?
>> >>
>> >> <parameterMap id="queryCustomization"
>> >> class="com.jrapp.customizations.QueryObject">
>> >>        <parameter property="keyCount" />
>> >>        <parameter property="keyList"
>> >> typeHandler="com.jrapp.ibatis.KeyHandlerCallback" />
>> >> </parameterMap>
>> >>
>> >> public class QueryObject{
>> >>
>> >>        private Long keyCount = 0;
>> >>        private ArrayList KeyList = new ArrayList();
>> >>
>> >>       // With proper getters and setters
>> >> }
>> >>
>> >> Snippet of ibatis sqlmap:
>> >>
>> >> <dynamic>
>> >>      <isGreaterThan property="keyCount" compareValue="0">
>> >>      and (
>> >>            q.objectListKey in (
>> >>                     <iterate property="keyList" conjunction=",">
>> >>                             #keyList[]#
>> >>                      </iterate>
>> >>                     )
>> >> </dynamic>
>> >>
>> >> ..So I expect that on "keyList[]" reference in above sqlmap,
>> typehandler
>> >> would be invoked. Is that wrong assumption? Any way to achieve this?
>> >>
>> >> Thanks!
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19210666.html
>> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19274746.html
>>  Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

--

-- 
View this message in context: http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19282479.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

J R | 3 Sep 05:56 2008
Picon

Re: TypeHandler on ParamterMap not getting invoked


D'oh, I forgot to change those. I was using parameterClass before and just
modified to parameterMap to use the typehandler. 

Thanks again! I will after implementing Jeff's solution.

Clinton Begin wrote:
> 
> LOL  good catch Jeff... I didn't even notice that.
> 
> FWIW:  iBATIS 3 resolves this inconsistency.  No more question marks
> anywhere... :-)
> 
> Clinton
> 
> On Tue, Sep 2, 2008 at 11:45 AM, Jeff Butler <jeffgbutler <at> gmail.com>
> wrote:
>> If you use a <parameterMap>, then you must use question marks as markers
>> in
>> your statement.  I suggest you skip the parameter map completely and
>> specify
>> the type handler in the statement:
>>
>> #keyList[],handler=com.jrapp.ibatis.KeyHandlerCallback#
>>
>> BTW - declared parameter maps will likely go away with iBATIS 3 - we
>> don't
>> like them AT ALL for this exact reason - they are too confusing to use.
>>
>> Jeff Butler
>>
>> On Tue, Sep 2, 2008 at 12:32 PM, J R <power_of_s <at> yahoo.com> wrote:
>>>
>>> Clinton this does not seem to work. Any other ideas? Any other way
>>> around
>>> to
>>> handle this?
>>>
>>> Thanks!
>>>
>>>
>>> Clinton Begin wrote:
>>> >
>>> > Upgrade to 2.3.3
>>> >
>>> > Cheers,
>>> > Clinton
>>> >
>>> > On Thu, Aug 28, 2008 at 5:00 PM, J R <power_of_s <at> yahoo.com> wrote:
>>> >
>>> >>
>>> >> I have a parameterClass which holds List and a Long, and I have to
>>> >> invoke
>>> >> a
>>> >> typeHandler on List to fit some custom logic. But seems like the
>>> >> typeHandler
>>> >> is not getting invoked.
>>> >>
>>> >> Intent is to have typeHandler invoked so that I can customize the
>>> items
>>> >> in
>>> >> the List. Is typeHandler invoked for each reference to list element?
>>> or
>>> >> am
>>> >> I
>>> >> doing something wrong?
>>> >>
>>> >> <parameterMap id="queryCustomization"
>>> >> class="com.jrapp.customizations.QueryObject">
>>> >>        <parameter property="keyCount" />
>>> >>        <parameter property="keyList"
>>> >> typeHandler="com.jrapp.ibatis.KeyHandlerCallback" />
>>> >> </parameterMap>
>>> >>
>>> >> public class QueryObject{
>>> >>
>>> >>        private Long keyCount = 0;
>>> >>        private ArrayList KeyList = new ArrayList();
>>> >>
>>> >>       // With proper getters and setters
>>> >> }
>>> >>
>>> >> Snippet of ibatis sqlmap:
>>> >>
>>> >> <dynamic>
>>> >>      <isGreaterThan property="keyCount" compareValue="0">
>>> >>      and (
>>> >>            q.objectListKey in (
>>> >>                     <iterate property="keyList" conjunction=",">
>>> >>                             #keyList[]#
>>> >>                      </iterate>
>>> >>                     )
>>> >> </dynamic>
>>> >>
>>> >> ..So I expect that on "keyList[]" reference in above sqlmap,
>>> >> typehandler
>>> >> would be invoked. Is that wrong assumption? Any way to achieve this?
>>> >>
>>> >> Thanks!
>>> >> --
>>> >> View this message in context:
>>> >>
>>> >>
>>> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19210666.html
>>> >> Sent from the iBATIS - User - Java mailing list archive at
>>> Nabble.com.
>>> >>
>>> >>
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19274746.html
>>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>>
>>
>>
> 
> 

--

-- 
View this message in context: http://www.nabble.com/TypeHandler-on-ParamterMap-not-getting-invoked-tp19210666p19282535.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

PLC_David | 3 Sep 10:52 2008
Picon
Picon

selectKey twice


Hello,

i have a problem with an insert.
I need two generated ids to avoid an update after the insert.

My Question is: Is it possible to use two selectKey Tags.
Ibatis throws no exception, instead I get the correct id at the first
selectKey and 0 at the second selectKey. 

<insert id="insertCd" parameterClass="cd">
		<selectKey resultClass="int" keyProperty="id">
			SELECT COALESCE(max(ID)+1,1) from CD
		</selectKey>	
		<selectKey resultClass="int" keyProperty="db.id">
			SELECT COALESCE(max(ID)+1,1) from DB
		</selectKey>)
                INSERT INTO .... (ID, DB_ID, ....)
		VALUES (#id#, #db.id#, ...)
</insert>
--

-- 
View this message in context: http://www.nabble.com/selectKey-twice-tp19285322p19285322.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Gmane