Clover icon

sunshower-base

  1. Project Clover database Mon May 7 2018 22:12:38 UTC
  2. Package io.sunshower.persist.hibernate.types

File FlakeBinaryTypeDescriptor.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
25% of files have more coverage

Code metrics

0
9
9
1
60
49
9
1
1
9
1

Classes

Class Line # Actions
FlakeBinaryTypeDescriptor 12 9 9
0.666666766.7%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    package io.sunshower.persist.hibernate.types;
2   
3    import java.sql.*;
4    import org.hibernate.type.descriptor.ValueBinder;
5    import org.hibernate.type.descriptor.ValueExtractor;
6    import org.hibernate.type.descriptor.WrapperOptions;
7    import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
8    import org.hibernate.type.descriptor.sql.BasicBinder;
9    import org.hibernate.type.descriptor.sql.BasicExtractor;
10    import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
11   
 
12    public class FlakeBinaryTypeDescriptor implements SqlTypeDescriptor {
13    public static final SqlTypeDescriptor INSTANCE = new FlakeBinaryTypeDescriptor();
14   
 
15  35 toggle @Override
16    public int getSqlType() {
17  35 return Types.VARBINARY;
18    }
19   
 
20  60 toggle @Override
21    public boolean canBeRemapped() {
22  60 return true;
23    }
24   
 
25  28 toggle @Override
26    public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
27   
28  28 return new BasicBinder<X>(javaTypeDescriptor, this) {
 
29  24 toggle protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
30    throws SQLException {
31  24 st.setBytes(index, (byte[]) javaTypeDescriptor.unwrap(value, byte[].class, options));
32    }
33   
 
34  0 toggle protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
35    throws SQLException {
36  0 st.setBytes(name, (byte[]) javaTypeDescriptor.unwrap(value, byte[].class, options));
37    }
38    };
39    }
40   
 
41  2 toggle @Override
42    public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
43   
44  2 return new BasicExtractor<X>(javaTypeDescriptor, this) {
 
45  2 toggle protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
46  2 return javaTypeDescriptor.wrap(rs.getBytes(name), options);
47    }
48   
 
49  0 toggle protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
50    throws SQLException {
51  0 return javaTypeDescriptor.wrap(statement.getBytes(index), options);
52    }
53   
 
54  0 toggle protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
55    throws SQLException {
56  0 return javaTypeDescriptor.wrap(statement.getBytes(name), options);
57    }
58    };
59    }
60    }