Java Code Examples for org.hibernate.cfg.Environment#useStreamsForBinary()

The following examples show how to use org.hibernate.cfg.Environment#useStreamsForBinary() . 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: EncryptedBinaryType.java    From jasypt with Apache License 2.0 6 votes vote down vote up
public void nullSafeSet(final PreparedStatement st, final Object value, final int index,
        final SharedSessionContractImplementor session)
        throws HibernateException, SQLException {

    checkInitialization();
    
    if (value == null) {
        st.setNull(index, sqlType);
    } else {
        final byte[] encryptedValue = this.encryptor.encrypt((byte[]) value);
        if (Environment.useStreamsForBinary()) {
            st.setBinaryStream(
                    index, 
                    new ByteArrayInputStream(encryptedValue), 
                    encryptedValue.length);
        } else {
            st.setBytes(index, encryptedValue);
        }
    }
    
}
 
Example 2
Source File: EncryptedBinaryType.java    From jasypt with Apache License 2.0 6 votes vote down vote up
public void nullSafeSet(final PreparedStatement st, final Object value, final int index,
        final SessionImplementor session)
        throws HibernateException, SQLException {

    checkInitialization();
    
    if (value == null) {
        st.setNull(index, sqlType);
    } else {
        final byte[] encryptedValue = this.encryptor.encrypt((byte[]) value);
        if (Environment.useStreamsForBinary()) {
            st.setBinaryStream(
                    index, 
                    new ByteArrayInputStream(encryptedValue), 
                    encryptedValue.length);
        } else {
            st.setBytes(index, encryptedValue);
        }
    }
    
}
 
Example 3
Source File: EncryptedBinaryType.java    From jasypt with Apache License 2.0 6 votes vote down vote up
public void nullSafeSet(final PreparedStatement st, final Object value, final int index)
        throws HibernateException, SQLException {

    checkInitialization();
    
    if (value == null) {
        st.setNull(index, sqlType);
    } else {
        final byte[] encryptedValue = this.encryptor.encrypt((byte[]) value);
        if (Environment.useStreamsForBinary()) {
            st.setBinaryStream(
                    index, 
                    new ByteArrayInputStream(encryptedValue), 
                    encryptedValue.length);
        } else {
            st.setBytes(index, encryptedValue);
        }
    }
    
}
 
Example 4
Source File: EncryptedBinaryType.java    From jasypt with Apache License 2.0 6 votes vote down vote up
public void nullSafeSet(final PreparedStatement st, final Object value, final int index)
        throws HibernateException, SQLException {

    checkInitialization();
    
    if (value == null) {
        st.setNull(index, sqlType);
    } else {
        final byte[] encryptedValue = this.encryptor.encrypt((byte[]) value);
        if (Environment.useStreamsForBinary()) {
            st.setBinaryStream(
                    index, 
                    new ByteArrayInputStream(encryptedValue), 
                    encryptedValue.length);
        } else {
            st.setBytes(index, encryptedValue);
        }
    }
    
}
 
Example 5
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean useStreamForLobBinding() {
	if ( useStreamForLobBinding == null ) {
		useStreamForLobBinding = Environment.useStreamsForBinary()
				|| getJdbcServices().getJdbcEnvironment().getDialect().useInputStreamToInsertBlob();
	}
	return useStreamForLobBinding;
}
 
Example 6
Source File: AbstractBynaryType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
	byte[] internalValue = toInternalFormat( value );
	if ( Environment.useStreamsForBinary() ) {
		st.setBinaryStream( index, new ByteArrayInputStream( internalValue ), internalValue.length );
	}
	else {
		st.setBytes( index, internalValue );
	}
}
 
Example 7
Source File: AbstractBynaryType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {

		if ( Environment.useStreamsForBinary() ) {

			InputStream inputStream = rs.getBinaryStream(name);

			if (inputStream==null) return toExternalFormat( null ); // is this really necessary?

			ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
			byte[] buffer = new byte[2048];

			try {
				while (true) {
					int amountRead = inputStream.read(buffer);
					if (amountRead == -1) {
						break;
					}
					outputStream.write(buffer, 0, amountRead);
				}

				inputStream.close();
				outputStream.close();
			}
			catch (IOException ioe) {
				throw new HibernateException( "IOException occurred reading a binary value", ioe );
			}

			return toExternalFormat( outputStream.toByteArray() );

		}
		else {
			return toExternalFormat( rs.getBytes(name) );
		}
	}