public String storeBytes(final byte[] content) throws SQLException { final String sql = "INSERT INTO BDF2_BLOB_STORE(ID_,CONTENT_) VALUES (?,?)"; final String id = this.generateId(); int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setBlobAsBytes(preparedstatement, 2, content); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功存储Byte"); } return id; }
public void storeBytes(final byte[] content,final String id) throws SQLException { final String sql = "INSERT INTO BDF2_BLOB_STORE(ID_,CONTENT_) VALUES (?,?)"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setBlobAsBytes(preparedstatement, 2, content); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功存储Byte"); } }
public void updateBytes(final String id, final byte[] content) throws SQLException { final String sql = "UPDATE BDF2_BLOB_STORE SET CONTENT_=? WHERE ID_=?"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { lobcreator .setBlobAsBytes(preparedstatement, 1, content); preparedstatement.setString(2, id); } }); if (0 == updatedRowCount) { throw new SQLException(String.format( "未能成功更新Byte[id=%s],请检查此记录是否存在", id)); } }
public String storeBinaryStream(final InputStream inputStream,final int contentLength) throws SQLException { final String sql = "INSERT INTO BDF2_BLOB_STORE (ID_,CONTENT_) VALUES (?,?)"; final String id = this.generateId(); int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setBlobAsBinaryStream(preparedstatement, 2, inputStream, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功存储二进制流"); } return id; }
public void storeBinaryStream(final InputStream inputStream,final int contentLength,final String id) throws SQLException { final String sql = "INSERT INTO BDF2_BLOB_STORE (ID_,CONTENT_) VALUES (?,?)"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setBlobAsBinaryStream(preparedstatement, 2, inputStream, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功存储二进制流"); } }
public void updateBinaryStream(final String id, final InputStream inputStream, final int contentLength) throws SQLException { final String sql = "UPDATE BDF2_BLOB_STORE SET CONTENT_=? WHERE ID_=?"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { lobcreator.setBlobAsBinaryStream(preparedstatement, 1, inputStream, contentLength); preparedstatement.setString(2, id); } }); if (0 == updatedRowCount) { throw new SQLException(String.format( "未能成功更新Byte[id=%s],请检查此记录是否存在", id)); } }
public String storeString(final String content) throws SQLException { final String sql = "INSERT INTO BDF2_CLOB_STORE (ID_,CONTENT_) VALUES(?,?)"; final String id = this.generateId(); int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setClobAsString(preparedstatement, 2, content); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功储存大字符串"); } return id; }
public void storeString(final String content,final String id) throws SQLException { final String sql = "INSERT INTO BDF2_CLOB_STORE (ID_,CONTENT_) VALUES(?,?)"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setClobAsString(preparedstatement, 2, content); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功储存大字符串"); } }
public void updateString(final String id, final String content) throws SQLException { final String sql = "UPDATE BDF2_CLOB_STORE SET CONTENT_=? WHERE ID_=?"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(2, id); lobcreator.setClobAsString(preparedstatement, 1, content); } }); if (0 == updatedRowCount) { throw new SQLException(String.format("未能成功更新大字符串[%s],请检查其是否存在", id)); } }
public String storeAsciiStream(final InputStream asciiStream, final int contentLength) throws SQLException { final String sql = "INSERT INTO BDF2_CLOB_STORE (ID_,CONTENT_) VALUES(?,?)"; final String id = this.generateId(); int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setClobAsAsciiStream(preparedstatement, 2, asciiStream, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功储存大字符串"); } return id; }
public void storeAsciiStream(final InputStream asciiStream, final int contentLength,final String id) throws SQLException { final String sql = "INSERT INTO BDF2_CLOB_STORE (ID_,CONTENT_) VALUES(?,?)"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setClobAsAsciiStream(preparedstatement, 2, asciiStream, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功储存大字符串"); } }
public void updateAsciiStream(final String id, final InputStream asciiStream, final int contentLength) throws SQLException { final String sql = "UPDATE BDF2_CLOB_STORE SET CONTENT_=? WHERE ID_=?"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(2, id); lobcreator.setClobAsAsciiStream(preparedstatement, 1, asciiStream, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException(String.format("未能成功更新大字符串[%s],请检查其是否存在", id)); } }
public String storeCharacterStream(final Reader reader, final int contentLength) throws SQLException { final String sql = "INSERT INTO BDF2_CLOB_STORE (ID_,CONTENT_) VALUES(?,?)"; final String id = this.generateId(); int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setClobAsCharacterStream(preparedstatement, 2, reader, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功储存大字符串"); } return id; }
public void storeCharacterStream(final Reader reader, final int contentLength,final String id) throws SQLException { final String sql = "INSERT INTO BDF2_CLOB_STORE (ID_,CONTENT_) VALUES(?,?)"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(1, id); lobcreator.setClobAsCharacterStream(preparedstatement, 2, reader, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException("未能成功储存大字符串"); } }
public void updateCharacterStream(final String id, final Reader reader, final int contentLength) throws SQLException { final String sql = "UPDATE BDF2_CLOB_STORE SET CONTENT_=? WHERE ID_=?"; int updatedRowCount = super.getJdbcTemplate().execute( sql, new AbstractLobCreatingPreparedStatementCallback(this .getLobHandler()) { @Override protected void setValues( PreparedStatement preparedstatement, LobCreator lobcreator) throws SQLException, DataAccessException { preparedstatement.setString(2, id); lobcreator.setClobAsCharacterStream(preparedstatement, 1, reader, contentLength); } }); if (0 == updatedRowCount) { throw new SQLException(String.format("未能成功更新大字符串[%s],请检查其是否存在", id)); } }
protected void insertAndUpdateHelper(final CamelContext camelContext, final String key, final Exchange exchange, String sql, final boolean idComesFirst) throws Exception { final byte[] data = codec.marshallExchange(camelContext, exchange, allowSerializedHeaders); jdbcTemplate.execute(sql, new AbstractLobCreatingPreparedStatementCallback(getLobHandler()) { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { int totalParameterIndex = 0; lobCreator.setBlobAsBytes(ps, ++totalParameterIndex, data); if (idComesFirst) { ps.setString(++totalParameterIndex, key); } if (storeBodyAsText) { ps.setString(++totalParameterIndex, exchange.getIn().getBody(String.class)); } if (hasHeadersToStoreAsText()) { for (String headerName : headersToStoreAsText) { String headerValue = exchange.getIn().getHeader(headerName, String.class); ps.setString(++totalParameterIndex, headerValue); } } if (!idComesFirst) { ps.setString(++totalParameterIndex, key); } } }); }
@Transactional public void storeImage( final String name, final InputStream contentStream, final int contentLength, final String description) throws DataAccessException { getJdbcTemplate().execute( "INSERT INTO imagedb (image_name, content, description) VALUES (?, ?, ?)", new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) { protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setString(1, name); lobCreator.setBlobAsBinaryStream(ps, 2, contentStream, contentLength); lobCreator.setClobAsString(ps, 3, description); } } ); }
@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 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); } }); }
public void saveProcess(final Process process) { super.saveProcess(process); if(process.getBytes() != null) { template.execute(PROCESS_UPDATE_BLOB, new AbstractLobCreatingPreparedStatementCallback(lobHandler) { protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException { try { lobCreator.setBlobAsBytes(ps, 1, process.getBytes()); StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, process.getId()); } catch (Exception e) { e.printStackTrace(); } } }); } }
public void updateProcess(final Process process) { super.updateProcess(process); if(process.getBytes() != null) { template.execute(PROCESS_UPDATE_BLOB, new AbstractLobCreatingPreparedStatementCallback(lobHandler) { protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException { try { lobCreator.setBlobAsBytes(ps, 1, process.getBytes()); StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, process.getId()); } catch (Exception e) { e.printStackTrace(); } } }); } }
public String insertFile(UploadBase64FileModification file) { String digest = DigestUtils.sha256Hex(file.getFile()); if(Integer.valueOf(1).equals(repository.isPresent(digest))) { return digest; } LobHandler lobHandler = new DefaultLobHandler(); jdbc.getJdbcOperations().execute(repository.uploadTemplate(), new AbstractLobCreatingPreparedStatementCallback(lobHandler) { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setString(1, digest); ps.setString(2, file.getName()); ps.setLong(3, file.getFile().length); lobCreator.setBlobAsBytes(ps, 4, file.getFile()); ps.setString(5, file.getType()); ps.setString(6, Json.GSON.toJson(getAttributes(file))); } }); return digest; }
public int saveResource(int organizationId, int eventId, UploadBase64FileModification file) { if (hasResource(organizationId, eventId, file.getName())) { uploadedResourceRepository.delete(organizationId, eventId, file.getName()); } LobHandler lobHandler = new DefaultLobHandler(); return jdbc.getJdbcOperations().execute(uploadedResourceRepository.uploadTemplate(organizationId, eventId, file.getName()), new AbstractLobCreatingPreparedStatementCallback(lobHandler) { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setInt(2, organizationId); ps.setInt(3, eventId); setFileValues(ps, lobCreator, file, 3); } }); }
/** * @param serviceID ID of the service for which the configuration will be * inserted * @param configurationXMLRepresentation the used MELA configuration to be * persisted in XML and reused */ public void writeConfiguration(final String serviceID, final ConfigurationXMLRepresentation configurationXMLRepresentation) { final StringWriter stringWriter = new StringWriter(); try { JAXBContext context = JAXBContext.newInstance(ConfigurationXMLRepresentation.class); context.createMarshaller().marshal(configurationXMLRepresentation, stringWriter); } catch (JAXBException e) { log.warn("Cannot marshal configuration into string: " + e); return; } String sql = "INSERT INTO Configuration (monSeqID, configuration) " + "VALUES (?, ?)"; jdbcTemplate.execute(sql, new AbstractLobCreatingPreparedStatementCallback(new DefaultLobHandler()) { protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setString(1, serviceID); lobCreator.setClobAsString(ps, 2, stringWriter.toString()); } }); }
@Override public void save(@NotNull final MultipartFile file, @NotNull final String id, int timeToLiveInSeconds, final @Nullable String context, final @Nullable String metadata) { Assert.notNull(file, "File cannot be null."); if (file.getSize() > Integer.MAX_VALUE) { throw new IllegalArgumentException(String.format("Cannot store files larger than %d bytes.", Integer.MAX_VALUE)); } Assert.hasText(id, "ID cannot be empty."); Assert.isTrue(timeToLiveInSeconds >= 0, "Time to live must be greater than or equal to 0."); Assert.isTrue(context == null || context.length() <= 255, "Context cannot be longer than 255 characters"); Assert.isTrue(metadata == null || metadata.length() <= 255, "Metadata cannot be longer than 255 characters"); final Date createdAt = new Date(); final Date expiresAt = new Date(createdAt.getTime() + timeToLiveInSeconds * 1000); logger.debug("Saving multipart file '{}'. Expires at: {} ", id, expiresAt); jdbc.execute(SqlConstants.INSERT_INTO, new AbstractLobCreatingPreparedStatementCallback(lobHandler) { @Override protected void setValues(final PreparedStatement ps, final LobCreator lobCreator) throws SQLException, DataAccessException { try { int pos = 1; ps.setString(pos++, id); ps.setString(pos++, file.getName()); ps.setString(pos++, file.getOriginalFilename()); ps.setString(pos++, file.getContentType()); ps.setInt(pos++, (int) file.getSize()); lobCreator.setBlobAsBinaryStream(ps, pos++, file.getInputStream(), (int) file.getSize()); ps.setString(pos++, context); ps.setString(pos++, metadata); ps.setLong(pos++, createdAt.getTime()); ps.setLong(pos++, expiresAt.getTime()); Assert.state(pos - 1 == SqlConstants.COLUMN_COUNT, "Unexpected column count."); } catch (final IOException e) { throw new RuntimeException(e); } } }); }
public int saveResource(UploadBase64FileModification file) { if (hasResource(file.getName())) { uploadedResourceRepository.delete(file.getName()); } LobHandler lobHandler = new DefaultLobHandler(); return jdbc.getJdbcOperations().execute(uploadedResourceRepository.uploadTemplate(file.getName()), new AbstractLobCreatingPreparedStatementCallback(lobHandler) { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { setFileValues(ps, lobCreator, file, 1); } }); }
public int saveResource(int organizationId, UploadBase64FileModification file) { if (hasResource(organizationId, file.getName())) { uploadedResourceRepository.delete(organizationId, file.getName()); } LobHandler lobHandler = new DefaultLobHandler(); return jdbc.getJdbcOperations().execute(uploadedResourceRepository.uploadTemplate(organizationId, file.getName()), new AbstractLobCreatingPreparedStatementCallback(lobHandler) { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setInt(2, organizationId); setFileValues(ps, lobCreator, file, 2); } }); }