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

The following examples show how to use org.springframework.jdbc.support.lob.DefaultLobHandler. 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 File: FileUploadRepository.java    From alf.io with 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
Source File: UploadedResourceRepository.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
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 #3
Source File: PostgresMigrateUriRegistrySqlCommand.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: StartApplication.java    From spring-boot with MIT License 4 votes vote down vote up
@Bean
public LobHandler lobHandler() {
    return new DefaultLobHandler();
}
 
Example #5
Source File: TestKit.java    From r2dbc-spi with 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 File: SqlLobValue.java    From lams with 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 #7
Source File: SqlLobValue.java    From effectivejava with 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 #8
Source File: SqlLobValue.java    From effectivejava with 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 #9
Source File: SqlLobValue.java    From effectivejava with 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 #10
Source File: SqlLobValue.java    From effectivejava with 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 #11
Source File: SqlLobValue.java    From spring4-understanding with 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 #12
Source File: SqlLobValue.java    From spring4-understanding with 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 #13
Source File: SqlLobValue.java    From spring4-understanding with 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 #14
Source File: SqlLobValue.java    From spring4-understanding with 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 #15
Source File: SqlLobValue.java    From lams with 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 #16
Source File: SqlLobValue.java    From spring-analysis-note with 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 #17
Source File: SqlLobValue.java    From lams with 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 #18
Source File: SqlLobValue.java    From lams with 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 #19
Source File: SqlLobValue.java    From java-technology-stack with 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 #20
Source File: SqlLobValue.java    From java-technology-stack with 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 #21
Source File: SqlLobValue.java    From java-technology-stack with 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 #22
Source File: SqlLobValue.java    From java-technology-stack with 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 #23
Source File: SqlLobValue.java    From spring-analysis-note with 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 #24
Source File: SqlLobValue.java    From spring-analysis-note with 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 #25
Source File: SqlLobValue.java    From spring-analysis-note with 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());
}