Java Code Examples for org.springframework.jdbc.support.lob.DefaultLobHandler

The following examples show how to use org.springframework.jdbc.support.lob.DefaultLobHandler. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: alf.io   Source File: FileUploadRepository.java    License: GNU General Public License v3.0 6 votes vote down vote up
default void upload(UploadBase64FileModification file, String digest, Map<String, String> attributes) {
    LobHandler lobHandler = new DefaultLobHandler();

    NamedParameterJdbcTemplate jdbc = getNamedParameterJdbcTemplate();

    jdbc.getJdbcOperations().execute("insert into file_blob (id, name, content_size, content, content_type, attributes) values(?, ?, ?, ?, ?, ?)",
        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(attributes));
            }
        });
}
 
Example 2
@Override
protected void updateAppRegistration(JdbcTemplate jdbcTemplate, List<AppRegistrationMigrationData> data) {
	DefaultLobHandler lobHandler = new DefaultLobHandler();
	lobHandler.setWrapAsLob(true);
	for (AppRegistrationMigrationData d : data) {
		Long nextVal = jdbcTemplate.queryForObject("select nextval('hibernate_sequence')", Long.class);
		jdbcTemplate.update(
				"insert into app_registration (id, object_version, default_version, metadata_uri, name, type, uri, version) values (?,?,?,?,?,?,?,?)",
				new Object[] { nextVal, 0, d.isDefaultVersion(), new SqlLobValue(d.getMetadataUri(), lobHandler),
						d.getName(), d.getType(), new SqlLobValue(d.getUri(), lobHandler), d.getVersion() },
				new int[] { Types.BIGINT, Types.BIGINT, Types.BOOLEAN, Types.CLOB, Types.VARCHAR, Types.INTEGER,
						Types.CLOB, Types.VARCHAR });
	}
}
 
Example 3
default int upload(Integer organizationId, Integer eventId, UploadBase64FileModification file, Map<String, String> attributes) {

        LobHandler lobHandler = new DefaultLobHandler();

        String query = "insert into resource_global (name, content_size, content, content_type, attributes) values(?, ?, ?, ?, ?)";
        if (organizationId != null && eventId != null) {
            query = "insert into resource_event (name, content_size, content, content_type, attributes, organization_id_fk, event_id_fk) values(?, ?, ?, ?, ?, ?, ?)";
        } else if(organizationId != null) {
            query = "insert into resource_organizer (name, content_size, content, content_type, attributes, organization_id_fk) values(?, ?, ?, ?, ?, ?)";
        }

        return getNamedParameterJdbcTemplate().getJdbcOperations().execute(query,
            new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
                @Override
                protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setString(1, file.getName());
                    ps.setLong(2, file.getFile().length);
                    lobCreator.setBlobAsBytes(ps, 3, file.getFile());
                    ps.setString(4, file.getType());
                    ps.setString(5, Json.GSON.toJson(attributes));
                    if (organizationId != null) {
                        ps.setInt(6, organizationId);
                    }
                    if (eventId != null) {
                        ps.setInt(7, eventId);
                    }
                }
            }
        );
    }
 
Example 4
Source Project: spring-boot   Source File: StartApplication.java    License: MIT License 4 votes vote down vote up
@Bean
public LobHandler lobHandler() {
    return new DefaultLobHandler();
}
 
Example 5
Source Project: r2dbc-spi   Source File: TestKit.java    License: Apache License 2.0 4 votes vote down vote up
@Test
default void clobSelect() {
    getJdbcOperations().execute("INSERT INTO clob_test VALUES (?)", new AbstractLobCreatingPreparedStatementCallback(new DefaultLobHandler()) {

        @Override
        protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
            lobCreator.setClobAsString(ps, 1, "test-value");
        }

    });

    // CLOB defaults to String
    Mono.from(getConnectionFactory().create())
        .flatMapMany(connection -> Flux.from(connection

            .createStatement("SELECT * from clob_test")
            .execute())
            .flatMap(result -> result
                .map((row, rowMetadata) -> row.get("value")))

            .concatWith(close(connection)))
        .as(StepVerifier::create)
        .expectNext("test-value").as("value from select")
        .verifyComplete();

    // CLOB consume as Clob
    Mono.from(getConnectionFactory().create())
        .flatMapMany(connection -> Flux.from(connection

            .createStatement("SELECT * from clob_test")
            .execute())
            .flatMap(result -> result
                .map((row, rowMetadata) -> row.get("value", Clob.class)))
            .flatMap(clob -> Flux.from(clob.stream())
                .reduce(new StringBuilder(), StringBuilder::append)
                .map(StringBuilder::toString)
                .concatWith(discard(clob)))

            .concatWith(close(connection)))
        .as(StepVerifier::create)
        .expectNext("test-value").as("value from select")
        .verifyComplete();
}
 
Example 6
Source Project: spring-analysis-note   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new BLOB value with the given byte array,
 * using a DefaultLobHandler.
 * @param bytes the byte array containing the BLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(@Nullable byte[] bytes) {
	this(bytes, new DefaultLobHandler());
}
 
Example 7
Source Project: spring-analysis-note   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new CLOB value with the given content string,
 * using a DefaultLobHandler.
 * @param content the String containing the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(@Nullable String content) {
	this(content, new DefaultLobHandler());
}
 
Example 8
Source Project: spring-analysis-note   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new BLOB/CLOB value with the given stream,
 * using a DefaultLobHandler.
 * @param stream the stream containing the LOB value
 * @param length the length of the LOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(InputStream stream, int length) {
	this(stream, length, new DefaultLobHandler());
}
 
Example 9
Source Project: spring-analysis-note   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new CLOB value with the given character stream,
 * using a DefaultLobHandler.
 * @param reader the character stream containing the CLOB value
 * @param length the length of the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(Reader reader, int length) {
	this(reader, length, new DefaultLobHandler());
}
 
Example 10
Source Project: java-technology-stack   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new BLOB value with the given byte array,
 * using a DefaultLobHandler.
 * @param bytes the byte array containing the BLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(@Nullable byte[] bytes) {
	this(bytes, new DefaultLobHandler());
}
 
Example 11
Source Project: java-technology-stack   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new CLOB value with the given content string,
 * using a DefaultLobHandler.
 * @param content the String containing the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(@Nullable String content) {
	this(content, new DefaultLobHandler());
}
 
Example 12
Source Project: java-technology-stack   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new BLOB/CLOB value with the given stream,
 * using a DefaultLobHandler.
 * @param stream the stream containing the LOB value
 * @param length the length of the LOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(InputStream stream, int length) {
	this(stream, length, new DefaultLobHandler());
}
 
Example 13
Source Project: java-technology-stack   Source File: SqlLobValue.java    License: MIT License 2 votes vote down vote up
/**
 * Create a new CLOB value with the given character stream,
 * using a DefaultLobHandler.
 * @param reader the character stream containing the CLOB value
 * @param length the length of the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(Reader reader, int length) {
	this(reader, length, new DefaultLobHandler());
}
 
Example 14
Source Project: lams   Source File: SqlLobValue.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new BLOB value with the given byte array,
 * using a DefaultLobHandler.
 * @param bytes the byte array containing the BLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(byte[] bytes) {
	this(bytes, new DefaultLobHandler());
}
 
Example 15
Source Project: lams   Source File: SqlLobValue.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new CLOB value with the given content string,
 * using a DefaultLobHandler.
 * @param content the String containing the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(String content) {
	this(content, new DefaultLobHandler());
}
 
Example 16
Source Project: lams   Source File: SqlLobValue.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new BLOB/CLOB value with the given stream,
 * using a DefaultLobHandler.
 * @param stream the stream containing the LOB value
 * @param length the length of the LOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(InputStream stream, int length) {
	this(stream, length, new DefaultLobHandler());
}
 
Example 17
Source Project: lams   Source File: SqlLobValue.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new CLOB value with the given character stream,
 * using a DefaultLobHandler.
 * @param reader the character stream containing the CLOB value
 * @param length the length of the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(Reader reader, int length) {
	this(reader, length, new DefaultLobHandler());
}
 
Example 18
Source Project: spring4-understanding   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new BLOB value with the given byte array,
 * using a DefaultLobHandler.
 * @param bytes the byte array containing the BLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(byte[] bytes) {
	this(bytes, new DefaultLobHandler());
}
 
Example 19
Source Project: spring4-understanding   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new CLOB value with the given content string,
 * using a DefaultLobHandler.
 * @param content the String containing the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(String content) {
	this(content, new DefaultLobHandler());
}
 
Example 20
Source Project: spring4-understanding   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new BLOB/CLOB value with the given stream,
 * using a DefaultLobHandler.
 * @param stream the stream containing the LOB value
 * @param length the length of the LOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(InputStream stream, int length) {
	this(stream, length, new DefaultLobHandler());
}
 
Example 21
Source Project: spring4-understanding   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new CLOB value with the given character stream,
 * using a DefaultLobHandler.
 * @param reader the character stream containing the CLOB value
 * @param length the length of the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(Reader reader, int length) {
	this(reader, length, new DefaultLobHandler());
}
 
Example 22
Source Project: effectivejava   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new BLOB value with the given byte array,
 * using a DefaultLobHandler.
 * @param bytes the byte array containing the BLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(byte[] bytes) {
	this(bytes, new DefaultLobHandler());
}
 
Example 23
Source Project: effectivejava   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new CLOB value with the given content string,
 * using a DefaultLobHandler.
 * @param content the String containing the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(String content) {
	this(content, new DefaultLobHandler());
}
 
Example 24
Source Project: effectivejava   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new BLOB/CLOB value with the given stream,
 * using a DefaultLobHandler.
 * @param stream the stream containing the LOB value
 * @param length the length of the LOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(InputStream stream, int length) {
	this(stream, length, new DefaultLobHandler());
}
 
Example 25
Source Project: effectivejava   Source File: SqlLobValue.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create a new CLOB value with the given character stream,
 * using a DefaultLobHandler.
 * @param reader the character stream containing the CLOB value
 * @param length the length of the CLOB value
 * @see org.springframework.jdbc.support.lob.DefaultLobHandler
 */
public SqlLobValue(Reader reader, int length) {
	this(reader, length, new DefaultLobHandler());
}