All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladmihalcea.hibernate.type.json.internal.JsonBinaryJdbcTypeDescriptor Maven / Gradle / Ivy

There is a newer version: 2.21.1
Show newest version
package com.vladmihalcea.hibernate.type.json.internal;

import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.BasicBinder;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author Vlad Mihalcea
 */
public class JsonBinaryJdbcTypeDescriptor extends AbstractJsonJdbcTypeDescriptor {

    public static final JsonBinaryJdbcTypeDescriptor INSTANCE = new JsonBinaryJdbcTypeDescriptor();

    @Override
    public  ValueBinder getBinder(final JavaType javaType) {
        return new BasicBinder(javaType, this) {
            @Override
            protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
                st.setObject(index, javaType.unwrap(value, String.class, options), getJdbcTypeCode());
            }

            @Override
            protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
                    throws SQLException {
                st.setObject(name, javaType.unwrap(value, String.class, options), getJdbcTypeCode());
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy