1 package com.vladmihalcea.hibernate.type.json.internal;
2
3 import com.fasterxml.jackson.databind.JsonNode;
4 import org.hibernate.type.descriptor.ValueBinder;
5 import org.hibernate.type.descriptor.WrapperOptions;
6 import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
7 import org.hibernate.type.descriptor.sql.BasicBinder;
8
9 import java.sql.CallableStatement;
10 import java.sql.PreparedStatement;
11 import java.sql.SQLException;
12
13 /**
14  * @author Vlad Mihalcea
15  */

16 public class JsonBinarySqlTypeDescriptor extends AbstractJsonSqlTypeDescriptor {
17
18     public static final JsonBinarySqlTypeDescriptor INSTANCE = new JsonBinarySqlTypeDescriptor();
19
20     @Override
21     public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
22         return new BasicBinder<X>(javaTypeDescriptor, this) {
23             @Override
24             protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
25                 st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
26             }
27
28             @Override
29             protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
30                     throws SQLException {
31                 st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
32             }
33         };
34     }
35 }
36