/
JsonBinaryJdbcTypeDescriptor.java
34 lines (28 loc) · 1.25 KB
/
JsonBinaryJdbcTypeDescriptor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>(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());
}
};
}
}