Search in sources :

Example 1 with ValueBinder

use of org.hibernate.type.descriptor.ValueBinder in project hibernate-orm by hibernate.

the class AttributeConverterSqlTypeDescriptorAdapter method getBinder.

// Binding ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
@SuppressWarnings("unchecked")
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
    // Get the binder for the intermediate type representation
    final ValueBinder realBinder = delegate.getBinder(intermediateJavaTypeDescriptor);
    return new ValueBinder<X>() {

        @Override
        public void bind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            final Object convertedValue;
            try {
                convertedValue = converter.convertToDatabaseColumn(value);
            } catch (PersistenceException pe) {
                throw pe;
            } catch (RuntimeException re) {
                throw new PersistenceException("Error attempting to apply AttributeConverter", re);
            }
            log.debugf("Converted value on binding : %s -> %s", value, convertedValue);
            realBinder.bind(st, convertedValue, index, options);
        }

        @Override
        public void bind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
            final Object convertedValue;
            try {
                convertedValue = converter.convertToDatabaseColumn(value);
            } catch (PersistenceException pe) {
                throw pe;
            } catch (RuntimeException re) {
                throw new PersistenceException("Error attempting to apply AttributeConverter", re);
            }
            log.debugf("Converted value on binding : %s -> %s", value, convertedValue);
            realBinder.bind(st, convertedValue, name, options);
        }
    };
}
Also used : CallableStatement(java.sql.CallableStatement) WrapperOptions(org.hibernate.type.descriptor.WrapperOptions) PersistenceException(javax.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) ValueBinder(org.hibernate.type.descriptor.ValueBinder)

Aggregations

CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 PersistenceException (javax.persistence.PersistenceException)1 ValueBinder (org.hibernate.type.descriptor.ValueBinder)1 WrapperOptions (org.hibernate.type.descriptor.WrapperOptions)1