[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-user
Subject:    Re: [DBUTILS] BeanHandler plus Blob
From:       "Manuel" <manuel () ilch ! de>
Date:       2010-10-16 5:51:26
Message-ID: 23b33d1318abbdc291c2195bc6a94026-EhVcX15CQAFXRwQRBhANVDBXdh9XVlpBXkJHHFxYNkhcS18KQVdoBVc6XF1XRkcCV1hRRg==-webmailer1 () server02 ! webmailer ! hosteurope ! de
[Download RAW message or body]

Hi,

just if some else have similar problem... found the solution myself.

Overwrite BeanProcessor

public class MyBeanProcessor extends BeanProcessor {
  @Override
  rotected Object processColumn(ResultSet rs, int index, Class<?>
propType) throws SQLException {
    if (propType.equals(ImageIcon.class)) {
      return getImageIcon(rs.getBlob(index));
    }

    return super.processColumn(rs, index, propType);
  }
}

Create ResultSetHandler like that:

ResultSetHandler<Person> h = new BeanHandler<Person>(Person.class, new
BasicRowProcessor(new MyBeanProcessor()));

That would do the job, now you can map a blob to an ImageIcon.
You can implement other special type the same way!

Greetings Manuel


Am Fr, 15.10.2010, 09:06 schrieb Manuel:
> Hi,
>
> have a class
>
> public class Person {
>   private Blob image;
>   public void setImage(Blob image) { this.image = image; }
>   public Blob getImage() { return image; }
> }
>
> Now I want to load the Person-class with BeanHandler-class
> ResultSetHandler<Person> h = new BeanHandler<Person>(Person.class);
> Person person = runner.query("select image from ...", h);
>
> Works so far :-) Now what not works:
>
> person.getImage();
> ObjectInputStream ois = null;
> ois = new ObjectInputStream(blob.getBinaryStream());
> ImageIcon icon = (ImageIcon) ois.readObject();
>
> -> Exception
> You cannot invoke other java.sql.Clob/java.sql.Blob methods after calling
> the free() method or after the Blob/Clob's transaction has been committed
> or rolled back.
>
> Do the query myself, or and write a own BeanHandler...
> But shouldn't there a solution to just say
> 1.) write blob data in a stream x
> 2.) write blob data to an object x
>
> OR ... go the other way, means change Person class to have an object let's
> say instead Blob and ImageIcon and tell dbutils how to map from blob to
> ImageIcon...
>
> thanks for any response in advance ;)
>
> greetings manuel
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic