1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.type;
17
18 import java.io.ByteArrayInputStream;
19 import java.sql.*;
20
21
22
23
24 public class BlobByteObjectArrayTypeHandler extends BaseTypeHandler<Byte[]> {
25
26 @Override
27 public void setNonNullParameter(PreparedStatement ps, int i, Byte[] parameter, JdbcType jdbcType)
28 throws SQLException {
29 ByteArrayInputStream bis = new ByteArrayInputStream(ByteArrayUtils.convertToPrimitiveArray(parameter));
30 ps.setBinaryStream(i, bis, parameter.length);
31 }
32
33 @Override
34 public Byte[] getNullableResult(ResultSet rs, String columnName)
35 throws SQLException {
36 Blob blob = rs.getBlob(columnName);
37 return getBytes(blob);
38 }
39
40 @Override
41 public Byte[] getNullableResult(ResultSet rs, int columnIndex)
42 throws SQLException {
43 Blob blob = rs.getBlob(columnIndex);
44 return getBytes(blob);
45 }
46
47 @Override
48 public Byte[] getNullableResult(CallableStatement cs, int columnIndex)
49 throws SQLException {
50 Blob blob = cs.getBlob(columnIndex);
51 return getBytes(blob);
52 }
53
54 private Byte[] getBytes(Blob blob) throws SQLException {
55 Byte[] returnValue = null;
56 if (blob != null) {
57 returnValue = ByteArrayUtils.convertToObjectArray(blob.getBytes(1, (int) blob.length()));
58 }
59 return returnValue;
60 }
61 }