25 Ekim 2018 Perşembe

LobCreator Arayüzü

createBlob metodu
java.sql.Blob nesnesi döner.

array
Örnek 
Şöyle yaparız.
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();

byte[] bFile = /* load image into byte array */;
Blob image = Hibernate.getLobCreator(session).createBlob(bFile);
/* ? Your actions with Blob ? */

session.getTransaction().commit();
Örnek
Şöyle yaparız.
Session currentSession = getSessionFactory().getCurrentSession();
Blob blob = Hibernate.getLobCreator(currentSession).createBlob(new byte[0]);
OutputStream setBinaryStream = blob.setBinaryStream(1);
Utils.fastChannelCopy(input, setBinaryStream);
setBinaryStream.close();
File
Örnek
Şöyle yaparız.
Session session = sessionFactory.getCurrentSession();
File file = new File(filePath);
Blob blob = Hibernate.getLobCreator(session).createBlob(
  new FileInputStream(file), file.length());
InputStream
Şöyle yaparız.
Blob blob = Hibernate.getLobCreator(currentSession)
  .createBlob(new SelfClosingInputStream(inputStream), size);

Hiç yorum yok:

Yorum Gönder