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

The following examples show how to use org.springframework.jdbc.support.lob.LobHandler. 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: DataLink   Source File: AbstractDbDialect.java    License: Apache License 2.0 6 votes vote down vote up
public AbstractDbDialect(final JdbcTemplate jdbcTemplate, LobHandler lobHandler) {
    this.jdbcTemplate = jdbcTemplate;
    this.lobHandler = lobHandler;
    // 初始化transction
    this.transactionTemplate = new TransactionTemplate();
    transactionTemplate.setTransactionManager(new DataSourceTransactionManager(jdbcTemplate.getDataSource()));
    transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    // 初始化一些数据
    jdbcTemplate.execute(new ConnectionCallback() {

        public Object doInConnection(Connection c) throws SQLException, DataAccessException {
            DatabaseMetaData meta = c.getMetaData();
            databaseName = meta.getDatabaseProductName();
            databaseMajorVersion = meta.getDatabaseMajorVersion();
            databaseMinorVersion = meta.getDatabaseMinorVersion();

            return null;
        }
    });

    initTables(jdbcTemplate);
}
 
Example 2
Source Project: lams   Source File: BlobSerializableType.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException, IOException, HibernateException {

	InputStream is = lobHandler.getBlobAsBinaryStream(rs, names[0]);
	if (is != null) {
		ObjectInputStream ois = new ObjectInputStream(is);
		try {
			return ois.readObject();
		}
		catch (ClassNotFoundException ex) {
			throw new HibernateException("Could not deserialize BLOB contents", ex);
		}
		finally {
			ois.close();
		}
	}
	else {
		return null;
	}
}
 
Example 3
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException, IOException, HibernateException {

	InputStream is = lobHandler.getBlobAsBinaryStream(rs, names[0]);
	if (is != null) {
		ObjectInputStream ois = new ObjectInputStream(is);
		try {
			return ois.readObject();
		}
		catch (ClassNotFoundException ex) {
			throw new HibernateException("Could not deserialize BLOB contents", ex);
		}
		finally {
			ois.close();
		}
	}
	else {
		return null;
	}
}
 
Example 4
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 5
Source Project: spring-analysis-note   Source File: SqlLobValueTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	preparedStatement = mock(PreparedStatement.class);
	handler = mock(LobHandler.class);
	creator = mock(LobCreator.class);
	given(handler.getLobCreator()).willReturn(creator);
}
 
Example 6
Source Project: java-technology-stack   Source File: SqlLobValueTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	preparedStatement = mock(PreparedStatement.class);
	handler = mock(LobHandler.class);
	creator = mock(LobCreator.class);
	given(handler.getLobCreator()).willReturn(creator);
}
 
Example 7
protected Object getResultInternal(ResultSet rs, int index, LobHandler lobHandler)
		throws SQLException {

	StringBuffer read_data = new StringBuffer("");
    int read_length;

	char [] buf = new char[1024];

	Reader rd =  lobHandler.getClobAsCharacterStream(rs, index);
    try {
		while( (read_length=rd.read(buf))  != -1) {
			read_data.append(buf, 0, read_length);
		}
    } catch (IOException ie) {
    	SQLException sqle = new SQLException(ie.getMessage());
    	throw sqle;
   	// 2011.10.10 보안점검 후속조치
    } finally {
	    if (rd != null) {
		try {
		    rd.close();
		} catch (Exception ignore) {
			LOGGER.debug("IGNORE: {}", ignore.getMessage());
		}
	    }
	}

    return read_data.toString();

	//return lobHandler.getClobAsString(rs, index);
}
 
Example 8
Source Project: DataLink   Source File: AbstractDbDialect.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractDbDialect(JdbcTemplate jdbcTemplate, LobHandler lobHandler, String name, int majorVersion,
                         int minorVersion) {
    this.jdbcTemplate = jdbcTemplate;
    this.lobHandler = lobHandler;
    // 初始化transction
    this.transactionTemplate = new TransactionTemplate();
    transactionTemplate.setTransactionManager(new DataSourceTransactionManager(jdbcTemplate.getDataSource()));
    transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    this.databaseName = name;
    this.databaseMajorVersion = majorVersion;
    this.databaseMinorVersion = minorVersion;

    initTables(jdbcTemplate);
}
 
Example 9
Source Project: lams   Source File: BlobByteArrayType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException {

	return lobHandler.getBlobAsBytes(rs, names[0]);
}
 
Example 10
Source Project: lams   Source File: ClobStringType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException {

	return lobHandler.getClobAsString(rs, names[0]);
}
 
Example 11
Source Project: lams   Source File: BlobStringType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException, UnsupportedEncodingException {

	byte[] bytes = lobHandler.getBlobAsBytes(rs, names[0]);
	if (bytes != null) {
		String encoding = getCharacterEncoding();
		return (encoding != null ? new String(bytes, encoding) : new String(bytes));
	}
	else {
		return null;
	}
}
 
Example 12
Source Project: spring4-understanding   Source File: BlobByteArrayType.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException {

	return lobHandler.getBlobAsBytes(rs, names[0]);
}
 
Example 13
Source Project: spring4-understanding   Source File: ClobStringType.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException {

	return lobHandler.getClobAsString(rs, names[0]);
}
 
Example 14
Source Project: spring4-understanding   Source File: BlobStringType.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Object nullSafeGetInternal(
		ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
		throws SQLException, UnsupportedEncodingException {

	byte[] bytes = lobHandler.getBlobAsBytes(rs, names[0]);
	if (bytes != null) {
		String encoding = getCharacterEncoding();
		return (encoding != null ? new String(bytes, encoding) : new String(bytes));
	}
	else {
		return null;
	}
}
 
Example 15
Source Project: spring4-understanding   Source File: SqlLobValueTests.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	preparedStatement = mock(PreparedStatement.class);
	handler = mock(LobHandler.class);
	creator = mock(LobCreator.class);
	given(handler.getLobCreator()).willReturn(creator);
}
 
Example 16
@Test
void customLobHandlerConfiguration() {
	registerAndRefresh(DataSourceConfiguration.class, CustomLobHandlerConfiguration.class);

	JdbcIndexedSessionRepository repository = this.context.getBean(JdbcIndexedSessionRepository.class);
	LobHandler lobHandler = this.context.getBean(LobHandler.class);
	assertThat(repository).isNotNull();
	assertThat(lobHandler).isNotNull();
	assertThat(ReflectionTestUtils.getField(repository, "lobHandler")).isEqualTo(lobHandler);
}
 
Example 17
Source Project: effectivejava   Source File: SqlLobValueTests.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	preparedStatement = mock(PreparedStatement.class);
	handler = mock(LobHandler.class);
	creator = mock(LobCreator.class);
	given(handler.getLobCreator()).willReturn(creator);
}
 
Example 18
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 19
Source Project: spring-analysis-note   Source File: SqlLobValue.java    License: MIT License 4 votes vote down vote up
/**
 * Create a new BLOB value with the given byte array.
 * @param bytes the byte array containing the BLOB value
 * @param lobHandler the LobHandler to be used
 */
public SqlLobValue(@Nullable byte[] bytes, LobHandler lobHandler) {
	this.content = bytes;
	this.length = (bytes != null ? bytes.length : 0);
	this.lobCreator = lobHandler.getLobCreator();
}
 
Example 20
Source Project: spring-analysis-note   Source File: SqlLobValue.java    License: MIT License 4 votes vote down vote up
/**
 * Create a new CLOB value with the given content string.
 * @param content the String containing the CLOB value
 * @param lobHandler the LobHandler to be used
 */
public SqlLobValue(@Nullable String content, LobHandler lobHandler) {
	this.content = content;
	this.length = (content != null ? content.length() : 0);
	this.lobCreator = lobHandler.getLobCreator();
}
 
Example 21
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 22
Source Project: java-technology-stack   Source File: SqlLobValue.java    License: MIT License 4 votes vote down vote up
/**
 * Create a new BLOB value with the given byte array.
 * @param bytes the byte array containing the BLOB value
 * @param lobHandler the LobHandler to be used
 */
public SqlLobValue(@Nullable byte[] bytes, LobHandler lobHandler) {
	this.content = bytes;
	this.length = (bytes != null ? bytes.length : 0);
	this.lobCreator = lobHandler.getLobCreator();
}
 
Example 23
Source Project: java-technology-stack   Source File: SqlLobValue.java    License: MIT License 4 votes vote down vote up
/**
 * Create a new CLOB value with the given content string.
 * @param content the String containing the CLOB value
 * @param lobHandler the LobHandler to be used
 */
public SqlLobValue(@Nullable String content, LobHandler lobHandler) {
	this.content = content;
	this.length = (content != null ? content.length() : 0);
	this.lobCreator = lobHandler.getLobCreator();
}
 
Example 24
/**
 * Constructor used for testing: takes an explicit LobHandler.
 */
protected AltibaseClobStringTypeHandler(LobHandler lobHandler) {
	super(lobHandler);
}
 
Example 25
Source Project: DataLink   Source File: AbstractDbDialect.java    License: Apache License 2.0 4 votes vote down vote up
public LobHandler getLobHandler() {
    return lobHandler;
}
 
Example 26
Source Project: DataLink   Source File: OracleDialect.java    License: Apache License 2.0 4 votes vote down vote up
public OracleDialect(JdbcTemplate jdbcTemplate, LobHandler lobHandler){
    super(jdbcTemplate, lobHandler);
    sqlTemplate = new OracleSqlTemplate(this);
}
 
Example 27
Source Project: DataLink   Source File: OracleDialect.java    License: Apache License 2.0 4 votes vote down vote up
public OracleDialect(JdbcTemplate jdbcTemplate, LobHandler lobHandler, String name, int majorVersion,
                     int minorVersion){
    super(jdbcTemplate, lobHandler, name, majorVersion, minorVersion);
    sqlTemplate = new OracleSqlTemplate(this);
}
 
Example 28
Source Project: DataLink   Source File: PostgreSqlDialect.java    License: Apache License 2.0 4 votes vote down vote up
public PostgreSqlDialect(JdbcTemplate jdbcTemplate, LobHandler lobHandler) {
    super(jdbcTemplate, lobHandler);
    sqlTemplate = new PostgreSqlTemplate(this);
}
 
Example 29
Source Project: DataLink   Source File: PostgreSqlDialect.java    License: Apache License 2.0 4 votes vote down vote up
public PostgreSqlDialect(JdbcTemplate jdbcTemplate, LobHandler lobHandler, String name, int majorVersion, int minorVersion) {
    super(jdbcTemplate, lobHandler, name, majorVersion, minorVersion);
    sqlTemplate = new PostgreSqlTemplate(this);
}
 
Example 30
Source Project: DataLink   Source File: SqlServerDialect.java    License: Apache License 2.0 4 votes vote down vote up
public SqlServerDialect(JdbcTemplate jdbcTemplate, LobHandler lobHandler) {
    super(jdbcTemplate, lobHandler);
    sqlTemplate = new SqlServerTemplate(this);
}