RE: Re:Blob Type

[email protected] Wed, 09 Sep 2009 09:47:41 +1000
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Yes.  It is in the nature of an ORM to need some sort of storage for the objects.  If one simply tried to store the stream reference to JDBC records then the JDBC driver could easily close the stream when the record set was closed, or worse when the record pointer moves through the set.  I have not performed experiments to verify the behavior of various drivers.

We used to allow access to the underlying JDBC RecordSet during row retrieval.  But it was rarely if ever used, and returning and ArrayList much more convenient.  Thus the byte buffer.  

I suppose we could/should have convenient methods get|setBytes(SFieldBytes, InputStream); but we haven't had demand previously.  If someone would like to provide them and a test case that would be great.  Otherwise I have added them to the TODO list, as they are very easy.  In the meantime, you will have to write a very small method yourself.  Note that the latter is easy because of the reified system -- it can be general for all fields without using reflection.

(If you had a special application that involved huge BLOBs, then you would probably be best using raw JDBC and carefully optimizing for the database.  But for just a few JPEGs then the byte array mechanism will be fine.)

Anthony


At 08:04 PM 8/09/2009, you wrote:
>  
>
>I use a byte arrays to deal with PDF and images that are defined and longblobs in mysql
>
> 
>
>public void setContent(String fieldName, byte[] val) {
>
>    this.setBytes(SFieldBytes, val);
>}
> 
>
>public byte[] getContent() {
>
>     return getBytes(SFieldBytes); 
>
>}
>
> 
>
>//To save the content to a file i use something like this
>
> 
>
>public void saveAsFile(String filePath) {
>
>try {
>
>OutputStream out = new FileOutputStream(filePath);
>
>out.write(this.getContent());
>
>out.close();
>
>return;
>
>} catch (Exception x) {
>
>throw new RuntimeException("cant save doc to file", x);
>
>}
>
>}
>
>
> 
>
> 
>
>hope this helps
>
>GA
>
> 
>
>----------
>To: [email protected]
>From: [email protected]
>Date: Tue, 8 Sep 2009 12:25:18 +0300
>Subject: [SimpleORM] Re:Blob Type
>
>  
>Hello all,
>
>I was wondering how best to work with images and/or documents that I want to save in a db based on the SFieldBlob data type. Once I have retrieved the file (eg image) from a web page, should I immiately pass it as a blob type such as "setBlob(SrecordMeta.BlobField, getUploadFile) or do I have to write some code to convert it into some kind of byte array and then pass it to the blob type? Kindly assist.
>
>Regards.
>
>Abel
>
>
>
>----------
>HotmailĀ® is up to 70% faster. Now good news travels really fast. <http://windowslive.com/online/hotmail?ocid=PID23391::T:WLMTAGL:ON:WL:en-US:WM_HYGN_faster:082009>Try it now. 
>


Spreadsheet Detective,
Southern Cross Software Queensland Pty Limited
54 Gerler Street
Bardon, Queensland 4065, Australia.

Email: [email protected]
www.SpreadsheetDetective.com
Ph: +61 427 830248 (Australian Eastern Standard Time)

"If the model seems correct only because the numbers look right, 
then why build the model in the first place?"


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
909fe98.jpg (image/jpeg, 3.3 KB) - not displayed