@Override public void setBlobAsBinaryStream( PreparedStatement ps, int paramIndex, @Nullable InputStream binaryStream, int contentLength) throws SQLException { if (binaryStream != null) { Blob blob = ps.getConnection().createBlob(); try { FileCopyUtils.copy(binaryStream, blob.setBinaryStream(1)); } catch (IOException ex) { throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex); } this.temporaryBlobs.add(blob); ps.setBlob(paramIndex, blob); } else { ps.setBlob(paramIndex, (Blob) null); } if (logger.isDebugEnabled()) { logger.debug(binaryStream != null ? "Copied binary stream into temporary BLOB with length " + contentLength : "Set BLOB to null"); } }
@Override public Blob mergeBlob(Blob original, Blob target, SharedSessionContractImplementor session) { if ( original != target ) { try { // the BLOB just read during the load phase of merge final OutputStream connectedStream = target.setBinaryStream( 1L ); // the BLOB from the detached state final InputStream detachedStream = original.getBinaryStream(); StreamCopier.copy( detachedStream, connectedStream ); return target; } catch (SQLException e ) { throw session.getFactory().getSQLExceptionHelper().convert( e, "unable to merge BLOB data" ); } } else { return NEW_LOCATOR_LOB_MERGE_STRATEGY.mergeBlob( original, target, session ); } }
/** * Sets a blob parameter for the prepared statement. * * @param ps * @param i * @param o * @param cls * @throws SQLException */ private static void setBlob(PreparedStatement ps, int i, Object o, Class<?> cls) throws SQLException { final InputStream is; if (o instanceof byte[]) { is = new ByteArrayInputStream((byte[]) o); } else if (o instanceof InputStream) is = (InputStream) o; else throw new RuntimeException( "cannot insert parameter of type " + cls + " into blob column " + i); Blob c = ps.getConnection().createBlob(); OutputStream os = c.setBinaryStream(1); copy(is, os); ps.setBlob(i, c); }
/** * @see java.sql.Blob#setBinaryStream(long) */ public OutputStream setBinaryStream(long pos) throws SQLException { return this.reference.setBinaryStream(pos); }
/** * {@inheritDoc} */ @Override public OutputStream setBinaryStream(long pos) throws SQLException { return this.blob.setBinaryStream(pos); }
@Override public OutputStream call() throws SQLException { return blob.setBinaryStream(pos); } });
/** * {@inheritDoc} */ @Override public OutputStream setBinaryStream(long pos) throws SQLException { return this.blob.setBinaryStream(pos); }
/** * @see java.sql.Blob#setBinaryStream(long) */ public OutputStream setBinaryStream(long pos) throws SQLException { return this.reference.setBinaryStream(pos); }
/** * {@inheritDoc} */ @Override public OutputStream setBinaryStream(long pos) throws SQLException { return this.blob.setBinaryStream(pos); }
Session currentSession = getSessionFactory().getCurrentSession(); Blob blob = Hibernate.getLobCreator(currentSession).createBlob(new byte[0]); OutputStream setBinaryStream = blob.setBinaryStream(1); Utils.fastChannelCopy(input, setBinaryStream); setBinaryStream.close();
private static void setReplicationDataBlob ( final PreparedStatement stmt, final Event event ) throws SQLException, IOException { final Blob blob = stmt.getConnection ().createBlob (); final ObjectOutputStream oos = new ObjectOutputStream ( blob.setBinaryStream ( 1 ) ); oos.writeObject ( event ); oos.close (); stmt.setBlob ( 4, blob ); }
private Object toBLOB(IAttachmentRef attachmentRef, Connection connection) { try { Blob blob = connection.createBlob(); try (OutputStream output = blob.setBinaryStream(1); InputStream input = attachmentRef.getContentAsInputStream()) { IOUtils.copy(input, output); } return blob; } catch (Exception e) { throw new IllegalArgumentException(e); } }
public OutputStream openOutputStream(long pos) throws PersistException { try { return getInternalBlobForPersist().setBinaryStream(pos); } catch (SQLException e) { throw mRepo.toPersistException(e); } }
private void doWriteDerby(Handle h, String id, InputStream file) { doDelete(h, id); try { Blob blob = h.getConnection().createBlob(); try (OutputStream out = blob.setBinaryStream(1)) { IOUtils.copy(file, out); } h.insert("INSERT INTO icon_filestore(id, data) values (?,?)", id, blob); } catch (IOException | SQLException ex) { throw IconDataAccessException.launderThrowable(ex); } }
private void doWriteDerby(Handle h, String path, InputStream file) { doDelete(h, path); try { Blob blob = h.getConnection().createBlob(); try (OutputStream out = blob.setBinaryStream(1)) { IOUtils.copy(file, out); } h.insert("INSERT INTO filestore(path, data) values (?,?)", path, blob); } catch (IOException | SQLException ex) { throw DaoException.launderThrowable(ex); } }
private void doWriteDerby(Handle h, String path, InputStream file) { doDelete(h, path); try { Blob blob = h.getConnection().createBlob(); try (OutputStream out = blob.setBinaryStream(1)) { IOUtils.copy(file, out); } h.insert("INSERT INTO filestore(path, data) values (?,?)", path, blob); } catch (IOException | SQLException ex) { throw DaoException.launderThrowable(ex); } }
private void doWriteDerby(Handle h, String path, InputStream file) { doDelete(h, path); try { Blob blob = h.getConnection().createBlob(); try (OutputStream out = blob.setBinaryStream(1)) { IOUtils.copy(file, out); } h.insert("INSERT INTO filestore(path, data) values (?,?)", path, blob); } catch (IOException | SQLException ex) { throw ExtensionDataAccessException.launderThrowable(ex); } }
@Override public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { checkClosed(); Blob blob = connection.createBlob(); try { ByteStreams.copy(inputStream, blob.setBinaryStream(1)); } catch (IOException e) { throw new SQLException(e); } set(parameterIndex, blob, Types.BLOB); }
@Override public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { checkClosed(); Blob blob = connection.createBlob(); try { ByteStreams.copy(inputStream, blob.setBinaryStream(1)); } catch (IOException e) { throw new SQLException(e); } set(parameterIndex, blob, JDBCType.BLOB); }
@Override public void updateBlob(int columnIndex, InputStream x) throws SQLException { checkClosed(); checkUpdate(); Blob blob = statement.connection.createBlob(); try { ByteStreams.copy(x, blob.setBinaryStream(1)); } catch (IOException e) { throw new SQLException(e); } set(columnIndex, blob); }