Example usage for org.springframework.jdbc.support.lob LobCreator setBlobAsBinaryStream

List of usage examples for org.springframework.jdbc.support.lob LobCreator setBlobAsBinaryStream

Introduction

In this page you can find the example usage for org.springframework.jdbc.support.lob LobCreator setBlobAsBinaryStream.

Prototype

void setBlobAsBinaryStream(PreparedStatement ps, int paramIndex, @Nullable InputStream contentStream,
        int contentLength) throws SQLException;

Source Link

Document

Set the given content as binary stream on the given statement, using the given parameter index.

Usage

From source file:org.sakaiproject.imagegallery.integration.standalone.FileLibraryStandalone.java

/**
 * @see org.sakaiproject.imagegallery.integration.FileLibraryService#storeImageFile(org.springframework.web.multipart.MultipartFile)
 *///from  ww w.  ja  v a 2  s.c o  m
@Transactional
public ImageFile storeImageFile(final MultipartFile sourceImageFile) {
    final String filename = sourceImageFile.getOriginalFilename();
    final String fileId = contextService.getCurrentContextUid() + "/" + filename;
    final String contentType = sourceImageFile.getContentType();

    ImageFile imageFile = new ImageFile();
    imageFile.setContentType(contentType);
    imageFile.setFilename(filename);
    imageFile.setFileId(fileId);
    imageFile.setDataUrl(urlPrefix + fileId);

    jdbcTemplate.getJdbcOperations().execute(
            "insert into IMAGE_GALLERY_STANDALONE_FILES_T (FILE_ID, CONTENT_TYPE, CONTENT) VALUES (?, ?, ?)",
            new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) {
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setString(1, fileId);
                    ps.setString(2, contentType);
                    try {
                        lobCreator.setBlobAsBinaryStream(ps, 3, sourceImageFile.getInputStream(),
                                (int) sourceImageFile.getSize());
                    } catch (IOException e) {
                        log.error("Error copying binary data from file " + filename, e);
                    }
                }
            });

    return imageFile;
}

From source file:io.lavagna.service.CardDataRepository.java

@Transactional(readOnly = false)
public int addUploadContent(final String digest, final long fileSize, final InputStream content,
        final String contentType) {
    LobHandler lobHandler = new DefaultLobHandler();
    return jdbc.getJdbcOperations().execute(queries.addUploadContent(),
            new AbstractLobCreatingPreparedStatementCallback(lobHandler) {

                @Override//from   ww  w  .j  a  v a  2s .c o  m
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setString(1, digest);
                    ps.setLong(2, fileSize);
                    lobCreator.setBlobAsBinaryStream(ps, 3, content, (int) fileSize);
                    ps.setString(4, contentType);
                }
            });
}

From source file:bd.gov.forms.dao.FormDaoImpl.java

public void updateForm(final Form form) {
    String sql = "UPDATE form";
    sql += " set title = ?, subtitle = ?, detail = ?, status = ?";

    if (formHasTemplate(form)) {
        sql += ", template_file = ?, template_file_name = ?";
    }/*from   w w w. j  av a  2s  . c  o  m*/

    sql += " WHERE form_id = ?";

    log.debug("SQL UPDATE query: {}", sql);

    jdbcTemplate.execute(sql, new AbstractLobCreatingPreparedStatementCallback(lobHandler) {

        @Override
        protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
            int i = 1;

            ps.setString(i++, form.getTitle());
            ps.setString(i++, form.getSubTitle());
            ps.setString(i++, form.getDetail());
            ps.setInt(i++, form.getStatus());

            if (formHasTemplate(form)) {
                lobCreator.setBlobAsBinaryStream(ps, i++, new ByteArrayInputStream(form.getPdfTemplate()),
                        form.getPdfTemplate().length);
                ps.setString(i++, form.getTemplateFileName());
            }

            ps.setString(i, form.getFormId());
        }
    });
}

From source file:bd.gov.forms.dao.FormDaoImpl.java

public void saveForm(final Form form) {
    String sql = "INSERT INTO form";
    sql += " (form_id, title, subtitle, detail, status";

    if (formHasTemplate(form)) {
        sql += ", template_file, template_file_name";
    }//w w  w .j  a  va  2s.  c om

    sql += ")";
    sql += " VALUES (?, ?, ?, ?, ?";

    if (formHasTemplate(form)) {
        sql += " , ?, ?";
    }

    sql += ")";

    log.debug("SQL INSERT query: {}" + sql);

    jdbcTemplate.execute(sql, new AbstractLobCreatingPreparedStatementCallback(lobHandler) {

        @Override
        protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
            int i = 1;

            ps.setString(i++, form.getFormId());
            ps.setString(i++, form.getTitle());
            ps.setString(i++, form.getSubTitle());
            ps.setString(i++, form.getDetail());
            ps.setInt(i++, form.getStatus());

            if (formHasTemplate(form)) {
                lobCreator.setBlobAsBinaryStream(ps, i++, new ByteArrayInputStream(form.getPdfTemplate()),
                        form.getPdfTemplate().length);
                ps.setString(i, form.getTemplateFileName());
            }
        }
    });
}

From source file:bd.gov.forms.dao.FormDaoImpl.java

public void saveEntry(final Form form) {
    String cols = "entry_date, entry_time, entry_id, entry_status, ";
    String val = "CURDATE(), CURTIME(), ?, ?, ";

    for (Field field : form.getFields()) {
        if (fieldTypeIsNotFileOrNoteOrSection(field.getType())) {
            cols += field.getColName() + ", ";
            val += "? , ";
        }/*from w w  w  .java  2s  .com*/

        if ("file".equals(field.getType())) {
            if (notEmpty(field.getByteVal())) {
                cols += field.getColName() + ", " + field.getColName() + "_fname, ";
                val += "? , ?, ";
            }
        }
    }

    cols = cols.substring(0, cols.length() - 2);
    val = val.substring(0, val.length() - 2);

    String sql = "INSERT INTO " + form.getTableName();
    sql += " (" + cols + ")";
    sql += " VALUES (" + val + ")";

    log.debug("SQL INSERT query: {}", sql);

    jdbcTemplate.execute(sql, new AbstractLobCreatingPreparedStatementCallback(lobHandler) {

        protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
            int i = 1;

            ps.setString(i++, form.getEntryId());
            ps.setString(i++, form.getEntryStatus());

            for (Field field : form.getFields()) {
                if (fieldTypeIsNotFileOrNoteOrSection(field.getType())) {
                    ps.setString(i++, field.getStrVal());
                }

                if ("file".equals(field.getType())) {
                    if (notEmpty(field.getByteVal())) {
                        lobCreator.setBlobAsBinaryStream(ps, i++, new ByteArrayInputStream(field.getByteVal()),
                                field.getByteVal().length);
                        ps.setString(i++, field.getStrVal());
                        log.debug("File Name: {}", field.getStrVal());
                    }
                }
            }
        }
    });
}

From source file:org.osaf.cosmo.hibernate.BufferedContentBlob.java

/**
 * @param statement the PreparedStatement to set on
 * @param index the statement parameter index
 * @param value the file/*from   w  w  w  .  j a  v  a  2 s. c o m*/
 * @param lobCreator the LobCreator to use
 * @throws SQLException if thrown by JDBC methods
 */
protected void nullSafeSetInternal(PreparedStatement statement, int index, Object value, LobCreator lobCreator)
        throws SQLException, HibernateException {

    BufferedContent content = (BufferedContent) value;

    if (content != null)
        lobCreator.setBlobAsBinaryStream(statement, index, content.getInputStream(), (int) content.getLength());
    else
        lobCreator.setBlobAsBinaryStream(statement, index, null, 0);
}