1 package com.vladmihalcea.hibernate.type.json.internal;
2
3 import org.hibernate.type.descriptor.ValueBinder;
4 import org.hibernate.type.descriptor.WrapperOptions;
5 import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
6 import org.hibernate.type.descriptor.sql.BasicBinder;
7
8 import java.sql.CallableStatement;
9 import java.sql.PreparedStatement;
10 import java.sql.SQLException;
11
12
15 public class JsonBinarySqlTypeDescriptor extends AbstractJsonSqlTypeDescriptor {
16
17 public static final JsonBinarySqlTypeDescriptor INSTANCE = new JsonBinarySqlTypeDescriptor();
18
19 @Override
20 public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
21 return new BasicBinder<X>(javaTypeDescriptor, this) {
22 @Override
23 protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
24 st.setObject(index, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
25 }
26
27 @Override
28 protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
29 throws SQLException {
30 st.setObject(name, javaTypeDescriptor.unwrap(value, String.class, options), getSqlType());
31 }
32 };
33 }
34 }
35